renjiazhuangModel.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 in (".$carType.") and car_state = '正常'";
  22. // return $sqlStr;
  23. $rows = $this->db->getall($sqlStr);
  24. return $rows;
  25. }
  26. public function getCarCon() {
  27. $sqlStr = 'SELECT car_type, count(1) all_con, count(case when car_state = "正常" then 1 end) free_con, ';
  28. $sqlStr .= ' count(case when car_state = "装车" then 1 end) loading_con,';
  29. $sqlStr .= ' count(case when car_state = "卸车" then 1 end) unload_con,';
  30. $sqlStr .= ' count(case when car_state = "维修中" then 1 end) repair_con,';
  31. $sqlStr .= ' count(case when car_state = "停用" then 1 end) stop_con';
  32. $sqlStr .= ' FROM xinhu_rjz_car_list GROUP BY car_type';
  33. $rows = $this->db->getall($sqlStr);
  34. $data = [];
  35. for($i = 0; $i < sizeof($rows); $i++) {
  36. $j=0;
  37. $data[$i]['car_type'] = $rows[$i]["car_type"];
  38. $data[$i]['con'][$j]['title'] = "全部";
  39. $data[$i]['con'][$j]['con'] = $rows[$i]["all_con"];
  40. $data[$i]['con'][$j]['is_show'] = 1;
  41. $data[$i]['con'][$j++]['order'] = 0;
  42. $data[$i]['con'][$j]['title'] = "空闲";
  43. $data[$i]['con'][$j]['con'] = $rows[$i]["free_con"];
  44. $data[$i]['con'][$j]['is_show'] = 1;
  45. $data[$i]['con'][$j++]['order'] = 1;
  46. $data[$i]['con'][$j]['title'] = "装车";
  47. $data[$i]['con'][$j]['con'] = $rows[$i]["loading_con"];
  48. $data[$i]['con'][$j]['is_show'] = 1;
  49. $data[$i]['con'][$j++]['order'] = 2;
  50. $data[$i]['con'][$j]['title'] = "卸车";
  51. $data[$i]['con'][$j]['con'] = $rows[$i]["unload_con"];
  52. $data[$i]['con'][$j]['is_show'] = 1;
  53. $data[$i]['con'][$j++]['order'] = 3;
  54. $data[$i]['con'][$j]['title'] = "维修";
  55. $data[$i]['con'][$j]['con'] = $rows[$i]["repair_con"];
  56. $data[$i]['con'][$j]['is_show'] = 1;
  57. $data[$i]['con'][$j++]['order'] = 4;
  58. $data[$i]['con'][$j]['title'] = "停用";
  59. $data[$i]['con'][$j]['con'] = $rows[$i]["stop_con"];
  60. $data[$i]['con'][$j]['is_show'] = 1;
  61. $data[$i]['con'][$j++]['order'] = 5;
  62. }
  63. return $data;
  64. }
  65. public function getOneCarCon($cartype='') {
  66. if(strlen($cartype) > 0) {
  67. $where = " and car_type in (" . $cartype . ")";
  68. }
  69. // option表选项id
  70. $optionTablePid = 1146;
  71. $table = '[Q]option a left join [Q]rjz_car_list b on a.`name` = b.car_type';
  72. $where = "pid = $optionTablePid $where";
  73. $fields = "a.`name` as car_type, count(b.id) car_con, count(case when car_state = '正常' then 1 end) car_free_con";
  74. $rows = $this->db->getone($table, $where, $fields);
  75. return $rows;
  76. }
  77. public function getCarIdleCon($cartypes='') {
  78. if(strlen($cartypes) > 0) {
  79. $where = " and car_type in (" . $cartypes . ")";
  80. }
  81. $sqlStr = 'select a.name as car_type, count(b.id) car_con, count(case when car_state = "正常" then 1 end) car_free_con';
  82. $sqlStr .= ' from xinhu_option a left join xinhu_rjz_car_list b on a.name = b.car_type';
  83. $sqlStr .= ' where pid = 1146 '.$where;
  84. $sqlStr .= ' group by a.name';
  85. $rows = $this->db->getall($sqlStr);
  86. return $rows;
  87. }
  88. public function getCarIdleConByApplyStartTime($car_types='', $apply_start_time = '') {
  89. if(strlen($car_types) > 0) {
  90. $where = " and car_type in (" . $car_types . ")";
  91. }
  92. # 申请使用时间大于前车空闲时间
  93. if (strlen($apply_start_time) > 0) {
  94. $free_where = " or (end_time <= '".$apply_start_time."' or end_time is null)";
  95. }
  96. $sqlStr = 'select a.name as car_type, count(b.id) car_con,';
  97. $sqlStr .= ' count(case when car_state = "正常" '.$free_where.' then 1 end) car_free_con';
  98. $sqlStr .= ' from xinhu_option a left join xinhu_rjz_car_list b on a.name = b.car_type';
  99. $sqlStr .= ' where pid = 1146 '.$where;
  100. $sqlStr .= ' group by a.name';
  101. $rows = $this->db->getall($sqlStr);
  102. return $rows;
  103. }
  104. public function updateCarState($carname, $carstate) {
  105. if ($carname) {
  106. $res = $this->db->update('[Q]rjz_car_list','`car_state`="'.$carstate.'"','`car_num` in ('.$carname.')');
  107. return returnsuccess($res);
  108. }
  109. return returnerror('车牌号为空');
  110. }
  111. }