|
@@ -165,7 +165,33 @@ class ApiAction extends Action {
|
|
|
json_success('上报预选车牌成功',$response);
|
|
|
}
|
|
|
}else{
|
|
|
- json_fail('该车牌已经被占用');
|
|
|
+ //是否过期
|
|
|
+ $time = time() - (C('EXPIREIN')*60);
|
|
|
+ if($time > $info['Timestamp']){
|
|
|
+ //过期车牌,新用户选牌信息添加到redis
|
|
|
+ $info = array(
|
|
|
+ 'ExpireIn' => C('EXPIREIN'),
|
|
|
+ 'Timestamp' => time(),
|
|
|
+ 'OpenId' => $openid
|
|
|
+ );
|
|
|
+ $new_val = json_encode($info,JSON_UNESCAPED_UNICODE);
|
|
|
+ $hash = array($key =>$new_val);
|
|
|
+ $redis_res = $p->add($hash);
|
|
|
+ if(!$redis_res){
|
|
|
+ json_fail('推送redis失败');
|
|
|
+ }
|
|
|
+ //返回成功信息
|
|
|
+ $response = array(
|
|
|
+ 'LicensePlate' => $licenseplate,
|
|
|
+ 'ExpireIn' => C('EXPIREIN'),
|
|
|
+ 'Timestamp' => time()
|
|
|
+ );
|
|
|
+ //删除未选车牌库中的该车牌
|
|
|
+ $this->deletePlateFromRedis($licenseplate);
|
|
|
+ json_success('上报预选车牌成功',$response);
|
|
|
+ }else{
|
|
|
+ json_fail('该车牌已被占用,请重新选牌!');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -498,54 +524,6 @@ class ApiAction extends Action {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function releaseRedisExpiredLicenseplate( ){
|
|
|
- $config = parse_url(C('REDIS_DSN'));
|
|
|
- $redis = new Redis();
|
|
|
- $redis->connect($config["host"],$config["port"]?:6379);
|
|
|
- $redis->auth($config["pass"]?: "");
|
|
|
- $redis->select(trim($config['path'],'//') ? : 0);
|
|
|
-
|
|
|
- $all = $redis->hgetall('wjw_plate');
|
|
|
- foreach($all as $key=>$val){
|
|
|
- $data = json_decode($val,true);
|
|
|
- $orderstatus = M('jms_order')->where(array('LicensePlate'=>$key))->getField('OrderStatus');
|
|
|
- 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('释放过期车牌失败');
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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('执行完毕');
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private function plate_verify( $licenseplate ){
|
|
|
if(!$licenseplate){
|
|
|
json_fail('车牌不能为空!');
|