MaintenanceController.class.php.bak.2021-12-15 15 KB

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