InspectionController.class.php.bak.2021-08-09 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 * from ytiot_xj_spot_operation_record where data3=2 and data2=1");
  70. foreach ($Res as $key => $value) {
  71. if ($Res[$key]['spot_abnormal'] == 0) {
  72. $Res[$key]['spot_status'] = "正常";
  73. } elseif ($Res[$key]['spot_abnormal'] == 1) {
  74. $Res[$key]['spot_status'] = "异常";
  75. } elseif ($Res[$key]['spot_abnormal'] == 2) {
  76. $Res[$key]['spot_status'] = "故障";
  77. } elseif ($Res[$key]['spot_abnormal'] == 3) {
  78. $Res[$key]['spot_status'] = "其他";
  79. }
  80. if (!empty($Res[$key]['spot_id'])) {
  81. $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[$key]['spot_id']);
  82. $Res[$key]['spot_name'] = $points_res[0]['spot_name'];
  83. $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[$key]['zb_id']);
  84. $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']);
  85. $Res[$key]['plan_name'] = $jh_res[0]['plan_name'];
  86. }
  87. }
  88. $res['msg'] = '操作成功';
  89. $res['flag'] = true;
  90. $res['company_code'] = $Data['company_code'];
  91. $res['data'] = $Res;
  92. echo json_encode($res);
  93. }
  94. //巡检记录详情数据查询
  95. public function getInspectionRecordDetails()
  96. {
  97. $Data = I();
  98. $record_id = $Data['id'];
  99. $Res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where id=" . $record_id);
  100. if ($Res[0]['spot_abnormal'] == 0) {
  101. $Res[0]['spot_status'] = "正常";
  102. } elseif ($Res[0]['spot_abnormal'] == 1) {
  103. $Res[0]['spot_status'] = "异常";
  104. } elseif ($Res[0]['spot_abnormal'] == 2) {
  105. $Res[0]['spot_status'] = "故障";
  106. } elseif ($Res[0]['spot_abnormal'] == 3) {
  107. $Res[0]['spot_status'] = "其他";
  108. }
  109. if (!empty($Res[0]['spot_id'])) {
  110. $jhz_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $Res[0]['zb_id']);
  111. $jh_res = query_187_ytIoT("select * from ytiot_xj_plan_master where id=" . $jhz_res[0]['zb_id']);
  112. $Res[0]['plan_name'] = $jh_res[0]['plan_name'];
  113. $points_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $Res[0]['spot_id']);
  114. $Res[0]['spot_name'] = $points_res[0]['spot_name'];
  115. $Res[0]['spot_address'] = $points_res[0]['spot_address'];
  116. }
  117. if (!empty($Res[0]['wbr_id'])) {
  118. $zrr_res = query_187_ytIoT("select * from ytiot_xj_inspectors where id=" . $Res[0]['wbr_id']);
  119. $Res[0]['name'] = $zrr_res[0]['name'];
  120. $Res[0]['phone'] = $zrr_res[0]['phone'];
  121. }
  122. if (!empty($Res[0]['company_code'])) {
  123. $company_data = M()->query("select owner_name,owner_address from sp_owner_company where building_id='" . $Res[0]['company_code'] . "'");
  124. $Res[0]['owner_name'] = $company_data[0]['owner_name'];
  125. $Res[0]['owner_address'] = $company_data[0]['owner_address'];
  126. }
  127. if (!empty($Res[0]['id'])) {
  128. $photos_res = query_187_ytIoT("select report_photos from ytiot_xj_operation_record_photos where dwczjl_id=" . $Res[0]['id']);
  129. $Res[0]['report_photos'] = $photos_res[0]['report_photos'];
  130. }
  131. $res['msg'] = '操作成功';
  132. $res['flag'] = true;
  133. $res['company_code'] = $Data['company_code'];
  134. $res['data'] = $Res;
  135. echo json_encode($res);
  136. }
  137. //巡检计划详情数据查询
  138. public function getInspectionDetails()
  139. {
  140. $Data = I("");
  141. $record_id = $Data['id'];
  142. $plan_child_res = query_187_ytIoT("select * from ytiot_xj_plan_child where id=" . $record_id . " and data2='1'");
  143. $plan_master_res = query_187_ytIoT("select plan_name from ytiot_xj_plan_master where id=" . $plan_child_res[0]['zb_id']);
  144. $spot_operation_record_res = query_187_ytIoT("select * from ytiot_xj_spot_operation_record where zb_id=" . $plan_child_res[0]['id']);
  145. $arr[0]['id'] = $plan_child_res[0]['id'];
  146. $arr[0]['completion'] = $plan_child_res[0]['completion'];
  147. $arr[0]['plan_name'] = "任务名称:" . $plan_master_res[0]['plan_name'];
  148. foreach ($spot_operation_record_res as $key1 => $value1) {
  149. $dw_res = query_187_ytIoT("select * from ytiot_xj_inspection_points where id=" . $value1['spot_id']);
  150. if (!empty($dw_res)) {
  151. $arr[0]['point'][$key1]['id'] = $spot_operation_record_res[$key1]['spot_id'];
  152. $arr[0]['point'][$key1]['spot_name'] = "点位名称:" . $dw_res[0]['spot_name'];
  153. $arr[0]['point'][$key1]['data3'] = $spot_operation_record_res[$key1]['data3'];
  154. }
  155. }
  156. $res['msg'] = '操作成功';
  157. $res['flag'] = true;
  158. $res['company_code'] = $Data['company_code'];
  159. $res['data'] = $arr;
  160. echo json_encode($res);
  161. }
  162. //巡检计划巡检功能接口
  163. public function setInspection()
  164. {
  165. $Data = I();
  166. $wc_time = date("Y-m-d H:i:s");
  167. $zb_id = $Data['zb_id'];
  168. $spot_id = $Data['spot_id'];
  169. $spot_abnormal = $Data['spot_abnormal'];
  170. $dwsb_remarks = $Data['dwsb_remarks'];
  171. $data1 = $Data['report_name'];
  172. $phone = $_SESSION['phone'];
  173. $newFilePath1=$Data['img'];
  174. $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);
  175. if (empty($people_id_res)) {
  176. $res['msg'] = '操作失败,系统内部查询出现错误';
  177. $res['flag'] = false;
  178. echo json_encode($res);
  179. exit();
  180. }
  181. $company_code = $people_id_res[0]['company_code'];
  182. $people_id_res1 = query_187_ytIoT("select person_liable_id from ytiot_xj_plan_team where id=" . $people_id_res[0]['team_id']);
  183. if (empty($people_id_res1)) {
  184. $res['msg'] = '操作失败,系统内部查询出现错误';
  185. $res['flag'] = false;
  186. echo json_encode($res);
  187. exit();
  188. }
  189. $people_id = $people_id_res1[0]['person_liable_id'];
  190. $people_id_data = query_187_ytIoT("select people_id from ytiot_xj_team_personnel where team_id=" . $people_id_res[0]['team_id']);
  191. $str = "";
  192. foreach ($people_id_data as $val) {
  193. $str .= "" . $val['people_id'] . ",";
  194. }
  195. if (empty($people_id_data)){
  196. $people_id_list = $people_id;
  197. }else{
  198. $people_id_list = substr($str, 0, strlen($str) - 1) . ',' . $people_id;
  199. }
  200. $people_data = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $phone . "' and id in(" . $people_id_list . ")");
  201. if (empty($people_data)) {
  202. $res['msg'] = '操作失败,该巡检人无巡检权限';
  203. $res['flag'] = false;
  204. echo json_encode($res);
  205. exit();
  206. }
  207. $wbr_id = $people_data[0]['id'];
  208. // $tmpFilePath = $_FILES['img']['tmp_name'];
  209. // if ($_FILES["img"]["error"] == 1) {
  210. // $res['msg'] = '图片上传失败,图片大小超过限制2M';
  211. // $res['flag'] = false;
  212. // echo json_encode($res);
  213. // exit();
  214. // }
  215. // if (empty($tmpFilePath)) {
  216. // $res['msg'] = '图片上传失败';
  217. // $res['flag'] = false;
  218. // echo json_encode($res);
  219. // exit();
  220. // }
  221. // $FileCode = date('YmdHis') . rand(1000, 9999);
  222. // $FileName = $_FILES['img']['name'];
  223. // $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  224. // $BasefName = $FileCode . '.' . $FileType;
  225. // $newFilePath = '/var/www/html/jdxf/Maintinfo/image/' . $BasefName;
  226. // $newFilePath = 'D:/phpStudy/PHPTutorial/WWW/USKYZHAF/img/' . $BasefName;
  227. // $newFilePath1 = 'https://iot.usky.cn/jdxf/Maintinfo/image/' . $BasefName;
  228. // if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  229. // $res['msg'] = '图片上传失败,上传路径错误';
  230. // $res['flag'] = false;
  231. // echo json_encode($res);
  232. // exit();
  233. // }
  234. $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 .
  235. " where zb_id=" . $zb_id . " and spot_id=" . $spot_id);
  236. if (!$res1) {
  237. $res['msg'] = '图片上传成功,数据保存失败';
  238. $res['flag'] = false;
  239. echo json_encode($res);
  240. exit();
  241. }
  242. $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 . "'");
  243. if (!empty($photosres)) {
  244. if ($photosres[0]['spot_abnormal'] == 1 || $photosres[0]['spot_abnormal'] == 2 || $photosres[0]['spot_abnormal'] == 3) {
  245. $company_data = M()->query("select owner_id from sp_owner_company where building_id='" . $company_code . "'");
  246. $wx_name = '设备异常';
  247. $lsxx = $wc_time . "," . $wx_name;
  248. $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 . "')");
  249. }
  250. $photos_res = insert_187_ytIoT("insert into ytiot_xj_operation_record_photos(dwczjl_id,report_photos) value (" . $photosres[0]['id'] . ",'" . $newFilePath1 . "')");
  251. if (!$photos_res) {
  252. $res['msg'] = '操作失败,上传成功,路径保存失败';
  253. $res['flag'] = false;
  254. echo json_encode($res);
  255. exit();
  256. }
  257. $dwzsl = query_187_ytIoT("select count(id) as dwzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id);
  258. $yxjzsl = query_187_ytIoT("select count(id) as yxjzsl from ytiot_xj_spot_operation_record where zb_id=" . $zb_id . " and data3='2'");
  259. if ($dwzsl[0]['dwzsl'] == $yxjzsl[0]['yxjzsl']) {
  260. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=100,data3='" . $wc_time . "' where id=" . $zb_id);
  261. if ($wcqk_res) {
  262. $res['msg'] = '操作成功';
  263. $res['flag'] = true;
  264. echo json_encode($res);
  265. exit();
  266. } else {
  267. $res['msg'] = '操作失败';
  268. $res['flag'] = false;
  269. echo json_encode($res);
  270. exit();
  271. }
  272. } else {
  273. $yg = 1 / $dwzsl[0]['dwzsl'] * 100;
  274. $completion = $people_id_res[0]['completion'] + $yg;
  275. $wcqk_res = insert_187_ytIoT("update ytiot_xj_plan_child set completion=" . $completion . " where id=" . $zb_id);
  276. if ($wcqk_res) {
  277. $res['msg'] = '操作成功';
  278. $res['flag'] = true;
  279. echo json_encode($res);
  280. } else {
  281. $res['msg'] = '操作失败';
  282. $res['flag'] = false;
  283. echo json_encode($res);
  284. }
  285. }
  286. }
  287. }
  288. public function setUpload(){
  289. //图片上传
  290. // print_r($_FILES);
  291. $tmpFilePath = $_FILES['file']['tmp_name'];
  292. if ($_FILES["file"]["error"] == 1) {
  293. $res['msg'] = '图片上传失败,图片大小超过限制2M';
  294. $res['flag'] = false;
  295. echo json_encode($res);
  296. exit();
  297. }
  298. if (empty($tmpFilePath)) {
  299. $res['msg'] = '图片上传失败';
  300. $res['flag'] = false;
  301. echo json_encode($res);
  302. exit();
  303. }
  304. $FileCode = date('YmdHis') . rand(1000, 9999);
  305. $FileName = $_FILES['file']['name'];
  306. $FileType = strtolower(substr(strrchr($FileName, '.'), 1));
  307. $BasefName = $FileCode . '.' . $FileType;
  308. // $newFilePath = 'D:/images/' . $BasefName;//本地路径
  309. // $newFilePath = 'D:/PHP_www/USKYZHAF/img/' . $BasefName;//本地路径
  310. $newFilePath = '/var/www/html/USKYZHAF/img/' . $BasefName;//线上路径
  311. // $newFilePath = 'https://qhome.usky.cn/USKYZHAF/img/' . $BasefName;//线上路径
  312. $newFilePath1 = '/USKYZHAF/img/' . $BasefName;
  313. if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  314. $res['msg'] = '图片上传失败,上传路径错误';
  315. $res['flag'] = false;
  316. echo json_encode($res);
  317. exit();
  318. }
  319. $res['msg'] = '上传成功';
  320. $res['flag'] = true;
  321. $res['img_url'] = $newFilePath1;
  322. echo json_encode($res);
  323. }
  324. }