renjiazhuangModel.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class renjiazhuangClassModel extends Model
  3. {
  4. public function baseCarList() {
  5. $sqlStr = 'select * from xinhu_rjz_car_list';
  6. $rows = $this->db->getall($sqlStr);
  7. return $rows;
  8. }
  9. // 车辆管理
  10. public function getCarList()
  11. {
  12. $data = $this->baseCarList();
  13. $arr = [];
  14. foreach ($data as $k => $v) {
  15. $arr[] = array('name' => $v['car_num'].'【'.$v['car_type'].'】', 'value'=>$v['car_num']);
  16. }
  17. return $arr;
  18. }
  19. public function getCarListByType($carType)
  20. {
  21. $sqlStr = 'select id, car_num, car_type, car_state from xinhu_rjz_car_list where car_type = "'.$carType.'"';
  22. $rows = $this->db->getall($sqlStr);
  23. return $rows;
  24. }
  25. public function getCarCon() {
  26. $sqlStr = 'SELECT car_type, count(1) all_con, count(case when car_state = "正常" then 1 end) free_con, ';
  27. $sqlStr .= ' count(case when car_state = "装车" then 1 end) loading_con,';
  28. $sqlStr .= ' count(case when car_state = "卸车" then 1 end) unload_con,';
  29. $sqlStr .= ' count(case when car_state = "维修中" then 1 end) repair_con,';
  30. $sqlStr .= ' count(case when car_state = "停用" then 1 end) stop_con';
  31. $sqlStr .= ' FROM xinhu_rjz_car_list GROUP BY car_type';
  32. $rows = $this->db->getall($sqlStr);
  33. $data = [];
  34. for($i = 0; $i < sizeof($rows); $i++) {
  35. $j=0;
  36. $data[$i]['car_type'] = $rows[$i]["car_type"];
  37. $data[$i]['con'][$j]['title'] = "全部";
  38. $data[$i]['con'][$j]['con'] = $rows[$i]["all_con"];
  39. $data[$i]['con'][$j]['is_show'] = 1;
  40. $data[$i]['con'][$j++]['order'] = 0;
  41. $data[$i]['con'][$j]['title'] = "空闲";
  42. $data[$i]['con'][$j]['con'] = $rows[$i]["free_con"];
  43. $data[$i]['con'][$j]['is_show'] = 1;
  44. $data[$i]['con'][$j++]['order'] = 1;
  45. $data[$i]['con'][$j]['title'] = "装车";
  46. $data[$i]['con'][$j]['con'] = $rows[$i]["loading_con"];
  47. $data[$i]['con'][$j]['is_show'] = 1;
  48. $data[$i]['con'][$j++]['order'] = 2;
  49. $data[$i]['con'][$j]['title'] = "卸车";
  50. $data[$i]['con'][$j]['con'] = $rows[$i]["unload_con"];
  51. $data[$i]['con'][$j]['is_show'] = 1;
  52. $data[$i]['con'][$j++]['order'] = 3;
  53. $data[$i]['con'][$j]['title'] = "维修";
  54. $data[$i]['con'][$j]['con'] = $rows[$i]["repair_con"];
  55. $data[$i]['con'][$j]['is_show'] = 1;
  56. $data[$i]['con'][$j++]['order'] = 4;
  57. $data[$i]['con'][$j]['title'] = "停用";
  58. $data[$i]['con'][$j]['con'] = $rows[$i]["stop_con"];
  59. $data[$i]['con'][$j]['is_show'] = 1;
  60. $data[$i]['con'][$j++]['order'] = 5;
  61. }
  62. return $data;
  63. }
  64. public function getOneCarCon($cartype='') {
  65. if(strlen($cartype) > 0) {
  66. $where = " and car_type = '" . $cartype . "'";
  67. }
  68. // option表选项id
  69. $optionTablePid = 1146;
  70. $table = '[Q]option a left join [Q]rjz_car_list b on a.`name` = b.car_type';
  71. $where = "pid = $optionTablePid $where";
  72. $fields = "a.`name` as car_type, count(b.id) car_con, count(case when car_state = '正常' then 1 end) car_free_con";
  73. $rows = $this->db->getone($table, $where, $fields);
  74. return $rows;
  75. }
  76. public function updateCarState($carname, $carstate) {
  77. if ($carname) {
  78. $res = $this->db->update('[Q]rjz_car_list','`car_state`="'.$carstate.'"','`car_num` = "'.$carname.'"');
  79. return returnsuccess($res);
  80. }
  81. return returnerror('车牌号为空');
  82. }
  83. }