RepairController.class.php.bak.2021-08-10 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class RepairController extends ComController
  5. {
  6. //报修列表查询
  7. public function getRepairList()
  8. {
  9. $Data = I();
  10. $date = date("Y-m-d", time());
  11. $personnel_data = query_187_ytIoT("select * from ytiot_xj_inspectors where phone='" . $_SESSION['phone'] . "' and zn in(4,5,6,7)");
  12. if (empty($personnel_data)) {
  13. $res['msg'] = '操作失败,系统内部查询出现错误';
  14. $res['flag'] = false;
  15. echo json_encode($res);
  16. exit();
  17. }
  18. $personnel_id_list = "";
  19. foreach ($personnel_data as $key => $value) {
  20. if ($key == 0) {
  21. $personnel_id_list .= $personnel_data[$key]['id'];
  22. } else {
  23. $personnel_id_list .= ',' . $personnel_data[$key]['id'];
  24. }
  25. }
  26. $state_res = query_187_ytIoT("select * from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") order by cl_type asc");
  27. $arr = array();
  28. foreach ($state_res as $key => $value) {
  29. // $planned_date=date('Y-m-d', strtotime($state_res[$key]['y_complete_time']));
  30. $audit_date = date('Y-m-d', strtotime($state_res[$key]['sh_time']));
  31. if ($state_res[$key]['cl_type'] == 1 || $state_res[$key]['cl_type'] == 2 || $state_res[$key]['cl_type'] == 3 ||
  32. ($state_res[$key]['cl_type'] == 4 && $audit_date == $date) || ($state_res[$key]['cl_type'] == 5 && $audit_date >= $date)) {
  33. if ($state_res[$key]['sj_type'] == 1) {
  34. $state_res[$key]['event_type_name'] = '故障';
  35. } elseif ($state_res[$key]['sj_type'] == 2) {
  36. $state_res[$key]['event_type_name'] = '隐患';
  37. } elseif ($state_res[$key]['sj_type'] == 3) {
  38. $state_res[$key]['event_type_name'] = '其他';
  39. }
  40. $state_res[$key]['repair_name'] = $state_res[$key]['wx_name'];
  41. $state_res[$key]['id'] = $state_res[$key]['id'];
  42. $state_res[$key]['audit_status'] = $state_res[$key]['cl_type'];
  43. }
  44. }
  45. $unprocessed_data = query_187_ytIoT("select count(*) as wclsl from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type=1");
  46. if (empty($unprocessed_data)) {
  47. $unprocessed_data[0]['wclsl'] = 0;
  48. }
  49. $not_reviewed_data = query_187_ytIoT("select count(*) as wshsl from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type=2");
  50. if (empty($not_reviewed_data)) {
  51. $not_reviewed_data[0]['wshsl'] = 0;
  52. }
  53. $failed_data = query_187_ytIoT("select count(*) as shwtgsl from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type=3");
  54. if (empty($failed_data)) {
  55. $failed_data[0]['shwtgsl'] = 0;
  56. }
  57. $completed_data = query_187_ytIoT("select count(*) as ywcsl from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type=4 and sh_time='%" . $date . "%'");
  58. if (empty($completed_data)) {
  59. $completed_data[0]['ywcsl'] = 0;
  60. }
  61. $overtime_data = query_187_ytIoT("select count(*) as cswcsl from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type=5 and sh_time='%" . $date . "%'");
  62. if (empty($overtime_data)) {
  63. $overtime_data[0]['cswcsl'] = 0;
  64. }
  65. $repair_count = (int)$unprocessed_data[0]['wclsl'] + (int)$not_reviewed_data[0]['wshsl'] + (int)$failed_data[0]['shwtgsl'] + (int)$completed_data[0]['ywcsl'] + (int)$overtime_data[0]['cswcsl'];
  66. $res['msg'] = '操作成功';
  67. $res['flag'] = true;
  68. $res['unprocessed_count'] = (int)$unprocessed_data[0]['wclsl'];
  69. $res['not_reviewed_count'] = (int)$not_reviewed_data[0]['wshsl'];
  70. $res['failed_count'] = (int)$failed_data[0]['shwtgsl'];
  71. $res['completed_count'] = (int)$completed_data[0]['ywcsl'];
  72. $res['overtime_count'] = (int)$overtime_data[0]['cswcsl'];
  73. $res['repair_count'] = (int)$repair_count;
  74. $res['data'] = $state_res;
  75. echo json_encode($res);
  76. }
  77. public function getFormData()
  78. {
  79. $Data = I();
  80. $id = $Data['id'];
  81. $record_data = query_187_ytIoT("select dwjl_id,sj_type,id from ytiot_xj_event_processing where id=" . $id);
  82. if (empty($record_data)) {
  83. $res['msg'] = '操作失败,系统内部查询出现错误';
  84. $res['flag'] = false;
  85. echo json_encode($res);
  86. exit();
  87. }
  88. if ($record_data[0]['sj_type'] == 1) {
  89. $sj_type_name = '故障';
  90. } elseif ($record_data[0]['sj_type'] == 2) {
  91. $sj_type_name = '隐患';
  92. } elseif ($record_data[0]['sj_type'] == 3) {
  93. $sj_type_name = '其他';
  94. }
  95. $point_data = query_187_ytIoT("select spot_id from ytiot_xj_spot_operation_record where id=" . $record_data[0]['dwjl_id']);
  96. if (empty($point_data)) {
  97. $res['msg'] = '操作失败,系统内部查询出现错误';
  98. $res['flag'] = false;
  99. echo json_encode($res);
  100. exit();
  101. }
  102. $address_data = query_187_ytIoT("select spot_address from ytiot_xj_inspection_points where id=" . $point_data[0]['spot_id']);
  103. if (empty($address_data)) {
  104. $res['msg'] = '操作失败,系统内部查询出现错误';
  105. $res['flag'] = false;
  106. echo json_encode($res);
  107. exit();
  108. }
  109. $arr[0]['address']=$address_data[0]['spot_address'];
  110. $arr[0]['id']=$record_data[0]['id'];
  111. $arr[0]['type_name']=$sj_type_name;
  112. $arr[0]['type']=$record_data[0]['sj_type'];
  113. $res['msg'] = '操作成功';
  114. $res['flag'] = true;
  115. $res['data'] = $arr;
  116. echo json_encode($res);
  117. }
  118. public function setRepair(){
  119. $Data=I();
  120. $time=date('Y-m-d h:i:s',time());
  121. $BasefName='';
  122. $tmpFilePath = $_FILES['img']['tmp_name'];
  123. if (empty($tmpFilePath)) {
  124. $res['msg'] = '上传失败,该图片不存在';
  125. $res['flag'] = false;
  126. echo json_encode($res);
  127. exit();
  128. }
  129. $FileCode=date('YmdHis').rand(1000,9999);
  130. $FileName=$_FILES['img']['name'];
  131. $FileType=strtolower(substr(strrchr($FileName,'.'),1));
  132. $BasefName=$FileCode.'.'.$FileType;
  133. // $newFilePath ='/var/www/html/jdxf/Maintinfo/image/'.$BasefName;
  134. $newFilePath ='D:/phpStudy/PHPTutorial/WWW/USKYZHAF/img/'.$BasefName;
  135. $newFilePath1 ='https://iot.usky.cn/jdxf/Maintinfo/image/'.$BasefName;
  136. if (!move_uploaded_file($tmpFilePath, $newFilePath)) {
  137. $res['msg'] = '上传失败';
  138. $res['flag'] = false;
  139. echo json_encode($res);
  140. exit();
  141. }
  142. $val=insert_187_ytIoT("update ytiot_xj_event_processing set data1='1',jg_remarks='".$Data['remarks']."',cl_time='".$time."',picture_path='".$newFilePath1."',cl_type=2 where id=".$Data['id']);
  143. if($val){
  144. $res['msg'] = '保存成功';
  145. $res['flag'] = true;
  146. echo json_encode($res);
  147. }else{
  148. $res['msg'] = '保存失败';
  149. $res['flag'] = false;
  150. echo json_encode($res);
  151. }
  152. }
  153. }