|
@@ -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']));
|