|
@@ -69,7 +69,6 @@ class ApiAction extends Action {
|
|
|
$list = $redis->sRandMember('plate_preselect_pool',20);
|
|
|
//var_dump($list);
|
|
|
//echo 'sRandMember: '.(microtime(true)-$start)*1000 .' ms'.PHP_EOL;
|
|
|
-
|
|
|
return $list;
|
|
|
}
|
|
|
|
|
@@ -191,7 +190,7 @@ class ApiAction extends Action {
|
|
|
json_fail('Random不存在!');
|
|
|
}
|
|
|
$this->token_verify($appkey,$timestamp,$random,$token);
|
|
|
- $res = M('yhgl_kh_places')->field('ID as PlaceId, RegPointName as PlaceName')->select();
|
|
|
+ $res = M('yhgl_kh_places')->field('ID as PlaceId, RegPointName as PlaceName,Longitude,Latitude')->select();
|
|
|
if(!$res){
|
|
|
json_fail('备案点不存在!');
|
|
|
}
|
|
@@ -253,43 +252,94 @@ class ApiAction extends Action {
|
|
|
$ordernumber = $this->setOrderNumber();
|
|
|
//检测车牌是否存在
|
|
|
if(!$data['LicensePlate']){
|
|
|
- $data['ID'] = create_guid();
|
|
|
- $data['OrderNumber'] = $ordernumber;
|
|
|
- $data['OrderStatus'] = 0;
|
|
|
- $data['AddTime'] = date('Y-m-d H:i:s');
|
|
|
- $data['EffectiveDate'] = date("Y-m-d");//开始日期
|
|
|
- $data['ExpireDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//过期日期
|
|
|
+ $data['ID'] = create_guid();
|
|
|
+ $data['OrderNumber'] = $ordernumber;
|
|
|
+ $data['OrderStatus'] = 0;
|
|
|
+ $data['AddTime'] = date('Y-m-d H:i:s');
|
|
|
+ if($data['OrderType']==1){
|
|
|
+ $data['EffectiveDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//开始安装日期
|
|
|
+ $data['ExpireDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')+C('WJW.EXPIRATION_DATE')." day"));//过期日期
|
|
|
+ }else{
|
|
|
+ $data['EffectiveDate'] = date("Y-m-d");
|
|
|
+ $data['ExpireDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//过期日期
|
|
|
+ }
|
|
|
$res = M('jms_order')->createAdd($data);
|
|
|
if(!$res){
|
|
|
json_fail('订单信息添加失败!');
|
|
|
}
|
|
|
$place_message['OrderNumber'] = $ordernumber;
|
|
|
$place_message['EffectiveDate'] = $data['EffectiveDate'];
|
|
|
- $place_message['ExpireDate'] = $data['ExpireDate'];
|
|
|
+ $place_message['ExpireDate'] = $data['ExpireDate'];
|
|
|
json_success('操作成功',$place_message);
|
|
|
}else{
|
|
|
- $order_num = M('jms_order')->where(array('LicensePlate'=>$data['LicensePlate'],'OrderStatus'=>array('neq','2')))->count();
|
|
|
- //判断订单状态,过期重新开户
|
|
|
- if(!$order_num){
|
|
|
- $data['ID'] = create_guid();
|
|
|
- $data['OrderNumber'] = $ordernumber;
|
|
|
- $data['OrderStatus'] = 0;
|
|
|
- $data['AddTime'] = date('Y-m-d H:i:s');
|
|
|
- $data['LicensePlate'] = $data['LicensePlate'];
|
|
|
- $data['EffectiveDate'] = date("Y-m-d",time());//开始日期
|
|
|
- $data['ExpireDate'] =date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//过期日期
|
|
|
- $res = M('jms_order')->createAdd($data);
|
|
|
- if(!$res){
|
|
|
- json_fail('订单信息保存失败!');
|
|
|
+ $licenseplate = $data['LicensePlate'];
|
|
|
+ //从redis获取车牌
|
|
|
+ $key = strtoupper($licenseplate);
|
|
|
+ $p = Redis("wjw_plate","hash");
|
|
|
+ $val = $p->get($key);
|
|
|
+ if(!$val){
|
|
|
+ json_fail('系统错误');
|
|
|
+ }
|
|
|
+ $info = json_decode($val,true);
|
|
|
+ //检测openid是否是本人
|
|
|
+ if($info['OpenId'] == $data['OpenId']){
|
|
|
+ //是否过期
|
|
|
+ $time = time() - (C('EXPIREIN')*60);
|
|
|
+ if($time > $info['Timestamp']){
|
|
|
+ json_fail('该车牌已经过期,请重选车牌');
|
|
|
+ }else{
|
|
|
+ $response = array(
|
|
|
+ 'LicensePlate' => $licenseplate,
|
|
|
+ 'ExpireIn' => C('EXPIREIN'),
|
|
|
+ 'Timestamp' => $info['Timestamp']
|
|
|
+ );
|
|
|
+ json_success('上报预选车牌成功',$response);
|
|
|
}
|
|
|
- $place_message['OrderNumber'] = $ordernumber;
|
|
|
- $place_message['LicensePlate'] = $data['LicensePlate'];
|
|
|
- $place_message['EffectiveDate'] = $data['EffectiveDate'];
|
|
|
- $place_message['ExpireDate'] = $data['ExpireDate'];
|
|
|
- json_success('操作成功',$place_message);
|
|
|
}else{
|
|
|
+ //是否过期
|
|
|
+ $time = time() - (C('EXPIREIN')*60);
|
|
|
+ if($time > $info['Timestamp']){
|
|
|
+ $response = array(
|
|
|
+ 'LicensePlate' => $licenseplate,
|
|
|
+ 'ExpireIn' => C('EXPIREIN'),
|
|
|
+ 'Timestamp' => $info['Timestamp']
|
|
|
+ );
|
|
|
+ json_success('上报预选车牌成功',$response);
|
|
|
+ }else{
|
|
|
+ json_fail('该车牌已被占用,请重新选牌!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $cond = array(
|
|
|
+ 'LicensePlate'=>$data['LicensePlate'],
|
|
|
+ 'OrderStatus'=>array('neq','2')
|
|
|
+ );
|
|
|
+ $order_num = M('jms_order')->where($cond)->count();
|
|
|
+ //判断订单状态,过期重新开户
|
|
|
+ if($order_num){
|
|
|
json_fail('订单信息已经存在');
|
|
|
}
|
|
|
+
|
|
|
+ $data['ID'] = create_guid();
|
|
|
+ $data['OrderNumber'] = $ordernumber;
|
|
|
+ $data['OrderStatus'] = 0;
|
|
|
+ $data['AddTime'] = date('Y-m-d H:i:s');
|
|
|
+ $data['LicensePlate'] = $data['LicensePlate'];
|
|
|
+ if($data['OrderType']==1){
|
|
|
+ $data['EffectiveDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//开始安装日期
|
|
|
+ $data['ExpireDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')+C('WJW.EXPIRATION_DATE')." day"));//过期日期
|
|
|
+ }else{
|
|
|
+ $data['EffectiveDate'] = date("Y-m-d");
|
|
|
+ $data['ExpireDate'] = date("Y-m-d",strtotime("+".C('WJW.DELIVERY_TIME')." day"));//过期日期
|
|
|
+ }
|
|
|
+ $res = M('jms_order')->createAdd($data);
|
|
|
+ if(!$res){
|
|
|
+ json_fail('订单信息保存失败!');
|
|
|
+ }
|
|
|
+ $place_message['OrderNumber'] = $ordernumber;
|
|
|
+ $place_message['LicensePlate'] = $data['LicensePlate'];
|
|
|
+ $place_message['EffectiveDate'] = $data['EffectiveDate'];
|
|
|
+ $place_message['ExpireDate'] = $data['ExpireDate'];
|
|
|
+ json_success('操作成功',$place_message);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -463,20 +513,38 @@ class ApiAction extends Action {
|
|
|
foreach($all as $key=>$val){
|
|
|
$data = json_decode($val,true);
|
|
|
$orderstatus = M('jms_order')->where(array('LicensePlate'=>$key))->getField('OrderStatus');
|
|
|
- if($orderstatus == 1){
|
|
|
- $time = time() - (C('EXPIREIN')*60);
|
|
|
- if($time > $data['Timestamp']){
|
|
|
- $p = Redis("wjw_plate","hash");
|
|
|
- $res = $p->where($key)->delete();
|
|
|
- if(!$res){
|
|
|
- json_fain('删除过期车牌失败');
|
|
|
+ if($orderstatus == NULL){
|
|
|
+ $time = time() - (C('EXPIREIN')*60);
|
|
|
+ if($time > $data['Timestamp']){
|
|
|
+ $p = Redis("wjw_plate","hash");
|
|
|
+ $res = $p->where($key)->delete();
|
|
|
+ if(!$res){
|
|
|
+ json_fail('删除过期车牌失败');
|
|
|
+ }
|
|
|
+ $result = $redis->sAdd('plate_preselect_pool' , $key);
|
|
|
+ if(!$result){
|
|
|
+ json_fail('释放过期车牌失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- $result = $redis->sAdd('plate_preselect_pool' , $key);
|
|
|
- if(!$result){
|
|
|
- json_fain('释放过期车牌失败');
|
|
|
+ if($orderstatus == 2){
|
|
|
+ $p = Redis("wjw_plate","hash");
|
|
|
+ $res = $p->where($key)->delete();
|
|
|
+ if(!$res){
|
|
|
+ json_fail('删除过期车牌失败');
|
|
|
+ }
|
|
|
+ $result = $redis->sAdd('plate_preselect_pool' , $key);
|
|
|
+ if(!$result){
|
|
|
+ json_fail('释放过期车牌失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($orderstatus == 1){
|
|
|
+ $p = Redis("wjw_plate","hash");
|
|
|
+ $res = $p->where($key)->delete();
|
|
|
+ if(!$res){
|
|
|
+ json_fail('删除已开户车牌失败');
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
json_success('执行完毕');
|
|
|
}
|