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