MaintenanceController.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class MaintenanceController extends ComController
  5. {
  6. //维保计划列表
  7. public function getMaintenanceList()
  8. {
  9. $Data = I();
  10. $Res = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $_SESSION['phone'] . "' and zn in(1,3,5,7)");
  11. $time = date("Y-m-d");
  12. if (empty($Res)) {
  13. $res['msg'] = '操作失败,该用户不存在巡检权限';
  14. $res['flag'] = false;
  15. echo json_encode($res);
  16. exit();
  17. }
  18. $person_id_count = count($Res);
  19. $person_id__list = '';
  20. for ($i = 0; $i < $person_id_count; $i++) {
  21. if ($i == 0) {
  22. $person_id__list = $Res[$i]['id'];
  23. } else {
  24. $person_id__list .= ',' . $Res[$i]['id'];
  25. }
  26. }
  27. $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");
  28. if (empty($team_res)) {
  29. $res['msg'] = '操作失败,该用户不巡检团队中';
  30. $res['flag'] = false;
  31. echo json_encode($res);
  32. exit();
  33. }
  34. $team_id_count = count($team_res);
  35. $team_id_list = '';
  36. for ($i = 0; $i < $team_id_count; $i++) {
  37. if ($i == 0) {
  38. $team_id_list = $team_res[$i]['team_id'];
  39. } else {
  40. $team_id_list .= ',' . $team_res[$i]['team_id'];
  41. }
  42. }
  43. $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'");
  44. // print_r($plan_child_res);
  45. $a=0;
  46. foreach ($plan_child_res as $key => $value) {
  47. if (($plan_child_res[$key]['cycle'] == 0 && $plan_child_res[$key]['inspect_date'] == $time) ||
  48. ($plan_child_res[$key]['cycle'] == 1 && strtotime("+7 day", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($time)) ||
  49. ($plan_child_res[$key]['cycle'] == 2 && strtotime("+1 month", strtotime($plan_child_res[$key]['inspect_date'])) > strtotime($time))) {
  50. $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $value['zb_id']);
  51. $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $value['id']);
  52. // if ($spot_operation_record_res!=null && $plan_master_res!=null)
  53. foreach ($spot_operation_record_res as $key1 => $value1) {
  54. $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);
  55. if (!empty($dw_res)) {
  56. $arr[$a]['id'] = $plan_child_res[$key]['id'];
  57. $arr[$a]['completion'] = $plan_child_res[$key]['completion'];
  58. $arr[$a]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  59. $arr[$a]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  60. $arr[$a]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  61. $arr[$a]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  62. }
  63. }
  64. $a++;
  65. }
  66. }
  67. // print_r($arr);
  68. $res['msg'] = '操作成功';
  69. $res['flag'] = true;
  70. $res['data'] = $arr;
  71. echo json_encode($res);
  72. }
  73. //维保记录列表数据查询
  74. public function getMaintenanceRecorList()
  75. {
  76. $Data = I();
  77. $Res = query_187_ytIoT("SELECT a.*, b.spot_name,d.plan_name FROM ytiot_xj_spot_operation_record AS a
  78. JOIN ytiot_xj_inspection_points AS b ON b.id = a.spot_id
  79. JOIN ytiot_xj_plan_child as c ON c.id=a.zb_id
  80. JOIN ytiot_xj_plan_master AS d ON d.id = c.zb_id
  81. WHERE a.data3 = 2 AND a.data2 = 2 ORDER BY a.id DESC");
  82. foreach ($Res as $key => $value) {
  83. if ($Res[$key]['spot_abnormal'] == 0) {
  84. $Res[$key]['spot_status'] = "正常";
  85. } elseif ($Res[$key]['spot_abnormal'] == 1) {
  86. $Res[$key]['spot_status'] = "异常";
  87. } elseif ($Res[$key]['spot_abnormal'] == 2) {
  88. $Res[$key]['spot_status'] = "故障";
  89. } elseif ($Res[$key]['spot_abnormal'] == 3) {
  90. $Res[$key]['spot_status'] = "其他";
  91. }
  92. }
  93. $res['msg'] = '操作成功';
  94. $res['flag'] = true;
  95. $res['company_code'] = $Data['company_code'];
  96. $res['data'] = $Res;
  97. echo json_encode($res);
  98. }
  99. //维保记录详情查询
  100. public function getMaintenanceRecordDetails()
  101. {
  102. $Data = I();
  103. $record_id = $Data['id'];
  104. $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where id=" . $record_id);
  105. if ($Res[0]['spot_abnormal'] == 0) {
  106. $Res[0]['spot_status'] = "正常";
  107. } elseif ($Res[0]['spot_abnormal'] == 1) {
  108. $Res[0]['spot_status'] = "异常";
  109. } elseif ($Res[0]['spot_abnormal'] == 2) {
  110. $Res[0]['spot_status'] = "故障";
  111. } elseif ($Res[0]['spot_abnormal'] == 3) {
  112. $Res[0]['spot_status'] = "其他";
  113. }
  114. if (!empty($Res[0]['spot_id'])) {
  115. $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[0]['zb_id']);
  116. $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']);
  117. $Res[0]['plan_name'] = $jh_res[0]['plan_name'];
  118. $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[0]['spot_id']);
  119. $Res[0]['spot_name'] = $points_res[0]['spot_name'];
  120. $Res[0]['spot_address'] = $points_res[0]['spot_address'];
  121. }
  122. if (!empty($Res[0]['wbr_id'])) {
  123. $zrr_res = query_187_ytIoT("select * from ytiot_xj_inspectors where id=" . $Res[0]['wbr_id']);
  124. $Res[0]['name'] = $zrr_res[0]['name'];
  125. $Res[0]['phone'] = $zrr_res[0]['phone'];
  126. }
  127. if (!empty($Res[0]['company_code'])) {
  128. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'");
  129. $Res[0]['owner_name'] = $company_data[0]['owner_name'];
  130. $Res[0]['owner_address'] = $company_data[0]['owner_address'];
  131. }
  132. if (!empty($Res[0]['id'])) {
  133. $photos_res = query_187_ytIoT("select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $Res[0]['id']);
  134. $Res[0]['report_photos'] = $photos_res[0]['report_photos'];
  135. }
  136. $res['msg'] = '操作成功';
  137. $res['flag'] = true;
  138. $res['company_code'] = $Data['company_code'];
  139. $res['data'] = $Res;
  140. echo json_encode($res);
  141. }
  142. //维保计划详情数据查询
  143. public function getMaintenanceDetails()
  144. {
  145. $Data = I("");
  146. $record_id = $Data['id'];
  147. $plan_child_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=".$record_id." and data2='2'");
  148. $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $plan_child_res[0]['zb_id']);
  149. $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $plan_child_res[0]['id']);
  150. $arr[0]['id'] = $plan_child_res[0]['id'];
  151. $arr[0]['completion'] = $plan_child_res[0]['completion'];
  152. $arr[0]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  153. foreach ($spot_operation_record_res as $key1 => $value1) {
  154. $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);
  155. if (!empty($dw_res)) {
  156. $arr[0]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  157. $arr[0]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  158. $arr[0]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  159. }
  160. }
  161. $res['msg'] = '操作成功';
  162. $res['flag'] = true;
  163. $res['company_code'] = $Data['company_code'];
  164. $res['data'] = $arr;
  165. echo json_encode($res);
  166. }
  167. //维保计划维保功能接口
  168. public function setMaintenance(){
  169. $Data = I();
  170. $wc_time = date("Y-m-d H:i:s");
  171. $zb_id = $Data['zb_id'];
  172. $spot_id = $Data['spot_id'];
  173. $spot_abnormal = $Data['spot_abnormal'];
  174. $dwsb_remarks = $Data['dwsb_remarks'];
  175. $data1 = $Data['report_name'];
  176. $phone = $_SESSION['phone'];
  177. $newFilePath1= $Data['img'];
  178. $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);
  179. if (empty($people_id_res)) {
  180. $res['msg'] = '操作失败,系统内部查询出现错误';
  181. $res['flag'] = false;
  182. echo json_encode($res);
  183. exit();
  184. }
  185. $company_code = $people_id_res[0]['company_code'];
  186. $people_id_res1 = query_187_ytIoT("select person_liable_id from ytiot_xj_plan_team where id=" . $people_id_res[0]['team_id']);
  187. if (empty($people_id_res1)) {
  188. $res['msg'] = '操作失败,系统内部查询出现错误';
  189. $res['flag'] = false;
  190. echo json_encode($res);
  191. exit();
  192. }
  193. $people_id = $people_id_res1[0]['person_liable_id'];
  194. $people_id_data = query_187_ytIoT("select people_id from ytiot_xj_team_personnel where team_id=" . $people_id_res[0]['team_id']);
  195. $str = "";
  196. foreach ($people_id_data as $val) {
  197. $str .= "" . $val['people_id'] . ",";
  198. }
  199. if (empty($people_id_data)){
  200. $people_id_list = $people_id;
  201. }else{
  202. $people_id_list = substr($str, 0, strlen($str) - 1) . ',' . $people_id;
  203. }
  204. $people_data = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $phone . "' and id in(" . $people_id_list . ")");
  205. if (empty($people_data)) {
  206. $res['msg'] = '操作失败,该巡检人无巡检权限';
  207. $res['flag'] = false;
  208. echo json_encode($res);
  209. exit();
  210. }
  211. $wbr_id = $people_data[0]['id'];
  212. // $tmpFilePath = $_FILES['img']['tmp_name'];
  213. // if ($_FILES["img"]["error"] == 1) {
  214. // $res['msg'] = '图片上传失败,图片大小超过限制2M';
  215. // $res['flag'] = false;
  216. // echo json_encode($res);
  217. // exit();
  218. // }
  219. // if (empty($tmpFilePath)) {
  220. // $res['msg'] = '图片上传失败';
  221. // $res['flag'] = false;
  222. // echo json_encode($res);
  223. // exit();
  224. // }
  225. // $FileCode = date('YmdHis') . rand(1000, 9999);
  226. // $FileName = $_FILES['img']['name'];
  227. // $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  228. // $BasefName = $FileCode . '.' . $FileType;
  229. // $newFilePath = '/var/www/html/jdxf/Maintinfo/image/' . $BasefName;
  230. // $newFilePath = 'D:/phpStudy/PHPTutorial/WWW/USKYZHAF/img/' . $BasefName;
  231. // $newFilePath1 = 'https://iot.usky.cn/jdxf/Maintinfo/image/' . $BasefName;
  232. // if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  233. // $res['msg'] = '图片上传失败,上传路径错误';
  234. // $res['flag'] = false;
  235. // echo json_encode($res);
  236. // exit();
  237. // }
  238. $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 .
  239. " where zb_id=" . $zb_id . " and spot_id=" . $spot_id);
  240. if (!$res1) {
  241. $res['msg'] = '图片上传成功,数据保存失败';
  242. $res['flag'] = false;
  243. echo json_encode($res);
  244. exit();
  245. }
  246. $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 . "'");
  247. if (!empty($photosres)) {
  248. if ($photosres[0]['spot_abnormal'] == 1 || $photosres[0]['spot_abnormal'] == 2 || $photosres[0]['spot_abnormal'] == 3) {
  249. $company_data = M()->query("select owner_id from sp_owner_company where building_id='" . $company_code . "'");
  250. $wx_name = '设备异常';
  251. $lsxx = $wc_time . "," . $wx_name;
  252. $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 . "')");
  253. }
  254. $photos_res = insert_187_ytIoT("insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (" . $photosres[0]['id'] . ",'" . $newFilePath1 . "')");
  255. if (!$photos_res) {
  256. $res['msg'] = '操作失败,上传成功,路径保存失败';
  257. $res['flag'] = false;
  258. echo json_encode($res);
  259. exit();
  260. }
  261. $dwzsl = query_187_ytIoT("select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id);
  262. $yxjzsl = query_187_ytIoT("select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id . " and data3='2'");
  263. if ($dwzsl[0]['dwzsl'] == $yxjzsl[0]['yxjzsl']) {
  264. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=100,data3='" . $wc_time . "' where id=" . $zb_id);
  265. if ($wcqk_res) {
  266. $res['msg'] = '操作成功';
  267. $res['flag'] = true;
  268. echo json_encode($res);
  269. exit();
  270. } else {
  271. $res['msg'] = '操作失败';
  272. $res['flag'] = false;
  273. echo json_encode($res);
  274. exit();
  275. }
  276. } else {
  277. $yg = 1 / $dwzsl[0]['dwzsl'] * 100;
  278. $completion = $people_id_res[0]['completion'] + $yg;
  279. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=" . $completion . " where id=" . $zb_id);
  280. if ($wcqk_res) {
  281. $res['msg'] = '操作成功';
  282. $res['flag'] = true;
  283. echo json_encode($res);
  284. exit();
  285. } else {
  286. $res['msg'] = '操作失败';
  287. $res['flag'] = false;
  288. echo json_encode($res);
  289. exit();
  290. }
  291. }
  292. }
  293. }
  294. }