You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
280 lines
12 KiB
280 lines
12 KiB
<?php
|
|
require_once "database.php";
|
|
$postData = file_get_contents('php://input');
|
|
#echo "收到:" . $postData . "<br>";
|
|
|
|
if ($postData) {
|
|
$data = json_decode($postData, true);
|
|
|
|
//筛选掉eventStatus=0的数据,eventStatus=1产生异常数据,保存到数据库
|
|
if ($data['data']['eventStatus'] == 1 && $data['data']['regCode'] != "748865688VK004XS8AC000000000") {
|
|
$iotnumber = $data['data']['regCode'];
|
|
$db_queryf = "SELECT * FROM facility WHERE iotnumber='$iotnumber'";
|
|
$data1 = mysqli_query($link, $db_queryf);
|
|
$row = mysqli_fetch_array($data1, MYSQLI_ASSOC);
|
|
$facilityno = $row['facilityno'];
|
|
$source = 'Monarch';
|
|
if (empty($data['data']['eventData'])) {
|
|
$flag = $data['data']['eventCode'];
|
|
}else{
|
|
$flag = $data['data']['eventCode'] . '/' . $data['data']['eventData'];
|
|
}
|
|
|
|
$eventCode=$data['data']['eventCode'];
|
|
//插入错误记录表
|
|
$imei = $data['data']['regCode'];
|
|
|
|
$fault_level = '';
|
|
$fault_time = $data['data']['eventTime'];
|
|
$fault_level = '';
|
|
|
|
$pass_code = '';
|
|
$start_date = '';
|
|
$end_date = '';
|
|
|
|
$eventStatus = $data['data']['eventStatus'];
|
|
|
|
if (empty($data['data']['eventData'])) {
|
|
$eventData = '';
|
|
} else {
|
|
$eventData = $data['data']['eventData'];
|
|
}
|
|
//判断failureCodeDesc是否为空。如果为空。用eventcode中文代替
|
|
if (empty($data['data']['failureCodeDesc'])) {
|
|
$eventcodeDesc = array(
|
|
"1" => "電話呼救",
|
|
"2" => "手動呼救",
|
|
"3" => "自動呼救",
|
|
"4" => "機房刷卡",
|
|
"5" => "轎頂刷卡",
|
|
"6" => "綜合故障",
|
|
"7" => "檢修狀態",
|
|
"8" => "電梯停電",
|
|
"9" => "電話告警",
|
|
"11" => "通信異常",
|
|
"12" => "雲總機通話",
|
|
"13" => "電壓檢測",
|
|
"14" => "維保簽到"
|
|
);
|
|
$failureCodeDesc = $eventcodeDesc[$eventCode];
|
|
} else {
|
|
$failureCodeDescDate=array(
|
|
"E02" => "加速過電流",
|
|
"E03" => "減速過電流",
|
|
"E04" => "恒速過電流",
|
|
"E05" => "加速過電壓",
|
|
"E06" => "減速過電壓",
|
|
"E07" => "恒速過電壓",
|
|
"E09" => "欠電壓故障",
|
|
"E10" => "控制器超載",
|
|
"E11" => "電機超載",
|
|
"E13" => "輸出側缺相",
|
|
"E14" => "模組過熱",
|
|
"E15" => "輸出側異常",
|
|
"E16" => "電流控制故障",
|
|
"E17" => "調諧時編碼器干擾",
|
|
"E18" => "硬體信號檢測故障",
|
|
"E19" => "電機調諧故障",
|
|
"E20" => "速度回饋錯誤故障",
|
|
"E21" => "參數設置錯誤",
|
|
"E22" => "平層信號異常",
|
|
"E23" => "短路故障",
|
|
"E24" => "RTC時鐘故障",
|
|
"E25" => "存儲資料異常",
|
|
"E26" => "地震信號",
|
|
"E27" => "專機故障",
|
|
"E28" => "維修故障",
|
|
"E29" => "封星故障",
|
|
"E30" => "電梯位置異常",
|
|
"E33" => "電梯速度異常",
|
|
"E34" => "邏輯故障",
|
|
"E35" => "井道自學習數據異常",
|
|
"E36" => "運行接觸器回饋異常",
|
|
"E37" => "新國標新增抱閘接觸器故障或抱閘控制輸出回饋異常",
|
|
"E38" => "旋轉編碼器信號異常",
|
|
"E39" => "電機過熱故障或閘機過熱故障",
|
|
"E40" => "保留",
|
|
"E41" => "安全回路斷開",
|
|
"E42" => "運行中門鎖斷開",
|
|
"E43" => "上限位元信號異常",
|
|
"E44" => "下限位元信號異常",
|
|
"E45" => "強迫減速開關異常",
|
|
"E47" => "SCB故障",
|
|
"E48" => "開門故障",
|
|
"E49" => "關門故障",
|
|
"E50" => "平層信號連續丟失",
|
|
"E51" => "CAN通信故障或廠家握手故障",
|
|
"E52" => "外召通信故障或廠家握手故障",
|
|
"E53" => "門鎖故障",
|
|
"E54" => "檢修啟動過電流",
|
|
"E55" => "換層停靠故障",
|
|
"E56" => "開關門到位信號故障",
|
|
"E57" => "SPI通信故障",
|
|
"E58" => "位置保護開關異常",
|
|
"E59" => "專用故障(E59)",
|
|
"E60" => "專用故障(E60)",
|
|
"E61" => "抱閘電源故障",
|
|
"E62" => "類比量斷線",
|
|
"E63" => "專用故障(E63)",
|
|
"E64" => "外部故障",
|
|
"E65" => "UCMP故障",
|
|
"E66" => "抱閘制動力故障",
|
|
"E74" => "STO故障",
|
|
"E77" => "消載故障",
|
|
"E79" => "許可權認證故障",
|
|
"E89" => "專用故障(E89)",
|
|
"E94" => "許可權認證提示"
|
|
);
|
|
//$failureCodeDesc = $data['data']['failureCodeDesc'];
|
|
$eventDatacode = $data['data']['eventData'];
|
|
$failureCodeDesc =$failureCodeDescDate[$eventDatacode];
|
|
}
|
|
$fault_message =$failureCodeDesc;
|
|
$creater = 'system';
|
|
$create_at = date('Y/m/d H:i:s');
|
|
$db_query = "insert into fault_log(facilityno,source,imei,flag,fault_message,eventStatus,eventData,failureCodeDesc";
|
|
$db_query .= ",fault_level,fault_time,pass_code,start_date,end_date,creater,create_at) values (";
|
|
$db_query .= "'$facilityno', '$source', '$imei', '$flag', '$fault_message','$eventStatus','$eventData','$failureCodeDesc','$fault_level',";
|
|
$db_query .= "'$fault_time', '$pass_code', '$start_date', '$end_date',";
|
|
$db_query .= "'$creater','$create_at')";
|
|
mysqli_query($link, $db_query);
|
|
|
|
//根据imei值查询电梯信息
|
|
$accountid = $row['customerid'];
|
|
$message_detail = '電梯編號:' . $row['facilityno'] . '地址:' . $row['address'] . '-' . $fault_message;//消息内容
|
|
$pushed_time = date('Y/m/d H:i:s');//系统推送时间
|
|
$push_messagecreater = 'system';
|
|
$push_messagecreate_at = date('Y/m/d H:i:s');
|
|
$push_messagedb_query = "insert into push_message(accountid,message_detail,pushed_time,source";
|
|
$push_messagedb_query .= ",creater,create_at) values (";
|
|
$push_messagedb_query .= "'$accountid', '$message_detail', '$pushed_time','$source',";
|
|
$push_messagedb_query .= "'$push_messagecreater','$push_messagecreate_at')";
|
|
mysqli_query($link, $push_messagedb_query);
|
|
|
|
// //插入客户受付表
|
|
|
|
$repairerid=$row['repairerid'];//保养员id;
|
|
$repairername=$row['repairername'];//保养员i姓名;
|
|
//查询客户姓名
|
|
$accountidA=$row['customerid'];
|
|
$db_query4 = "SELECT * FROM account WHERE accountid='$accountidA'";
|
|
$data4 = mysqli_query($link,$db_query4);
|
|
$row4 = mysqli_fetch_array($data4, MYSQLI_ASSOC);
|
|
|
|
|
|
$facilityno = $row['facilityno'];
|
|
$sitename = $row['customerid'];
|
|
$customname=$row4['name'];//客户姓名;
|
|
$customtel=$row4['tel'];//客户电话;
|
|
$caller = 'system/Monarch';
|
|
$customerconfirmationbar = '';
|
|
$address = $row['address'];
|
|
$buildingnumber = '';
|
|
$positionnumber = '';
|
|
$maintenanceoperationcategory = '';
|
|
$brandmodel = '';
|
|
$faultstate = $fault_message;
|
|
$investigationprocess = '';
|
|
$causeanalysis = '';
|
|
$processingprocess = '';
|
|
$calltime = date('Y/m/d H:i:s');
|
|
$arrivaltime = '';
|
|
$completiontime = '';
|
|
$returntime = '';
|
|
$handlestaff=$repairerid;
|
|
$handstaffname=$repairername;
|
|
$supportstaff = '';
|
|
$supporttime = '';
|
|
if (empty($data['data']['eventData'])) {
|
|
$faultcode = $data['data']['eventCode'];
|
|
}else{
|
|
$faultcode = $data['data']['eventCode'] . '/' . $data['data']['eventData'];
|
|
}
|
|
|
|
$remarks = '';
|
|
$operationstaff = 'system';
|
|
$filingstaff = '';
|
|
$supervisor = '';
|
|
$creater = 'system';
|
|
$create_at = date('Y/m/d H:i:s');
|
|
$updatee_at = date('Y/m/d H:i:s');
|
|
|
|
$db_query1 = "insert into fault_notification_job_handling(facilityno,sitename,customtel,customname,caller,customerconfirmationbar,address";
|
|
$db_query1 .= ",buildingnumber,positionnumber,maintenanceoperationcategory,brandmodel,faultstate,investigationprocess";
|
|
$db_query1 .= ",causeanalysis,processingprocess,calltime,arrivaltime,completiontime,returntime";
|
|
$db_query1 .= ",handlestaff,handstaffname,supportstaff,supporttime,faultcode,remarks,operationstaff,filingstaff";
|
|
$db_query1 .= ",iotnumber,supervisor,creater,create_at,updatee_at) values (";
|
|
$db_query1 .= "'$facilityno', '$sitename','$customtel','$customname', '$caller', '$customerconfirmationbar', '$address', '$buildingnumber',";
|
|
$db_query1 .= "'$positionnumber', '$maintenanceoperationcategory', '$brandmodel', '$faultstate','$investigationprocess',";
|
|
$db_query1 .= "'$causeanalysis','$processingprocess','$calltime','$arrivaltime','$completiontime','$returntime',";
|
|
$db_query1 .= "'$handlestaff','$handstaffname','$supportstaff','$supporttime','$faultcode','$remarks','$operationstaff','$filingstaff',";
|
|
$db_query1 .= "'$iotnumber','$supervisor','$creater','$create_at','$updatee_at')";
|
|
mysqli_query($link, $db_query1);
|
|
|
|
|
|
if ($mid = mysqli_insert_id($link)) {
|
|
|
|
if (mysqli_affected_rows($link) > 0) {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增成功')";
|
|
echo "</script>";
|
|
|
|
} else {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增失敗,請重新操作[I]')";
|
|
echo "</script>";
|
|
}
|
|
} else {
|
|
echo "<script type ='text/JavaScript'>";
|
|
echo "alert('新增失敗,請重新操作[M]')";
|
|
echo "</script>";
|
|
}
|
|
|
|
mysqli_close($link);
|
|
|
|
//以下推送到客户端消息
|
|
$access_token = array();
|
|
$access_token[]="blymLDSO21gDaCXA6nJ2jf6fEZTNE0wEwANbLAhKMhM";
|
|
$TargetCount = count($access_token);
|
|
$Push_Content['message'] = $faultstate . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "電梯編號: " . $facilityno . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "故障代碼: " . $faultcode . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "故障時間: " . $calltime . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "電梯地址: " . $address . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "客戶編號: " . $sitename . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "客戶名稱: " . $customname . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "客戶電話: " . $customtel . "\n";
|
|
$Push_Content['message'] = $Push_Content['message'] . "保養員: " . $handstaffname . "(" . $handlestaff . ")";
|
|
#$Push_Content['message'] = $Push_Content['message'] . "發生時間: " . date('Y-m-d H:i:s');
|
|
|
|
for ($i=0;$i<$TargetCount;$i++) {
|
|
$ch = curl_init("https://notify-api.line.me/api/notify");
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Push_Content));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
'Content-Type: application/x-www-form-urlencoded',
|
|
'Authorization: Bearer '.$access_token[$i]
|
|
));
|
|
$response_json_str = curl_exec($ch);
|
|
curl_close($ch);
|
|
}
|
|
//以上推送到客户端消息
|
|
} else {
|
|
echo "2222";
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
$myfile = fopen("receive_inovance.txt", "a") or die("Unable to open file!");
|
|
fwrite($myfile, "Got it: " . $postData . date('Y/m/d H:i:s') . "\n");
|
|
fclose($myfile);
|
|
|
|
?>
|