123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- namespace Home\Controller;
- use Think\Controller;
- class MaintenanceController extends ComController
- {
- //维保计划列表
- public function getMaintenanceList()
- {
- $Data = I();
- $Res = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $_SESSION['phone'] . "' and zn in(1,3,5,7)");
- $time = date("Y-m-d");
- if (empty($Res)) {
- $res['msg'] = '操作失败,该用户不存在巡检权限';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- $person_id_count = count($Res);
- $person_id__list = '';
- for ($i = 0; $i < $person_id_count; $i++) {
- if ($i == 0) {
- $person_id__list = $Res[$i]['id'];
- } else {
- $person_id__list .= ',' . $Res[$i]['id'];
- }
- }
- $team_res = query_187_ytIoT("select a.team_id from ytiot_xj_team_personnel as a join ytiot_xj_plan_team as b on a.team_id=b.id where b.person_liable_id in(" . $person_id__list . ") or a.people_id in(" . $person_id__list . ") group by a.team_id");
- if (empty($team_res)) {
- $res['msg'] = '操作失败,该用户不巡检团队中';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- $team_id_count = count($team_res);
- $team_id_list = '';
- for ($i = 0; $i < $team_id_count; $i++) {
- if ($i == 0) {
- $team_id_list = $team_res[$i]['team_id'];
- } else {
- $team_id_list .= ',' . $team_res[$i]['team_id'];
- }
- }
- $plan_child_res = query_187_ytIoT("select a.*,b.cycle from ytiot_xj_plan_child as a join ytiot_xj_plan_master as b on a.zb_id=b.id where a.team_id in(" . $team_id_list . ") and a.data2='2'");
- foreach ($plan_child_res as $key => $value) {
- if (($plan_child_res[$key]['cycle'] == 0 && $plan_child_res[$key]['inspect_date'] == $time) ||
- ($plan_child_res[$key]['cycle'] == 1 && strtotime("+7 day", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($time)) ||
- ($plan_child_res[$key]['cycle'] == 2 && strtotime("+1 month", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($time))) {
- $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 ($spot_operation_record_res!=null && $plan_master_res!=null)
- 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 getMaintenanceRecorList()
- {
- $Data = I();
- $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where data3=2 and data2=2");
- 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 getMaintenanceRecordDetails()
- {
- $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 getMaintenanceDetails()
- {
- $Data = I("");
- $record_id = $Data['id'];
- $plan_child_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=".$record_id." and data2='2'");
- $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 setMaintenance(){
- $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);
- exit();
- } else {
- $res['msg'] = '操作失败';
- $res['flag'] = false;
- echo json_encode($res);
- exit();
- }
- }
- }
- }
- }
|