RepairController.class.php.bak.2021-12-16 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. if (!empty($Data['cl_type'])){
  27. $where=" and cl_type=".$Data['cl_type'];
  28. }else{
  29. $where="";
  30. }
  31. $state_res = query_187_ytIoT("select * from ytiot_xj_event_processing where person_liable in(" . $personnel_id_list . ") and cl_type!=0 ".$where." order by id desc");
  32. foreach ($state_res as $key => $value) {
  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]['audit_status'] = $state_res[$key]['cl_type'];
  42. }
  43. $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");
  44. if (empty($unprocessed_data)) {
  45. $unprocessed_data[0]['wclsl'] = 0;
  46. }
  47. $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");
  48. if (empty($not_reviewed_data)) {
  49. $not_reviewed_data[0]['wshsl'] = 0;
  50. }
  51. $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");
  52. if (empty($failed_data)) {
  53. $failed_data[0]['shwtgsl'] = 0;
  54. }
  55. // $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 . "%'");
  56. $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");
  57. if (empty($completed_data)) {
  58. $completed_data[0]['ywcsl'] = 0;
  59. }
  60. // $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 . "%'");
  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");
  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. $newFilePath1=$Data['img'];
  122. $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']);
  123. if($val){
  124. $res['msg'] = '保存成功';
  125. $res['flag'] = true;
  126. echo json_encode($res);
  127. }else{
  128. $res['msg'] = '保存失败';
  129. $res['flag'] = false;
  130. echo json_encode($res);
  131. }
  132. }
  133. }