git il y a 5 ans
Parent
commit
6281c9f243
3 fichiers modifiés avec 99 ajouts et 32 suppressions
  1. 11 6
      Home/Lib/Action/ApiAction.class.php
  2. 87 25
      Home/Lib/Action/CronAction.class.php
  3. 1 1
      czapp

+ 11 - 6
Home/Lib/Action/ApiAction.class.php

@@ -219,7 +219,11 @@ class ApiAction extends Action {
 		$this->token_verify();
 		$post_data = I('post.data');
 		if( empty($post_data) ){
-			$this->api_fail(C('FAIL'),'post_data不能为空!');
+			$this->api_fail(C('FAIL'),'报警信息不能为空!');
+		}
+		$mobile = trim($post_data['UserPhone']);
+		if(!preg_match("/^1[345678]{1}\d{9}$/",$mobile)){
+		    $this->api_fail(C('FAIL'),'手机号格式不正确!');
 		}
 		$date = $post_data['StolenDate'];
 		if($date == '请选择'){
@@ -241,7 +245,7 @@ class ApiAction extends Action {
 		if ( empty($stolenaddress)) {
 			$this->api_fail(C('FAIL'),'事发地址不能为空');
 		}
-		$WoContent = $post_data['WoContent'];
+		$WoContent = trim($post_data['WoContent']);
 		if (empty($WoContent)) {
 			$this->api_fail(C('FAIL'),'报警原因不能为空');
 		}
@@ -278,24 +282,25 @@ class ApiAction extends Action {
 		} else {
 			$StolenDate = date('Y-m-d');
 		}
+		$this->api_fail(C('FAIL'),$stolenCityId);
 		if(M('jms_baojing')->where(array('LicensePlate' => $vehicle_info['LicensePlate'],'StolenState'=>0))->find()){
 			$this->api_fail(C('FAIL'),'报警信息已经存在');
 		}
-		$StolenCityId = explode(',',$post_data['StolenCityId']);
+		$StolenCityId = explode(',',$stolenCityId);
 		$StolenCityId = $StolenCityId[2]+1000;
 		$data = array(
-			'WoContent' => $post_data['WoContent'], 
+			'WoContent' => $WoContent, 
 			'VehicleId' =>  $userid, 
 			'LicensePlate' => $vehicle_info['LicensePlate'], 
 			'IdCard' => $vehicle_info['IdCard'], 
 			'UserId' => $userid, 
-			'UserPhone' => I('post.UserPhone'),
+			'UserPhone' =>$mobile,
 			'CityId' => $vehicle_info['CityId'], 
 			'SubmitUserId' => $userid, 
 			'SubmitTime' => date('Y-m-d H:i:s'), 
 			'StolenDate' => $StolenDate,
 			'StolenCityId' => $StolenCityId, //新增:被盗城市id
-			'StolenAddress' => $post_data['StolenAddress']
+			'StolenAddress' => $stolenaddress
 		);
 		if (!M('jms_baojing')->createAdd($data)) {
 			$this->api_fail(C('FAIL'),'添加报警信息失败');

+ 87 - 25
Home/Lib/Action/CronAction.class.php

@@ -18,28 +18,36 @@ class CronAction extends Action {
 		$plateLocalPath = Redis('jyzl_wait_upload2oss_eplate', 'queue');
 		while( (time() - $start) < 60 ){
 			$licensPlate = $pendingElectricPlate->pop();
-			if($licensPlate){
-				echo 'pop licensPlate:'.$licensPlate.PHP_EOL;
-				$field = 'LicensPlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand, RegistrationTime';
-				$vehicleInfo = M('jms_vehicle')->where(array('LicensPlate' => $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;
-					}
+			if(!$licensPlate){
+				echo 'no message!'.PHP_EOL;
+				sleep(1);
+			}
+			echo 'pop licensPlate:'.$licensPlate.PHP_EOL;
+			$field = 'LicensPlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand, RegistrationTime';
+			$vehicleInfo = M('jms_vehicle')->where(array('LicensPlate' => $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;
 				}
-				$up2ossWait = json_encode(array('licensPlate' => $licensPlate, 'localPath' => $localPath));
-				$plateLocalPath->push($up2ossWait);
 			}
-			sleep(1);
+			//生成的本地电子车牌,加入到待上传oss队列
+			$up2ossWait = json_encode(array('licensPlate' => $licensPlate, 'localPath' => $localPath));
+			$reslut = $plateLocalPath->add($up2ossWait);//push方法没有返回值,用add代替
+			if(!$result){
+				echo 'plateLocalPath->add() failed,$licensPlate = '.$licensPlate .PHP_EOL;
+				continue;
+			}
+			usleep(100000);
 		}
 	}
 	
@@ -253,24 +261,69 @@ class CronAction extends Action {
 	
  
 	private  function createLocalElectronicPlate( $params ){
-		$license_plate = $params['LicensPlate'];//LicensPlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand
+		$license_plate = $params['LicensPlate'];
+		if(!$license_plate){
+			echo "LicensPlate empty!".PHP_EOL;
+			return false;
+		}
 		$vehicle_color = $params['VehicleColor'];
+		if(!$vehicle_color){
+			echo "VehicleColor empty!".PHP_EOL;
+			return false;
+		}
 		$real_name = $params['FullName'];
+		if(!$real_name){
+			echo "FullName empty!".PHP_EOL;
+			return false;
+		}
 		$address = $params['Address'];
+		if(!$address){
+			echo "Address empty!".PHP_EOL;
+			return false;
+		}
 		$cjh = $params['FrameNumber'];
+		if(!$cjh){
+			echo "FrameNumber empty!".PHP_EOL;
+			return false;
+		}
 		$djh = $params['MotorNumber'];
+		if(!$djh){
+			echo "MotorNumber empty!".PHP_EOL;
+			return false;
+		}
 		$cph = $params['VehicleBrand'];
+		if(!$cph){
+			echo "VehicleBrand empty!".PHP_EOL;
+			return false;
+		}
+		if(strtotime($params['RegistrationTime']) < 1546272000){
+			echo "RegistrationTime invalid! RegistrationTime: ".$params['RegistrationTime'].PHP_EOL;
+			return false;
+		}
 		$date = date('Y-m-d',$params['RegistrationTime']);
+		if(!$date){
+			echo "date empty! RegistrationTime: ".$params['RegistrationTime'].PHP_EOL;
+			return false;
+		}
 		$reg_date = $date;
 		$fz_date = $date;
 		$fz_org = "包头市公安局";
 		
 		$im = imagecreatetruecolor(500, 278);           // 设置画布
 		//$bg = imagecreatefromjpeg('bg.jpg');   // 设置背景图片
-		$bg = imagecreatefromjpeg('./Public/images/front.jpg');   // 设置背景图片
+		$front_img = './Public/images/front.jpg'
+		if(!is_file($front_img)){
+			echo "front_img not existed! front_img: ".$front_img.PHP_EOL;
+			return false;
+		}
+		$bg = imagecreatefromjpeg($front_img);   // 设置背景图片
 		imagecopy($im,$bg,0,0,0,0,500,278);             // 将背景图片拷贝到画布相应位置
 		imagedestroy($bg);                              // 销毁背景图片
 		$font = './Public/font/stsong.ttf';               // 设置字体             // 设置字体,这里可以指向ttf文件
+		if(!is_file($font)){
+			echo "font file not existed! font: ".$font.PHP_EOL;
+			return false;
+		}
 		$blacka = imagecolorallocate($im, 15, 23, 25);  // 颜色
 		
 		/* 写入内容 */
@@ -286,15 +339,24 @@ class CronAction extends Action {
 		imagettftext($im, 12, 0, 263, 255, $blacka, $font,$fz_org );       // 发证机关
 		
 		
-		$img_file = "./images/myplate.jpg";
+		$img_file_dir = SOLUTION_LOG_PATH ."/images/".date('Y-m-d')."/";
+		if(!is_dir($img_file_dir)){
+			$res = mkdir($img_file_dir,0777,true);
+			if (!$res){
+				echo "目录 $img_file_dir 创建失败!".PHP_EOL;
+				return false;
+			}
+		}
+		$img_file = $img_file_dir .$license_plate.".jpg";
 		$result = imagejpeg($im, $img_file);     // 生成jpeg格式图片
 		imagedestroy($im);  // 销毁图片
 		if(!$result){
-			echo "生成电子车牌失败";
-			exit;
+			echo "生成电子车牌失败, license_plate: ".$license_plate .PHP_EOL;
+			return false;
 		}
 		
-		echo '生成电子车牌完成';
+		echo "生成电子车牌完成, license_plate: ".$license_plate .PHP_EOL;
+		return $img_file;
 	}
 	
 

+ 1 - 1
czapp

@@ -1 +1 @@
-Subproject commit 0962e8fa9b3acbd52eceb4ad2ab92c5255544bb4
+Subproject commit 0c8fc6c718911ebb4fa73ef62a2d17744d89b82a