InspectionController.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class InspectionController extends ComController
  5. {
  6. //巡检计划列表查询
  7. public function getInspectionList()
  8. {
  9. $Data = I();
  10. $Res = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $_SESSION['phone'] . "' and zn in(2,3,6,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 * from ytiot_xj_plan_child where inspect_date='" . $time . "' and team_id in(" . $team_id_list . ") and data2='1'");
  44. foreach ($plan_child_res as $key => $value) {
  45. $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $value['zb_id']);
  46. $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $value['id']);
  47. // if (!empty($spot_operation_record_res)&& !empty($plan_master_res))
  48. foreach ($spot_operation_record_res as $key1 => $value1) {
  49. $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);;
  50. if (!empty($dw_res)) {
  51. $arr[$key]['id'] = $plan_child_res[$key]['id'];
  52. $arr[$key]['completion'] = $plan_child_res[$key]['completion'];
  53. $arr[$key]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  54. $arr[$key]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  55. $arr[$key]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  56. $arr[$key]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  57. }
  58. }
  59. }
  60. $res['msg'] = '操作成功';
  61. $res['flag'] = true;
  62. $res['data'] = $arr;
  63. echo json_encode($res);
  64. }
  65. //巡检记录列表查询
  66. public function getInspectionRecordList()
  67. {
  68. $Data = I();
  69. $Res = query_187_ytIoT("SELECT a.*, b.spot_name,d.plan_name FROM ytiot_xj_spot_operation_record AS a
  70. JOIN ytiot_xj_inspection_points AS b ON b.id = a.spot_id
  71. JOIN ytiot_xj_plan_child as c ON c.id=a.zb_id
  72. JOIN ytiot_xj_plan_master AS d ON d.id = c.zb_id
  73. WHERE a.data3 = 2 AND a.data2 = 1 ORDER BY a.id DESC");
  74. foreach ($Res as $key => $value) {
  75. if ($Res[$key]['spot_abnormal'] == 0) {
  76. $Res[$key]['spot_status'] = "正常";
  77. } elseif ($Res[$key]['spot_abnormal'] == 1) {
  78. $Res[$key]['spot_status'] = "异常";
  79. } elseif ($Res[$key]['spot_abnormal'] == 2) {
  80. $Res[$key]['spot_status'] = "故障";
  81. } elseif ($Res[$key]['spot_abnormal'] == 3) {
  82. $Res[$key]['spot_status'] = "其他";
  83. }
  84. }
  85. $res['msg'] = '操作成功';
  86. $res['flag'] = true;
  87. $res['company_code'] = $Data['company_code'];
  88. $res['data'] = $Res;
  89. echo json_encode($res);
  90. }
  91. //巡检记录详情数据查询
  92. public function getInspectionRecordDetails()
  93. {
  94. $Data = I();
  95. $record_id = $Data['id'];
  96. $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where id=" . $record_id);
  97. if ($Res[0]['spot_abnormal'] == 0) {
  98. $Res[0]['spot_status'] = "正常";
  99. } elseif ($Res[0]['spot_abnormal'] == 1) {
  100. $Res[0]['spot_status'] = "异常";
  101. } elseif ($Res[0]['spot_abnormal'] == 2) {
  102. $Res[0]['spot_status'] = "故障";
  103. } elseif ($Res[0]['spot_abnormal'] == 3) {
  104. $Res[0]['spot_status'] = "其他";
  105. }
  106. if (!empty($Res[0]['spot_id'])) {
  107. $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[0]['zb_id']);
  108. $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']);
  109. $Res[0]['plan_name'] = $jh_res[0]['plan_name'];
  110. $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[0]['spot_id']);
  111. $Res[0]['spot_name'] = $points_res[0]['spot_name'];
  112. $Res[0]['spot_address'] = $points_res[0]['spot_address'];
  113. }
  114. if (!empty($Res[0]['wbr_id'])) {
  115. $zrr_res = query_187_ytIoT("select * from ytiot_xj_inspectors where id=" . $Res[0]['wbr_id']);
  116. $Res[0]['name'] = $zrr_res[0]['name'];
  117. $Res[0]['phone'] = $zrr_res[0]['phone'];
  118. }
  119. if (!empty($Res[0]['company_code'])) {
  120. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'");
  121. $Res[0]['owner_name'] = $company_data[0]['owner_name'];
  122. $Res[0]['owner_address'] = $company_data[0]['owner_address'];
  123. }
  124. if (!empty($Res[0]['id'])) {
  125. $photos_res = query_187_ytIoT("select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $Res[0]['id']);
  126. $Res[0]['report_photos'] = $photos_res[0]['report_photos'];
  127. }
  128. $res['msg'] = '操作成功';
  129. $res['flag'] = true;
  130. $res['company_code'] = $Data['company_code'];
  131. $res['data'] = $Res;
  132. echo json_encode($res);
  133. }
  134. //巡检计划详情数据查询
  135. public function getInspectionDetails()
  136. {
  137. $Data = I("");
  138. $record_id = $Data['id'];
  139. $plan_child_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $record_id . " and data2='1'");
  140. $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $plan_child_res[0]['zb_id']);
  141. $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $plan_child_res[0]['id']);
  142. $arr[0]['id'] = $plan_child_res[0]['id'];
  143. $arr[0]['completion'] = $plan_child_res[0]['completion'];
  144. $arr[0]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  145. foreach ($spot_operation_record_res as $key1 => $value1) {
  146. $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);
  147. if (!empty($dw_res)) {
  148. $arr[0]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  149. $arr[0]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  150. $arr[0]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  151. }
  152. }
  153. $res['msg'] = '操作成功';
  154. $res['flag'] = true;
  155. $res['company_code'] = $Data['company_code'];
  156. $res['data'] = $arr;
  157. echo json_encode($res);
  158. }
  159. //巡检计划巡检功能接口
  160. public function setInspection()
  161. {
  162. $Data = I();
  163. $wc_time = date("Y-m-d H:i:s");
  164. $zb_id = $Data['zb_id'];
  165. $spot_id = $Data['spot_id'];
  166. $spot_abnormal = $Data['spot_abnormal'];
  167. $dwsb_remarks = $Data['dwsb_remarks'];
  168. $data1 = $Data['report_name'];
  169. $phone = $_SESSION['phone'];
  170. $newFilePath1=$Data['img'];
  171. $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);
  172. if (empty($people_id_res)) {
  173. $res['msg'] = '操作失败,系统内部查询出现错误';
  174. $res['flag'] = false;
  175. echo json_encode($res);
  176. exit();
  177. }
  178. $company_code = $people_id_res[0]['company_code'];
  179. $people_id_res1 = query_187_ytIoT("select person_liable_id from ytiot_xj_plan_team where id=" . $people_id_res[0]['team_id']);
  180. if (empty($people_id_res1)) {
  181. $res['msg'] = '操作失败,系统内部查询出现错误';
  182. $res['flag'] = false;
  183. echo json_encode($res);
  184. exit();
  185. }
  186. $people_id = $people_id_res1[0]['person_liable_id'];
  187. $people_id_data = query_187_ytIoT("select people_id from ytiot_xj_team_personnel where team_id=" . $people_id_res[0]['team_id']);
  188. $str = "";
  189. foreach ($people_id_data as $val) {
  190. $str .= "" . $val['people_id'] . ",";
  191. }
  192. if (empty($people_id_data)){
  193. $people_id_list = $people_id;
  194. }else{
  195. $people_id_list = substr($str, 0, strlen($str) - 1) . ',' . $people_id;
  196. }
  197. $people_data = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $phone . "' and id in(" . $people_id_list . ")");
  198. if (empty($people_data)) {
  199. $res['msg'] = '操作失败,该巡检人无巡检权限';
  200. $res['flag'] = false;
  201. echo json_encode($res);
  202. exit();
  203. }
  204. $wbr_id = $people_data[0]['id'];
  205. // $tmpFilePath = $_FILES['img']['tmp_name'];
  206. // if ($_FILES["img"]["error"] == 1) {
  207. // $res['msg'] = '图片上传失败,图片大小超过限制2M';
  208. // $res['flag'] = false;
  209. // echo json_encode($res);
  210. // exit();
  211. // }
  212. // if (empty($tmpFilePath)) {
  213. // $res['msg'] = '图片上传失败';
  214. // $res['flag'] = false;
  215. // echo json_encode($res);
  216. // exit();
  217. // }
  218. // $FileCode = date('YmdHis') . rand(1000, 9999);
  219. // $FileName = $_FILES['img']['name'];
  220. // $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  221. // $BasefName = $FileCode . '.' . $FileType;
  222. // $newFilePath = '/var/www/html/jdxf/Maintinfo/image/' . $BasefName;
  223. // $newFilePath = 'D:/phpStudy/PHPTutorial/WWW/USKYZHAF/img/' . $BasefName;
  224. // $newFilePath1 = 'https://iot.usky.cn/jdxf/Maintinfo/image/' . $BasefName;
  225. // if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  226. // $res['msg'] = '图片上传失败,上传路径错误';
  227. // $res['flag'] = false;
  228. // echo json_encode($res);
  229. // exit();
  230. // }
  231. $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 .
  232. " where zb_id=" . $zb_id . " and spot_id=" . $spot_id);
  233. if (!$res1) {
  234. $res['msg'] = '图片上传成功,数据保存失败';
  235. $res['flag'] = false;
  236. echo json_encode($res);
  237. exit();
  238. }
  239. $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 . "'");
  240. if (!empty($photosres)) {
  241. if ($photosres[0]['spot_abnormal'] == 1 || $photosres[0]['spot_abnormal'] == 2 || $photosres[0]['spot_abnormal'] == 3) {
  242. $company_data = M()->query("select owner_id from sp_owner_company where building_id='" . $company_code . "'");
  243. $wx_name = '设备异常';
  244. $lsxx = $wc_time . "," . $wx_name;
  245. $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 . "')");
  246. }
  247. $photos_res = insert_187_ytIoT("insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (" . $photosres[0]['id'] . ",'" . $newFilePath1 . "')");
  248. if (!$photos_res) {
  249. $res['msg'] = '操作失败,上传成功,路径保存失败';
  250. $res['flag'] = false;
  251. echo json_encode($res);
  252. exit();
  253. }
  254. $dwzsl = query_187_ytIoT("select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id);
  255. $yxjzsl = query_187_ytIoT("select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id . " and data3='2'");
  256. if ($dwzsl[0]['dwzsl'] == $yxjzsl[0]['yxjzsl']) {
  257. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=100,data3='" . $wc_time . "' where id=" . $zb_id);
  258. if ($wcqk_res) {
  259. $res['msg'] = '操作成功';
  260. $res['flag'] = true;
  261. echo json_encode($res);
  262. exit();
  263. } else {
  264. $res['msg'] = '操作失败';
  265. $res['flag'] = false;
  266. echo json_encode($res);
  267. exit();
  268. }
  269. } else {
  270. $yg = 1 / $dwzsl[0]['dwzsl'] * 100;
  271. $completion = $people_id_res[0]['completion'] + $yg;
  272. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=" . $completion . " where id=" . $zb_id);
  273. if ($wcqk_res) {
  274. $res['msg'] = '操作成功';
  275. $res['flag'] = true;
  276. echo json_encode($res);
  277. } else {
  278. $res['msg'] = '操作失败';
  279. $res['flag'] = false;
  280. echo json_encode($res);
  281. }
  282. }
  283. }
  284. }
  285. public function setUpload(){
  286. //图片上传
  287. // print_r($_FILES);
  288. $tmpFilePath = $_FILES['file']['tmp_name'];
  289. if ($_FILES["file"]["error"] == 1) {
  290. $res['msg'] = '图片上传失败,图片大小超过限制2M';
  291. $res['flag'] = false;
  292. echo json_encode($res);
  293. exit();
  294. }
  295. if (empty($tmpFilePath)) {
  296. $res['msg'] = '图片上传失败';
  297. $res['flag'] = false;
  298. echo json_encode($res);
  299. exit();
  300. }
  301. $FileCode = date('YmdHis') . rand(1000, 9999);
  302. $FileName = $_FILES['file']['name'];
  303. $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  304. $BasefName = $FileCode . '.' . $FileType;
  305. // $newFilePath = 'D:/images/' . $BasefName;//本地路径
  306. // $newFilePath = 'D:/PHP_www/USKYZHAF/img/' . $BasefName;//本地路径
  307. $newFilePath = '/var/www/html/USKYZHAF/img/' . $BasefName;//线上路径
  308. // $newFilePath = 'https://qhome.usky.cn/USKYZHAF/img/' . $BasefName;//线上路径
  309. $newFilePath1 = '/USKYZHAF/img/' . $BasefName;
  310. if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  311. $res['msg'] = '图片上传失败,上传路径错误';
  312. $res['flag'] = false;
  313. echo json_encode($res);
  314. exit();
  315. }
  316. $res['msg'] = '上传成功';
  317. $res['flag'] = true;
  318. $res['img_url'] = $newFilePath1;
  319. echo json_encode($res);
  320. }
  321. //已巡检计划详情数据查询
  322. public function getPatrolDetailss()
  323. {
  324. $Data = I();
  325. $zb_id = $Data['zb_id'];
  326. $spot_id = $Data['spot_id'];
  327. $wc_time=date('Y-m-d', time());
  328. // echo $Data['zb_id'];
  329. // print_r("select * from ytiot_xj_spot_operation_record where zb_id=" . $zb_id." and spot_id=".$spot_id." and wc_time like '".$wc_time."%'");
  330. $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $zb_id." and spot_id=".$spot_id." and wc_time like '".$wc_time."%'");
  331. // exit();
  332. if (empty($Res)){
  333. $res['msg'] = '操作成功';
  334. $res['flag'] = true;
  335. $res['company_code'] = $Data['company_code'];
  336. $res['data'] = $Res;
  337. echo json_encode($res);
  338. exit();
  339. }
  340. if ($Res[0]['spot_abnormal'] == 0) {
  341. $Res[0]['spot_status'] = "正常";
  342. } elseif ($Res[0]['spot_abnormal'] == 1) {
  343. $Res[0]['spot_status'] = "异常";
  344. } elseif ($Res[0]['spot_abnormal'] == 2) {
  345. $Res[0]['spot_status'] = "故障";
  346. } elseif ($Res[0]['spot_abnormal'] == 3) {
  347. $Res[0]['spot_status'] = "其他";
  348. }
  349. if (!empty($Res[0]['spot_id'])) {
  350. $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[0]['zb_id']);
  351. $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']);
  352. $Res[0]['plan_name'] = $jh_res[0]['plan_name'];
  353. $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[0]['spot_id']);
  354. $Res[0]['spot_name'] = $points_res[0]['spot_name'];
  355. $Res[0]['spot_address'] = $points_res[0]['spot_address'];
  356. }
  357. if (!empty($Res[0]['wbr_id'])) {
  358. $zrr_res = query_187_ytIoT("select * from ytiot_xj_inspectors where id=" . $Res[0]['wbr_id']);
  359. $Res[0]['name'] = $zrr_res[0]['name'];
  360. $Res[0]['phone'] = $zrr_res[0]['phone'];
  361. }
  362. if (!empty($Res[0]['company_code'])) {
  363. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'");
  364. // print_r($company_data);
  365. // print_r("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'");
  366. // exit();
  367. $Res[0]['owner_name'] = $company_data[0]['owner_name'];
  368. $Res[0]['owner_address'] = $company_data[0]['owner_address'];
  369. }
  370. if (!empty($Res[0]['id'])) {
  371. $photos_res = query_187_ytIoT("select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $Res[0]['id']);
  372. $Res[0]['report_photos'] = $photos_res[0]['report_photos'];
  373. $photos_res = query_187_ytIoT("select wx_name from ytiot_xj_event_processing where dwjl_id=" . $Res[0]['id']);
  374. $Res[0]['wx_name'] = $photos_res[0]['wx_name'];
  375. }
  376. $res['msg'] = '操作成功';
  377. $res['flag'] = true;
  378. $res['company_code'] = $Data['company_code'];
  379. $res['data'] = $Res;
  380. echo json_encode($res);
  381. }
  382. }