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.
 
 
 
 
 
 

70 lines
3.6 KiB

<?php
error_reporting(0);
include '../DB.php';
try {
$conn=new DB();
if($conn){
$account=[];
$customerid=$_REQUEST['customerid'];
$sql="SELECT facilityno,address,numberofstop,numberoffloor,speed from facility where customerid='$customerid'";
if ($result=$conn->getAll($sql)) {
foreach ($result as $k => $v) {
$facility_arr[] = $v["facilityno"];
}
}
$schedule_arr = $fault_arr = [];
$facility_str = implode("','", $facility_arr);
if ($facility_str) {
// 電梯最近一次保養記錄
$sql ="select id, facilityno, actualdate, item, item_detail, result from schedule where (facilityno, actualdate) in ";
$sql.="(select facilityno, max(actualdate) from schedule where facilityno in ('".$facility_str."') and actualdate is not null group by facilityno)";
$res = $conn->getAll($sql);
for ($i=0; $i<count($res); $i++) {
$item_arr = json_decode($res[$i]["item"], true);
$item_detail_arr = json_decode($res[$i]["item_detail"], true);
$result_arr = json_decode($res[$i]["result"], true);
$baditems = 0;
$m = count($result_arr);
for ($j=0; $j<$m ; $j++) {
if ($result_arr[$j] > 1) {
$baditems = $baditems + 1;
$schedule_arr[$res[$i]["facilityno"]]["item_detail"] .= $item_detail_arr[$j]."<br>";
}
}
if ($baditems > 0) {
$schedule_arr[$res[$i]["facilityno"]]["baditems"] = "<b style='color:red';>有" . $baditems . "項問題</b>";
} else {
$schedule_arr[$res[$i]["facilityno"]]["baditems"] = "<b style='color:blue';>Good!</b>";
$schedule_arr[$res[$i]["facilityno"]]["item_detail"] = "";
}
$schedule_arr[$res[$i]["facilityno"]]["actualdate"] = $res[$i]["actualdate"];
$schedule_arr[$res[$i]["facilityno"]]["id"] = $res[$i]["id"];
}
// DEMO資料處理
$demo_imei_arr = ['861577063344498', '861577063351097', '861577063351113', '861577063351741', '861577063351774', '861577063352293',
'861577063352749', '861577063352871', '861577063352970', '864442060230983', '864442060231551', '864442060231734',
'864442060239414', '864442060293510', '864442068257731', '864442068361905', '864442068513299', '864442068513380',
'864442068537074', '864442068537082', '864442068537207', '864442068537884', '864442068537934'];
$demo_imei_str = implode("','", $demo_imei_arr);
// 本月電梯實時故障
$sql = "select facilityno, fault_message, create_at from fault_log where facilityno in ('".$facility_str."') and create_at like '".date("Y-m")."%' and (fault_message != ' ') ";
$sql .= "and imei not in ('".$demo_imei_str."')";
$sql .= "and flag <> '1100' ";
$sql .= "order by id desc";
$res = $conn->getAll($sql);
for ($i=0; $i<count($res); $i++) {
if ($res[$i]["create_at"] < $schedule_arr[$res[$i]["facilityno"]]["actualdate"]) {
$fault_arr[$res[$i]["facilityno"]][] = $res[$i]["create_at"]." ".$res[$i]["fault_message"];
}
}
echo json_encode(array($result, $schedule_arr, $fault_arr));
}
}
}catch (Exception $e) {
die($e->getMessage());
}
?>