git 2 years ago
parent
commit
253908226c

+ 3 - 6
.env

@@ -23,12 +23,9 @@ return array (
   "KAFKA_ENABLE_PRODUCE_ALL_RFID_LOCATION"=>true,
   "TCP_PORT"=>20160,
   // 微信公众号推送
-  'WX_FENCE_TEMPLATE_ID' => '_g17U1Bmax2lH0D7QbTBCohzmpQXRz8a1PN91kMLdNE', // 进围栏告警
-  'WX_PRESS_ALARM_TEMPLATE_ID' => 'NeSrB4ViIkRMOuCtoA6BIPPi_N5L-B5zaWcIXJZwkD0',// 按键告警
-  'WX_LOW_BAT_ALARM_TEMPLATE_ID'=>'mf_HK4Qehv6vHr5_wxRWKTkgYK91WkI4JqP6ucyDPBw',//低电量告警
-  'WX_LOW_RECOVER_ALARM_TEMPLATE_ID'=>'FnoFZZAxmOcPCB5kVyqCNpxJJhONVpSQyq1kIzVJm9o',//低电量恢复
-  'WX_CHARGE_FULL_ALARM_TEMPLATE_ID'=>'FnoFZZAxmOcPCB5kVyqCNpxJJhONVpSQyq1kIzVJm9o',//充电完成
-  'WX_VOICE_TEMPLATE_ID'=>'mf_HK4Qehv6vHr5_wxRWKTkgYK91WkI4JqP6ucyDPBw',//充电完成
+
+  'WX_LOW_BAT_ALARM_TEMPLATE_ID'=>'BgR1H2mph1r6inoDp2Nclo_dNpZIQ-1GeIc35O2HIpI',//低电量告警
+
 
 
   'WX_KQ_TEMPLATE_ID'=>'PJJywM6pv6xFWfW184q9iEHIS-vS4IoAqqPtEQZ-0EM',//考勤通知

+ 36 - 0
Home/Common/kq_funclib.php

@@ -897,4 +897,40 @@
 		}
 	}
 	
+ 
+	function create_log( $message, $filename = 'error_log' ){
+		//要创建的多级目录
+		if(defined('SOLUTION_LOG_PATH')){
+			$log_dir = SOLUTION_LOG_PATH .'/xskq/'.date('Y-m-d').'/';
+		}else{
+			$log_dir = './log/xskq/'.date('Y-m-d').'/';
+		}
+		//判断目录存在否,不存在则创建目录
+		if (!is_dir($log_dir)){  
+			//第三个参数是“true”表示能创建多级目录
+			$res=mkdir($log_dir,0777,true); 
+			exec("chmod -R 777 $log_dir ");
+			if (!$res){
+				$content = "目录 ". $log_dir." 创建失败";
+				if(APP_DEBUG){
+					echo $content;
+				}
+				return array('success'=>false,'message'=>$content);
+			}
+		}
+		$file_path  = $log_dir .$filename. '.log';//要写入文件的文件名(可以是任意文件名),如果文件不存在,将会创建一个
+		$content = '['.date('Y-m-d H:i:s') .'] ' .json_encode($message,JSON_UNESCAPED_UNICODE) . PHP_EOL; 
+		if(APP_DEBUG){
+			echo $content;
+		}		
+		if(!file_put_contents($file_path, $content,FILE_APPEND)){// 这个函数支持版本(PHP 5) 
+			$content = "日志写入失败".PHP_EOL;
+			if(APP_DEBUG){
+				echo $content;
+			}
+			return array('success'=>false,'message'=>$content);	
+		}
+		return array('success'=>true,'message'=>'add log success');
+	}
+	
 

+ 17 - 154
Home/Lib/Action/BatteryAlarmKafkaAction.class.php

@@ -91,16 +91,6 @@ class BatteryAlarmKafkaAction extends Action {
 		}
 		
 		
-		/*
-		$data = array(
-			'tid' => $data['tid'],
-			'alarm' => $data['alarm'],
-			'is_low' => $data['is_low'],
-			'is_charge' => $data['is_charge'],
-			'is_charge_full' => $data['is_charge_full'],
-			'battery_level' => $data['battery_level'],
-			'timestamp' => $data['timestamp']
-		);*/
 		
 		$cond=array('imei'=>$data['tid']);
 		$device_info=M('devices')->where($cond)->find();
@@ -118,20 +108,26 @@ class BatteryAlarmKafkaAction extends Action {
 		if($data['battery_level']==0){
 			return array('success'=>false,'message'=>$data['tid'].' battery_level is 0');
 		}
-		$table_name =getBatteryTableName();
-		M($table_name)->createAdd($save_data_log);
-		if(!$device_info['user_id']){
+		
+		M('battery_log')->createAdd($save_data_log);
+		
+		if(!$device_info['bind_id']){
 			$res=M('devices')->createSave(array('imei'=>$data['tid']),array('battery_level'=> $data['battery_level']));
-			return array('success'=>false,'message'=>$data['tid'].' userid not existed');
+			return array('success'=>false,'message'=>$data['tid'].' bind_id not existed');
 		}
 		$this->wxMsg = new  \Jiaruan\WxTmp();
-		$send_user=M('users')->where(array('id'=>$device_info['user_id']))->find();
+		$user_id=M('vehicles')->where(array('id'=>$device_info['bind_id']))->getField('user_id');
+		if(!$user_id){
+			return array('success'=>false,'message'=>$data['tid'].' user_id not existed');
+		}
+		$send_user=M('users')->where(array('id'=>$user_id))->find();
 		$alarm_state=0;
 		$save_data=array('battery_level'=> $data['battery_level']);
 		$alarm_time=$data['timestamp'];
 		if($alarm_time<(time()-3600)){
 			$alarm_time=time();
 		}
+		
 		$alarm_data=array(
 			'device_number'=>$device_info['imei'],
 			//'alarm_type'=>'low_recover',
@@ -147,142 +143,15 @@ class BatteryAlarmKafkaAction extends Action {
 			'device_number'=>$device_info['imei'],
 			'created_at'=>array('gt',time()-$send_interval),
 		);
-		if($data['is_charge_full']){
-			//新版本充满只报一次
-			//充电充满
-			$alarm_data['alarm_type']='charge_full';
-			$check_cond['alarm_type']='charge_full';
-			if(!M('alarm_report')->where($check_cond)->count()){
-				$insertId=M('alarm_report')->createAdd($alarm_data);
-				// 电量充满模板ID
-				$full_template_id = C('WX_CHARGE_FULL_ALARM_TEMPLATE_ID');
-				if (!$full_template_id) {
-					create_log('WX_CHARGE_FULL_ALARM_TEMPLATE_ID required', 'add_alarm');
-					return array('success'=>false,'message'=>'WX_CHARGE_FULL_ALARM_TEMPLATE_ID required');
-				}
-		
-				$sendmsg = array(
-							'touser'=>$send_user['wx_open_id'],
-							'template_id' => $full_template_id, //"NeSrB4ViIkRMOuCtoA6BIPPi_N5L-B5zaWcIXJZwkD0",
-							'data' => [
-									'first' => [ 'value' =>$send_user['realname'].'的电子卡已充电完成', 'color' => '#173177' ],
-									'keyword1' => [ 'value' => $data['tid'], 'color' => '#173177' ],
-									'keyword2' => [ 'value' => date('Y-m-d H:i:s'), 'color' => '#173177' ],
-									'remark' => [ 'value' => '', 'color' => '#173177' ],
-							],
-				);
-				$res=$this->wxMsg->sendMessage($sendmsg);
-				create_log($device_info['imei'].' charge_full user:'.$send_user['id'].' openid:'.$send_user['wx_open_id'].' res:'.json_encode($res), 'wx_push_result_log');
-						//推送记录
-				$push_res_data = array(
-							'username'=>$send_user['realname'],
-							'device_number'=>$device_info['imei'],
-							'result'=> json_encode($res),
-							'created_at'=>time(),
-							'alarm_id'=>$insertId,
-							'alarm_type'=>$alarm_data['alarm_type'],
-							'creator_id'=>$device_info['creator_id']
-				);
-				M('wx_push_result_log')->createAdd($push_res_data);
-			}
-			
-		}
-		if($data['is_charge'] || $data['is_charge_full']){
-			$recover_cond=array(
-				'device_number'=>$device_info['imei'],
-				'alarm_reason'=>'low_bat',
-				'state'=>'start',
-			);
-			if(M("alarm_records")->where($recover_cond)->count()){
-				$recover_data=array(
-						'end_time'=>time(),
-						'state'=>'end',
-						'result'=>'1',
-				);
-				M('alarm_records')->createSave($recover_cond,$recover_data);
-				if(M('alarm_records')->where(array('device_number'=>$device_info['imei'],'state'=>'start'))->count()){
-					$save_data['alarm_state']=1;
-				}else{
-					$save_data['alarm_state']=0;
-				}
-			}
-				
-			/* //充电中  低电量告警恢复
-			$alarm_data['alarm_type']='is_charge';
-			$check_cond['alarm_type']='charge_full';
-			if(!M('alarm_report')->where($check_cond)->count()){
-				$insertId=M('alarm_report')->createAdd($alarm_data);
 		
-				$recover_cond=array(
-						'device_number'=>$device_info['imei'],
-						'alarm_reason'=>'low_bat',
-						'state'=>'start',
-				);
-				$recover_data=array(
-						'end_time'=>time(),
-						'state'=>'end',
-						'result'=>'1',
-				);
-				M('alarm_records')->createSave($recover_cond,$recover_data);
-				if(M('alarm_records')->where(array('device_number'=>$device_info['imei'],'state'=>'start'))->count()){
-					$save_data['alarm_state']=1;
-				}else{
-					$save_data['alarm_state']=0;
-				}
-				//充电中 推送低电量恢复模板ID
-				$recover_template_id = C('WX_LOW_RECOVER_ALARM_TEMPLATE_ID');
-				if (!$recover_template_id) {
-					create_log('WX_LOW_RECOVER_ALARM_TEMPLATE_ID required', 'add_alarm');
-					return false;
-				}
-		
-				$sendmsg = array(
-							'touser'=>$send_user['wx_open_id'],
-							'template_id' => $recover_template_id, //"NeSrB4ViIkRMOuCtoA6BIPPi_N5L-B5zaWcIXJZwkD0",
-							'data' => [
-									'first' => [ 'value' =>$send_user['realname'].'的电子卡正在充电', 'color' => '#173177' ],
-									'keyword1' => [ 'value' => $send_user['realname'], 'color' => '#173177' ],
-									'keyword2' => [ 'value' => $data['tid'], 'color' => '#173177' ],
-									'keyword3' => [ 'value' => $data['battery_level'], 'color' => '#173177' ],
-									'remark' => [ 'value' => '', 'color' => '#173177' ],
-							],
-				);
-				$res=$this->wxMsg->sendMessage($sendmsg);
-						//推送记录
-				$push_res_data = array(
-							'username'=>$send_user['realname'],
-							'device_number'=>$device_info['imei'],
-							'result'=> json_encode($res),
-							'created_at'=>time(),
-							'alarm_id'=>$insertId,
-							'alarm_type'=>$alarm_data['alarm_type'],
-							'creator_id'=>$device_info['creator_id']
-				);
-				M('wx_push_result_log')->createAdd($push_res_data);
-			}*/
-		}
-		if($data['is_low'] && !$data['is_charge']){
+		if($data['is_low']){
 			//低电量告警
 			$save_data['alarm_state']=1;
 			//低电量告警
 			$alarm_data['alarm_type']='low_bat';
 			$insertId=M('alarm_report')->createAdd($alarm_data);
-			$cond=array(
-				'device_number'=>$device_info['imei'],
-				'alarm_reason'=>'low_bat',
-				'state'=>'start',
-			);
-			//如果不存在告警  则添加
-			if(!M("alarm_records")->where($cond)->count()){
-				$records_save_data=array(
-					'device_number'=>$device_info['imei'],
-					'alarm_reason'=>'low_bat',
-					'state'=>'start',
-					'start_time'=>time(),
-					'creator_id'=>$device_info['creator_id']
-				);
-				M('alarm_records')->createAdd($records_save_data);
-				
+		
+			
 				// 低电量模板ID
 				$bat_template_id = C('WX_LOW_BAT_ALARM_TEMPLATE_ID');
 				if (!$bat_template_id) {
@@ -294,10 +163,9 @@ class BatteryAlarmKafkaAction extends Action {
 						'touser'=>$send_user['wx_open_id'],
 						'template_id' => $bat_template_id, //"NeSrB4ViIkRMOuCtoA6BIPPi_N5L-B5zaWcIXJZwkD0",
 						'data' => [
-							'first' => [ 'value' =>$send_user['realname'].'的电子卡电量过低,请及时充电', 'color' => '#173177' ],
+							'first' => [ 'value' =>$send_user['realname'].'的设备电量过低,请及时充电', 'color' => '#173177' ],
 							'keyword1' => [ 'value' => $data['tid'], 'color' => '#173177' ],
-							'keyword2' => [ 'value' => '低电量告警', 'color' => '#173177' ],
-							'keyword3' => [ 'value' => date('Y-m-d H:i:s'), 'color' => '#173177' ],
+							'keyword2' => [ 'value' => date('Y-m-d H:i:s'), 'color' => '#173177' ],
 							'remark' => [ 'value' => '', 'color' => '#173177' ],
 						],
 				);
@@ -314,13 +182,8 @@ class BatteryAlarmKafkaAction extends Action {
 						'creator_id'=>$device_info['creator_id']
 				);
 				M('wx_push_result_log')->createAdd($push_res_data);
-			}
-				
-		
-			
-				
-			
 			
+		
 		}
 		$cond=array('imei'=>$data['tid']);
 		//M('users')->createSave($cond,array('battery_level'=> $data['battery_level']));

+ 6 - 6
Home/Lib/Action/WxApiAction.class.php

@@ -476,13 +476,13 @@ class WxApiAction extends Action {
 		//student_id
 		//queyRouteListByStudentId
 		$routeInfo = [];
-			$lngLatAlter = new \Jms\Algo\Geometry();
+		$lngLatAlter = new \Jms\Algo\Geometry();
 			
-			$routeInfo = queyGpsRouteListByimei($imei, $startTime, $endTime);
+		$routeInfo = queyGpsRouteListByimei($imei, $startTime, $endTime);
 		
 			//$routeInfo = analyzeRouteInfoGaodeBatch($routeInfo);
-			$routeInfo = analyzeRouteInfoWayzBatch($routeInfo);
-			$arr = [];
+		$routeInfo = analyzeRouteInfoWayzBatch($routeInfo);
+		$arr = [];
 			foreach($routeInfo as &$v){
 				$v['lat'] = $v['Latitude'];
 				$v['lng'] = $v['Longitude'];
@@ -490,8 +490,8 @@ class WxApiAction extends Action {
 					array_push($arr, $v);
 				}
 			}
-			$routeInfo =$arr;
-			//$routeInfo =bmapFilterOutliers($arr);
+		$routeInfo =$arr;
+		//$routeInfo =bmapFilterOutliers($arr);