$value) { $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $value['zb_id']); $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $value['id']); // if (!empty($spot_operation_record_res)&& !empty($plan_master_res)) foreach ($spot_operation_record_res as $key1 => $value1) { $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);; if (!empty($dw_res)) { $arr[$key]['id'] = $plan_child_res[$key]['id']; $arr[$key]['completion'] = $plan_child_res[$key]['completion']; $arr[$key]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name']; $arr[$key]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id']; $arr[$key]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name']; $arr[$key]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3']; } } } $res['msg'] = '操作成功'; $res['flag'] = true; $res['data'] = $arr; echo json_encode($res); } //巡检记录列表查询 public function getInspectionRecordList() { $Data = I(); $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where data3=2 and data2=1"); foreach ($Res as $key => $value) { if ($Res[$key]['spot_abnormal'] == 0) { $Res[$key]['spot_status'] = "正常"; } elseif ($Res[$key]['spot_abnormal'] == 1) { $Res[$key]['spot_status'] = "异常"; } elseif ($Res[$key]['spot_abnormal'] == 2) { $Res[$key]['spot_status'] = "故障"; } elseif ($Res[$key]['spot_abnormal'] == 3) { $Res[$key]['spot_status'] = "其他"; } if (!empty($Res[$key]['spot_id'])) { $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[$key]['spot_id']); $Res[$key]['spot_name'] = $points_res[0]['spot_name']; $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[$key]['zb_id']); $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']); $Res[$key]['plan_name'] = $jh_res[0]['plan_name']; } } $res['msg'] = '操作成功'; $res['flag'] = true; $res['company_code'] = $Data['company_code']; $res['data'] = $Res; echo json_encode($res); } //巡检记录详情数据查询 public function getInspectionRecordDetails() { $Data = I(); $record_id = $Data['id']; $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where id=" . $record_id); if ($Res[0]['spot_abnormal'] == 0) { $Res[0]['spot_status'] = "正常"; } elseif ($Res[0]['spot_abnormal'] == 1) { $Res[0]['spot_status'] = "异常"; } elseif ($Res[0]['spot_abnormal'] == 2) { $Res[0]['spot_status'] = "故障"; } elseif ($Res[0]['spot_abnormal'] == 3) { $Res[0]['spot_status'] = "其他"; } if (!empty($Res[0]['spot_id'])) { $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[0]['zb_id']); $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']); $Res[0]['plan_name'] = $jh_res[0]['plan_name']; $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[0]['spot_id']); $Res[0]['spot_name'] = $points_res[0]['spot_name']; $Res[0]['spot_address'] = $points_res[0]['spot_address']; } if (!empty($Res[0]['wbr_id'])) { $zrr_res = query_187_ytIoT("select * from ytiot_xj_inspectors where id=" . $Res[0]['wbr_id']); $Res[0]['name'] = $zrr_res[0]['name']; $Res[0]['phone'] = $zrr_res[0]['phone']; } if (!empty($Res[0]['company_code'])) { $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'"); $Res[0]['owner_name'] = $company_data[0]['owner_name']; $Res[0]['owner_address'] = $company_data[0]['owner_address']; } if (!empty($Res[0]['id'])) { $photos_res = query_187_ytIoT("select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $Res[0]['id']); $Res[0]['report_photos'] = $photos_res[0]['report_photos']; } $res['msg'] = '操作成功'; $res['flag'] = true; $res['company_code'] = $Data['company_code']; $res['data'] = $Res; echo json_encode($res); } //巡检计划详情数据查询 public function getInspectionDetails() { $Data = I(""); $record_id = $Data['id']; $plan_child_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $record_id . " and data2='1'"); $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $plan_child_res[0]['zb_id']); $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $plan_child_res[0]['id']); $arr[0]['id'] = $plan_child_res[0]['id']; $arr[0]['completion'] = $plan_child_res[0]['completion']; $arr[0]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name']; foreach ($spot_operation_record_res as $key1 => $value1) { $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']); if (!empty($dw_res)) { $arr[0]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id']; $arr[0]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name']; $arr[0]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3']; } } $res['msg'] = '操作成功'; $res['flag'] = true; $res['company_code'] = $Data['company_code']; $res['data'] = $arr; echo json_encode($res); } //巡检计划巡检功能接口 public function setInspection() { $Data = I(); $wc_time = date("Y-m-d H:i:s"); $zb_id = $Data['zb_id']; $spot_id = $Data['spot_id']; $spot_abnormal = $Data['spot_abnormal']; $dwsb_remarks = $Data['dwsb_remarks']; $data1 = $Data['report_name']; $phone = $_SESSION['phone']; $people_id_res = query_187_ytIoT(" select team_id,inspect_date,end_time,company_code,completion from ytiot_xj_plan_child where id=" . $zb_id); if (empty($people_id_res)) { $res['msg'] = '操作失败,系统内部查询出现错误'; $res['flag'] = false; echo json_encode($res); exit(); } $company_code = $people_id_res[0]['company_code']; $people_id_res1 = query_187_ytIoT("select person_liable_id from ytiot_xj_plan_team where id=" . $people_id_res[0]['team_id']); if (empty($people_id_res1)) { $res['msg'] = '操作失败,系统内部查询出现错误'; $res['flag'] = false; echo json_encode($res); exit(); } $people_id = $people_id_res1[0]['person_liable_id']; $people_id_data = query_187_ytIoT("select people_id from ytiot_xj_team_personnel where team_id=" . $people_id_res[0]['team_id']); $str = ""; foreach ($people_id_data as $val) { $str .= "" . $val['people_id'] . ","; } if (empty($people_id_data)){ $people_id_list = $people_id; }else{ $people_id_list = substr($str, 0, strlen($str) - 1) . ',' . $people_id; } $people_data = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $phone . "' and id in(" . $people_id_list . ")"); if (empty($people_data)) { $res['msg'] = '操作失败,该巡检人无巡检权限'; $res['flag'] = false; echo json_encode($res); exit(); } $wbr_id = $people_data[0]['id']; $tmpFilePath = $_FILES['img']['tmp_name']; if ($_FILES["img"]["error"] == 1) { $res['msg'] = '图片上传失败,图片大小超过限制2M'; $res['flag'] = false; echo json_encode($res); exit(); } if (empty($tmpFilePath)) { $res['msg'] = '图片上传失败'; $res['flag'] = false; echo json_encode($res); exit(); } $FileCode = date('YmdHis') . rand(1000, 9999); $FileName = $_FILES['img']['name']; $FileType = strtolower(substr(strrchr($FileName, '.'), 1)); $BasefName = $FileCode . '.' . $FileType; // $newFilePath = '/var/www/html/jdxf/Maintinfo/image/' . $BasefName; $newFilePath = 'D:/phpStudy/PHPTutorial/WWW/USKYZHAF/img/' . $BasefName; $newFilePath1 = 'https://iot.usky.cn/jdxf/Maintinfo/image/' . $BasefName; if (!move_uploaded_file($tmpFilePath, $newFilePath)) { $res['msg'] = '图片上传失败,上传路径错误'; $res['flag'] = false; echo json_encode($res); exit(); } $res1 = insert_187_ytIoT("UPDATE ytiot_xj_spot_operation_record set people_id=" . $people_id . ",spot_abnormal=" . $spot_abnormal . ",wc_time='" . $wc_time . "',dwsb_remarks='" . $dwsb_remarks . "',data3='2',wbr_id=" . $wbr_id . " where zb_id=" . $zb_id . " and spot_id=" . $spot_id); if (!$res1) { $res['msg'] = '图片上传成功,数据保存失败'; $res['flag'] = false; echo json_encode($res); exit(); } $photosres = query_187_ytIoT("select id,spot_abnormal,data1 from ytiot_xj_spot_operation_record where zb_id=" . $zb_id . " and spot_id=" . $spot_id . " and wc_time='" . $wc_time . "'"); if (!empty($photosres)) { if ($photosres[0]['spot_abnormal'] == 1 || $photosres[0]['spot_abnormal'] == 2 || $photosres[0]['spot_abnormal'] == 3) { $company_data = M()->query("select owner_id from sp_owner_company where building_id='" . $company_code . "'"); $wx_name = '设备异常'; $lsxx = $wc_time . "," . $wx_name; $photos_res = insert_187_ytIoT("insert into ytiot_xj_event_processing (id,dwjl_id,wx_name,sj_type,y_complete_time,person_liable,zp_remarks,user_name,cl_type,jg_remarks,sh_remarks,sh_time,cl_time,picture_path,data1,data2,data3) value (''," . $photosres[0]['id'] . ",'" . $data1 . "',0,'',null,'','" . $photosres[0]['data1'] . "',0,'','','','','','','" . $company_data[0]['owner_id'] . "','" . $lsxx . "')"); } $photos_res = insert_187_ytIoT("insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (" . $photosres[0]['id'] . ",'" . $newFilePath1 . "')"); if (!$photos_res) { $res['msg'] = '操作失败,上传成功,路径保存失败'; $res['flag'] = false; echo json_encode($res); exit(); } $dwzsl = query_187_ytIoT("select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id); $yxjzsl = query_187_ytIoT("select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id . " and data3='2'"); if ($dwzsl[0]['dwzsl'] == $yxjzsl[0]['yxjzsl']) { $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=100,data3='" . $wc_time . "' where id=" . $zb_id); if ($wcqk_res) { $res['msg'] = '操作成功'; $res['flag'] = true; echo json_encode($res); exit(); } else { $res['msg'] = '操作失败'; $res['flag'] = false; echo json_encode($res); exit(); } } else { $yg = 1 / $dwzsl[0]['dwzsl'] * 100; $completion = $people_id_res[0]['completion'] + $yg; $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=" . $completion . " where id=" . $zb_id); if ($wcqk_res) { $res['msg'] = '操作成功'; $res['flag'] = true; echo json_encode($res); } else { $res['msg'] = '操作失败'; $res['flag'] = false; echo json_encode($res); } } } } }