git vor 5 Jahren
Ursprung
Commit
83dc6425a0
1 geänderte Dateien mit 81 neuen und 20 gelöschten Zeilen
  1. 81 20
      Home/Lib/Action/CronAction.class.php

+ 81 - 20
Home/Lib/Action/CronAction.class.php

@@ -24,7 +24,7 @@ class CronAction extends Action {
 				continue;
 			}
 			echo 'pop licensPlate:'.$licensPlate.PHP_EOL;
-			$field = 'LicensePlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand, RegistrationTime';
+			$field = 'LicensePlate,VehicleColor, FullName, DetailedAdd, FrameNumber, MotorNumber, VehicleBrand, RegistrationTime';
 			$vehicleInfo = M('jms_vehicle')->where(array('LicensePlate' => $licensPlate))->field($field)->find();
 			if(!$vehicleInfo){
 				echo 'vehicleInfo not existed,$licensPlate = '.$licensPlate .PHP_EOL;
@@ -73,31 +73,92 @@ class CronAction extends Action {
 			$data = $plateLocalPath->pop();
 			if(!$data){
 				echo 'no more data, waiting for next mesaage.'.PHP_EOL;
+				sleep(1);
 				continue;
 			}
 			
-			if($data){
-				//TEST
-				$fileName = 'gravatar.jpg';
-				//$fileName = $data['localPath'];
-				$uploadRes = $upload->localFileUpload($fileName);
-				if(!$uploadRes['success']){
-					echo $uploadRes['message'].PHP_EOL;
-					continue;
-				}
-				$frontImageUrl = $uploadRes['objectname'];
+			$data = json_decode($data, true);
+			
+			if(!$data){
+				echo 'json_decode failed, please check the format of the json data';
+				continue;
+			}
+			
+			$fileName = 'gravatar.jpg';//TEST
+			//$fileName = $data['localPath'];
+			if(!$fileName){
+				echo 'cant get loacl file';
+				continue;
+			}
+			
+			$uploadRes = $upload->localFileUpload($fileName);
+			if(!$uploadRes['success']){
+				echo $uploadRes['message'].PHP_EOL;
+				continue;
+			}
+			$frontImageUrl = $uploadRes['objectname'];
+			if(!$frontImageUrl){
+				echo 'cant get img_oss_url';
+				continue;
+			}
+			
+			$licensPlate = $data['licensPlate'];
+			if(!$licensPlate)
 		
-				$updateRes = M('jms_vehicle')->where(array('LicensePlate' => $data['licensPlate']))->setField('FrontElectronicPlateUrl',$frontImageUrl);
-				if(!$updateRes){
-					echo 'update failed'.PHP_EOL;
-					continue;
-				}
-				if(file_exists($filename)){
-					unlink($filename);
+			$updateRes = M('jms_vehicle')->where(array('LicensePlate' => $licensPlate))->setField('FrontElectronicPlateUrl',$frontImageUrl);
+			if(!$updateRes){
+				echo 'update failed'.PHP_EOL;
+				continue;
+			}
+			
+			//删除本地图片
+			$filePath = $config['filePathDir'].$filename;
+			if(file_exists(!$filePath)){
+				$flag = unlink($filePath);
+				if(!$flag){
+					echo 'delete localImg failed'.PHP;
 				}
 			}
+			
+			
 			sleep(1);
 		}
+		
+		
+		/*
+			$licensPlate = $pendingElectricPlate->pop();
+			if(!$licensPlate){
+				echo 'no message!'.PHP_EOL;
+				sleep(1);
+				continue;
+			}
+			echo 'pop licensPlate:'.$licensPlate.PHP_EOL;
+			$field = 'LicensePlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand, RegistrationTime';
+			$vehicleInfo = M('jms_vehicle')->where(array('LicensePlate' => $licensPlate))->field($field)->find();
+			if(!$vehicleInfo){
+				echo 'vehicleInfo not existed,$licensPlate = '.$licensPlate .PHP_EOL;
+				continue;
+			}
+			//生成电子车牌到本地
+			$localPath = $this->createLocalElectronicPlate($vehicleInfo);
+			if(!$localPath){
+				echo 'createLocalElectronicPlate failed,$licensPlate = '.$licensPlate .PHP_EOL;
+				//生成失败的重新放回队列
+				$result = $pendingElectricPlate->add($licensPlate);
+				if(!$result){
+					echo 'pendingElectricPlate->add() failed,$licensPlate = '.$licensPlate .PHP_EOL;
+					continue;
+				}
+			}
+			//生成的本地电子车牌,加入到待上传oss队列
+			$up2ossWait = json_encode(array('LicensePlate' => $licensPlate, 'localPath' => $localPath));
+			$reslut = $plateLocalPath->add($up2ossWait);//push方法没有返回值,用add代替
+			if(!$result){
+				echo 'plateLocalPath->add() failed,$licensPlate = '.$licensPlate .PHP_EOL;
+				continue;
+			}
+			usleep(100000);
+		*/
 	}
 	
  
@@ -293,9 +354,9 @@ class CronAction extends Action {
 			echo "FullName empty!".PHP_EOL;
 			return false;
 		}
-		$address = $params['Address'];
+		$address = $params['DetailedAdd'];
 		if(!$address){
-			echo "Address empty!".PHP_EOL;
+			echo "DetailedAdd empty!".PHP_EOL;
 			return false;
 		}
 		$cjh = $params['FrameNumber'];