You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1959 lines
102 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/10/28
  6. * Time: 9:17
  7. * 组合线路车次调度
  8. */
  9. require 'dispatchAlgorithm.class.php';
  10. class groupDispatch extends base
  11. {
  12. /**
  13. * 获取产品线信息
  14. * @return mixed
  15. * User: Steven
  16. */
  17. public function getBaseInfo()
  18. {
  19. $res = $this->productLine();
  20. if ($res) {
  21. $json['code'] = '0';
  22. $json['info'] = '产品线获取成功';
  23. $json['base_info'] = $res;
  24. return $json;
  25. }
  26. }
  27. /**
  28. * 获取某天某特定组合线路的订单信息
  29. * 温依莅
  30. * 2016.11.03
  31. * @param $param
  32. * start_date(date) 出发日期
  33. * line_id(int) 组合订单id
  34. * @return
  35. * 成功返回参数
  36. * code(str)
  37. * info(str)
  38. * list_order(array):
  39. * order_id(int) 订单id
  40. * run_bus_id(int) 车次id,如果无,返回''
  41. * line_codes(str) 订单所对应组合线路编码
  42. * day(int) 标示今天是该订单第几天的行程
  43. * start_station(str) 订单所对应组合线路出发站点
  44. * tran_id(int) 接驳线路id
  45. * num(int) 符合条件该线路订单人数
  46. * list_bus(array): 车次及相应剩余座位数
  47. * --run_bus_id(int) 车次id
  48. * --stock(int) 余票数
  49. */
  50. public function getOrderDetail($param)
  51. {
  52. /*
  53. start_date:出发日期
  54. line_id:组合订单id
  55. */
  56. $start_date = isset($param['start_date']) ? $param['start_date'] : false;
  57. $line_id = isset($param['line_id']) ? $param['line_id'] : false;
  58. $product_id = isset($param['product_id']) ? $param['product_id'] : false;
  59. //判断参数是否缺少
  60. if (false === $start_date || false === $line_id || !trim($start_date) || !trim($line_id)) {
  61. $json['code'] = '2';
  62. $json['info'] = '缺少必要参数';
  63. return $json;
  64. }
  65. //判断日期格式正确
  66. $tmp_arr = explode('-', $start_date);
  67. $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期
  68. if (!$bool) {
  69. $json['code'] = '1';
  70. $json['info'] = '日期格式不正确';
  71. return $json;
  72. }
  73. //根据日期和组合线路id得到该日组合订单 分拆后的 订单信息
  74. if($line_id== -1){
  75. $where='';
  76. }else{
  77. $where=" a.PARENT_PROD_ID=$line_id AND ";
  78. }
  79. $sql = "
  80. SELECT *,convert(x.trans_name using gbk) 't1',convert(x.start_station using gbk) 't2'
  81. from(
  82. SELECT
  83. a.order_id,
  84. a.customer_mobile as tel,
  85. (DATEDIFF('$start_date',a.prod_start_station_date)+1) as day,
  86. IFNULL((SELECT h.line_id FROM order_main g LEFT JOIN opera_line h ON g.parent_prod_id=h.line_id WHERE h.LINE_TYPE=256 AND g.PARENT_ORDER_ID=a.order_id limit 1),'') AS tran_id,
  87. IFNULL((select res_name from base_resource where res_id=(select parent_id from base_resource where res_id=(SELECT p.prod_start_station_res_id FROM order_main p LEFT JOIN opera_line q ON p.parent_prod_id=q.line_id WHERE q.LINE_TYPE=256 AND p.PARENT_ORDER_ID=a.order_id limit 1))),'') as trans_name,
  88. IFNULL((SELECT o.run_bus_order_id FROM order_main o LEFT JOIN opera_line v ON o.parent_prod_id=v.line_id WHERE v.LINE_TYPE=255 AND o.PARENT_ORDER_ID=a.order_id AND o.PROD_START_STATION_DATE='$start_date' limit 1),'') AS run_bus_id,
  89. a.prod_start_station_res_name AS start_station,
  90. b.line_code AS line_codes,
  91. IFNULL(SUBSTRING_INDEX(a.order_description,'|',-1),0) AS num
  92. FROM
  93. order_main a LEFT JOIN opera_line b
  94. ON
  95. a.parent_prod_id = b.line_id
  96. WHERE
  97. $where '$start_date' IN ( SELECT prod_start_station_date FROM order_main WHERE parent_order_id=a.order_id)
  98. AND a.order_valid_status=1 AND a.order_status<>148
  99. AND b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1
  100. ) x
  101. ORDER BY t1,t2;";
  102. $order_info = $this->query($sql);
  103. if (false === $order_info) {
  104. $json['code'] = '1';
  105. $json['info'] = '数据库错误';
  106. return $json;
  107. }
  108. //若查询无信息
  109. if (count($order_info) == 0) {
  110. $json['code'] = '1';
  111. $json['info'] = '无符合条件的线路订单信息';
  112. $json['list'] = array();
  113. return $json;
  114. }
  115. //处理得到今日车次信息
  116. $sql2 = "SELECT
  117. a.order_id,a.parent_order_id,a.run_id,b.BUS_ORDER_ID as run_bus_id,(b.seat_count - b.saled_count) AS stock
  118. FROM
  119. order_main a,run_bus b,
  120. opera_line c,run_main d
  121. WHERE
  122. a.run_id = b.run_id
  123. AND a.PARENT_PROD_ID = c.line_id
  124. AND b.run_id = d.run_id
  125. AND d.prod_id = 0
  126. AND d.run_date = '$start_date'
  127. AND c.line_type = 255
  128. AND b.cancel_flag = 0
  129. group by b.bus_order_id
  130. having $product_id=(SELECT l.product_type FROM opera_line l LEFT JOIN order_main m ON l.line_id = m.PARENT_PROD_ID WHERE m.order_id = a.PARENT_ORDER_ID limit 1);";
  131. $bus_info = $this->query($sql2);
  132. if (false === $bus_info) {
  133. $json['code'] = '1';
  134. $json['info'] = '数据库出错';
  135. $json['list'] = array();
  136. return $json;
  137. }
  138. //若查询无车次信息
  139. if (count($bus_info) == 0) {
  140. //这里如果尚未派车,无车次信息,则返回一个空的bus_info数组
  141. /*$json['code'] = '1';
  142. $json['info'] = '无符合条件的车次信息';
  143. $json['list'] = array();
  144. return $json;*/
  145. $bus_info = array();
  146. }
  147. //处理run_bus_id返回值
  148. foreach ($order_info as $k => $v) {
  149. if ($v['run_bus_id'] == 0) {
  150. $order_info[$k]['run_bus_id'] = '';
  151. }
  152. }
  153. $json['code'] = '0';
  154. $json['info'] = '返回线路订单信息成功';
  155. $json['list_order'] = $order_info;
  156. $json['list_bus'] = $bus_info;
  157. return $json;
  158. }
  159. /**
  160. * 获取某一天的组合线路的所有线路的订单统计信息
  161. * 温依莅
  162. * 2016.11.01
  163. * @param $param
  164. * start_date(date) 出发日期
  165. * product_type(int) 产品线 --若为'-1'则表示所有
  166. * @return
  167. * 成功返回参数
  168. * code(str)
  169. * info(str)
  170. * total_num(int) 符合条件订单总人数
  171. * list(array):
  172. * line_id(int) 订单id
  173. * line_name(str) 订单名字
  174. * line_code(str) 订单编码
  175. * num(int) 符合条件该线路订单总人数
  176. */
  177. public function getOrderList($param)
  178. {
  179. /*
  180. start_date:出发日期
  181. product_type:产品线 --若为'-1'则表示所有
  182. */
  183. $start_date = isset($param['start_date']) ? $param['start_date'] : false;
  184. $product_type = isset($param['product_type']) ? $param['product_type'] : false;
  185. //判断参数是否缺少
  186. if (false === $start_date || false === $product_type || !trim($start_date) || !trim($product_type)) {
  187. $json['code'] = '2';
  188. $json['info'] = '缺少必要参数';
  189. return $json;
  190. }
  191. //判断日期格式正确
  192. $tmp_arr = explode('-', $start_date);
  193. $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期
  194. if (!$bool) {
  195. $json['code'] = '1';
  196. $json['info'] = '日期格式不正确';
  197. return $json;
  198. }
  199. //从数据库取得该天组合线路统计信息
  200. //如果是所有产品线
  201. $sql = "SELECT
  202. b.line_id,b.line_code,IFNULL(sum(SUBSTRING_INDEX(a.order_description,'|',-1)),0) AS num
  203. FROM
  204. order_main a
  205. RIGHT JOIN
  206. opera_line b
  207. ON
  208. a.parent_prod_id = b.line_id AND a.cancel_flag=0 AND a.order_valid_status=1 AND a.order_status<>148 AND a.parent_order_id=0 AND '$start_date' IN ( select c.prod_start_station_date from order_main c where c.parent_order_id=a.order_id)
  209. WHERE
  210. b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1 AND ";
  211. if ($product_type == '-1') {
  212. $sql .= "b.product_type IN (select id from dict_type where parent_id=323) GROUP BY b.line_id;";
  213. } else {
  214. $sql .= "b.product_type=$product_type GROUP BY b.line_id;";
  215. }
  216. $order_info = $this->query($sql);
  217. if (false === $order_info) {
  218. $json['code'] = '1';
  219. $json['info'] = '数据库错误';
  220. return $json;
  221. }
  222. //若查询无信息
  223. if (count($order_info) == 0) {
  224. $json['code'] = '1';
  225. $json['info'] = '无符合条件的线路信息';
  226. $json['list'] = array();
  227. return $json;
  228. }
  229. //处理得到符合条件总计数
  230. $total_num = 0;
  231. foreach ($order_info as $k => $v) {
  232. $total_num += $v['num'];
  233. }
  234. $json['code'] = '0';
  235. $json['info'] = '返回票种信息成功';
  236. $json['total_num'] = $total_num;
  237. $json['list'] = $order_info;
  238. return $json;
  239. }
  240. /**
  241. * 获取组合线路接驳段的分车信息
  242. * @param run_date 出发日期
  243. * @param product_id 产品线ID
  244. * @param current_page 当前页
  245. * @param page_size 每页显示条数
  246. * @return mixed
  247. * User: Steven
  248. */
  249. public function getSingleResult($param)
  250. {
  251. $valid = zzcsUtils::validateParams(array('run_date,product_id,current_page,page_size' => 'empty'), $param); //参数验证
  252. if (!$valid['status']) {
  253. $result['code'] = (string)$valid['status'];
  254. $result['info'] = $valid['info'];
  255. return $result;
  256. }
  257. $start_row = ($param['current_page'] - 1) * $param['page_size'];
  258. //SQL:查询组合线路中接驳段的分车结果
  259. $sql = "select b.id,
  260. (select RES_NAME from base_resource where res_id=b.start_zone_id limit 1) as line_code,
  261. b.run_id, -- 班次ID
  262. m.run_date, -- 出发日期
  263. b.bus_order_id as run_bus_order_id, -- 车号
  264. (SELECT BASE_RESOURCE.RES_NAME FROM BASE_RESOURCE WHERE BASE_RESOURCE.CANCEL_FLAG = 0 AND BASE_RESOURCE.RES_ID = IF(b.SEND_BUS_TYPE_RES_ID = 0,b.BUS_TYPE_RES_ID,b.SEND_BUS_TYPE_RES_ID)) AS res_name, -- 指派车型名称
  265. b.SEAT_COUNT AS seat_count,
  266. b.SALED_COUNT AS order_cnt, -- 已售座位数
  267. (b.SEAT_COUNT-b.SALED_COUNT) AS remain_cnt,
  268. b.SEND_BUS_RES_ID AS send_bus_res_id, -- 实派车辆资源ID
  269. b.SEND_BUS_NO AS send_bus_res_name, -- 实派车辆车牌号
  270. b.SEND_BUS_DRIVER_RES_ID AS send_bus_driver_res_id, -- 司机资源ID
  271. b.SEND_DRIVER_NAME AS send_driver_name, -- 司机姓名
  272. b.SEND_TOUR_GUIDE_RES_ID AS send_tour_guide_res_id, -- 导游
  273. b.SEND_TOUR_GUIDE_NAME As send_tour_guide_name -- 导游
  274. from run_bus b left join
  275. run_main m on b.run_id = m.run_id
  276. where m.run_date = '{$param['run_date']}' and b.group_line_flag = 1 and b.cancel_flag = 0 and m.prod_id > 0
  277. and b.run_id in (
  278. select distinct run_id from order_main where parent_order_id > 0 and prod_id in (select ticket_id from opera_tickets t, opera_line l where t.line_id = l.line_id and l.line_type = 316 and l.product_type = {$param['product_id']})
  279. ) order by b.bus_order_id";
  280. /*$sql = "select distinct s.id as id,
  281. -- CONCAT(l.LINE_CODE,' ',l.LINE_NAME) as line_code,
  282. (select RES_NAME from base_resource where res_id=s.start_zone_id limit 1) as line_code,
  283. b.run_id, -- 班次ID
  284. b.run_date, -- 出发日期
  285. b.run_bus_order_id, -- 车号
  286. (SELECT BASE_RESOURCE.RES_NAME FROM BASE_RESOURCE WHERE BASE_RESOURCE.CANCEL_FLAG = 0 AND BASE_RESOURCE.RES_ID = IF(s.SEND_BUS_TYPE_RES_ID = 0,s.BUS_TYPE_RES_ID,s.SEND_BUS_TYPE_RES_ID)) AS res_name, -- 指派车型名称
  287. s.SEAT_COUNT AS seat_count,
  288. s.SALED_COUNT AS order_cnt, -- 已售座位数
  289. (s.SEAT_COUNT-s.SALED_COUNT) AS remain_cnt,
  290. s.SEND_BUS_RES_ID AS send_bus_res_id, -- 实派车辆资源ID
  291. s.SEND_BUS_NO AS send_bus_res_name, -- 实派车辆车牌号
  292. s.SEND_BUS_DRIVER_RES_ID AS send_bus_driver_res_id, -- 司机资源ID
  293. s.SEND_DRIVER_NAME AS send_driver_name, -- 司机姓名
  294. s.SEND_TOUR_GUIDE_RES_ID AS send_tour_guide_res_id, -- 导游
  295. s.SEND_TOUR_GUIDE_NAME As send_tour_guide_name -- 导游
  296. from opera_tickets a, run_bus s,order_main b, opera_line l
  297. where a.ticket_id = b.prod_id
  298. and s.run_id = b.RUN_ID
  299. and s.bus_order_id = b.run_bus_order_id
  300. and b.parent_prod_id = l.LINE_ID
  301. and l.line_type = 256
  302. and l.cancel_flag =0
  303. and a.line_id in (select line_id from opera_line where line_type = 316 and product_type = {$param['product_id']} and cancel_flag = 0) -- 组合线路
  304. and b.run_date = '{$param['run_date']}' order by b.run_bus_order_id,s.SEAT_COUNT";*/
  305. $sql_query = $sql . " limit $start_row,{$param['page_size']}";
  306. $sql_count = "SELECT COUNT(*) as count from (" . $sql . ") as a";
  307. zzcsUtils::writeLog($sql_query);
  308. $res_query = $this->query($sql_query);
  309. $res_count = $this->query($sql_count);
  310. if (false === $sql_query) {
  311. $result['code'] = '1';
  312. $result['info'] = '获取接驳段自动分车结果失败';
  313. return $result;
  314. }
  315. $total_page = ceil($res_count[0]['count'] / $param['page_size']);
  316. $result['code'] = '0';
  317. $result['info'] = '获取接驳段自动分车结果成功';
  318. $result['data'] = $res_query;
  319. $result['page'] = array(
  320. 'page_size' => $param['page_size'],
  321. 'current_page' => $param['current_page'],
  322. 'total_count' => $res_count[0]['count'],
  323. 'total_page' => $total_page
  324. );
  325. return $result;
  326. }
  327. /**
  328. * 获取组合线路直通段分车的结果
  329. * @param run_date 出发日期
  330. * @param product_id 产品线ID
  331. * @param current_page 当前页
  332. * @param page_size 每页显示条数
  333. * @return mixed
  334. * User: Steven
  335. */
  336. public function getDispatchResult($param)
  337. {
  338. $valid = zzcsUtils::validateParams(array('run_date,product_id,current_page,page_size' => 'empty'), $param); //参数验证
  339. if (!$valid['status']) {
  340. $result['code'] = (string)$valid['status'];
  341. $result['info'] = $valid['info'];
  342. return $result;
  343. }
  344. $start_row = ($param['current_page'] - 1) * $param['page_size'];
  345. //SQL:查询组合线路直通段的分车后的结果
  346. $sql = "select r.run_id, r.bus_order_id as run_bus_order_id, r.seat_count, ifnull(sum(order_cnt),0) as order_cnt,(seat_count-saled_count) as remain_cnt,
  347. ifnull(group_concat(DISTINCT line_code),'') as line_code,r.id,r.SEND_BUS_NO as send_bus_res_name, r.send_driver_name, r.send_tour_guide_name
  348. from (select s.id,s.run_id,s.bus_order_id,s.seat_count,s.SEND_BUS_NO,s.send_driver_name,s.send_tour_guide_name,s.saled_count
  349. from run_main m,run_bus s
  350. where m.run_id = s.run_id and m.run_date = '{$param['run_date']}' and m.prod_id = 0 AND s.cancel_flag=0) r
  351. left join
  352. (select distinct a.parent_order_id, b.parent_prod_id,b.line_code, b.order_cnt, a.run_id,a.run_bus_order_id
  353. from order_main a,
  354. (select order_id,parent_prod_id,l.line_code,l.line_name, substring_index(order_description,'|',-1) as order_cnt
  355. from order_main m,opera_line l
  356. where m.parent_prod_id = l.line_id and m.parent_order_id = 0 and m.cancel_flag = 0 and m.order_valid_status = 1 and l.line_type = 316 and l.PRODUCT_TYPE={$param['product_id']} and l.cancel_flag = 0 ) b
  357. where a.parent_order_id = b.order_id
  358. and a.run_date = '{$param['run_date']}'
  359. and a.cancel_flag = 0
  360. and a.order_valid_status = 1
  361. and a.parent_prod_id not in (select line_id from opera_line where line_type = 256 and cancel_flag = 0)
  362. ) t on r.run_id = t.run_id and r.bus_order_id = t.run_bus_order_id
  363. group by r.run_id, r.bus_order_id, r.seat_count";
  364. //SQL:查询组合线路直通段的分车结果包括分页
  365. $sql_query = $sql . " LIMIT $start_row,{$param['page_size']}";
  366. $sql_count = "SELECT COUNT(*) as count from (" . $sql . ") as a";
  367. zzcsUtils::writeLog($sql_query);
  368. $res_query = $this->query($sql_query);
  369. $res_count = $this->query($sql_count);
  370. if (false === $sql_query) {
  371. $result['code'] = '1';
  372. $result['info'] = '获取直通段自动分车结果失败';
  373. return $result;
  374. }
  375. $total_page = ceil($res_count[0]['count'] / $param['page_size']);
  376. $result['code'] = '0';
  377. $result['info'] = '获取直通段自动分车结果成功';
  378. $result['data'] = $res_query;
  379. $result['page'] = array(
  380. 'page_size' => $param['page_size'],
  381. 'current_page' => $param['current_page'],
  382. 'total_count' => $res_count[0]['count'],
  383. 'total_page' => $total_page
  384. );
  385. return $result;
  386. }
  387. /**
  388. * 组合线路车辆调度算法
  389. * @param run_date 出发日期
  390. * @param product_id 产品线ID
  391. * @return mixed
  392. * User: Steven
  393. */
  394. public function dispatch($param)
  395. {
  396. $user_id = $this->user_id;
  397. $valid = zzcsUtils::validateParams(array('run_date,product_id' => 'empty'), $param); //参数验证
  398. if (!$valid['status']) {
  399. $result['code'] = (string)$valid['status'];
  400. $result['info'] = $valid['info'];
  401. return $result;
  402. }
  403. //接驳段的分车算法 并返回被占用的车辆信息
  404. $sql_jiebo = "CALL sp_bus_dispatch_for_group_line($user_id,'{$param['run_date']}',{$param['product_id']})";
  405. zzcsUtils::writeLog($sql_jiebo);
  406. $res_jiebo = $this->procQuery($sql_jiebo);
  407. if ($res_jiebo['code'] != 0) { //存储过程执行出错
  408. $json["code"] = (string)$res_jiebo['code'];
  409. $json["info"] = $res_jiebo['info'];
  410. return $json;
  411. }
  412. $car_list1 = $res_jiebo['data'][0]; //得到接驳段的车辆信息列表
  413. //TODO:进行组合线路直通段的分车
  414. //sql:获取需要加入分车算法的订单信息
  415. $sql_zhitong = "CALL SP_GET_LINE_GROUP_DISTRIB_RULE('{$param['run_date']}',{$param['product_id']})";
  416. zzcsUtils::writeLog($sql_zhitong);
  417. $res = $this->procQuery($sql_zhitong);
  418. if ($res['code'] != 0) {
  419. $json['code'] = '1';
  420. $json['info'] = '订单数据获取失败';
  421. return $json;
  422. }
  423. #region TODO: 以下是组合线路分车算法
  424. $Ta = array();
  425. $Tb = array();
  426. $Tc = array();
  427. $Te = array();
  428. $Za = array();
  429. $Zb = array();
  430. $Zc = array();
  431. $Ze = array();
  432. $Taeab = array();
  433. $Tbcbe = array();
  434. if ($res['data'][0]) {
  435. foreach ($res['data'][0] as $k => $v) {
  436. $order = array(
  437. 'order_number' => $v['parent_order_id'], // 组合订单ID
  438. 'sub_order_id' => $v['sub_order_id'], //单一线路ID
  439. 'passenger_number' => $v['order_cnt'], //订单中的人数
  440. 'superior_hotel' => $v['start_res_id'], //上车站点ID(酒店ID)
  441. 'superior_product' => $v['sub_line_id'], //组合线路ID A+B+E(两天) 第一天A+B该字段显示的是A+B线路的ID
  442. 'group_line_id' => $v['group_line_id'], //组合线路ID
  443. 'start_time' => $v['start_time'] //发车时间
  444. );
  445. switch ($v['sub_line_id']) {
  446. case ZA: //纯玩产品a $Ta对应ZA
  447. $Ta['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  448. break;
  449. case ZB:
  450. $Tb['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  451. break;
  452. case ZC:
  453. $Tc['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  454. break;
  455. case ZE:
  456. $Te['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  457. break;
  458. case TA:
  459. $Za['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  460. break;
  461. case TB:
  462. $Zb['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  463. break;
  464. case TC:
  465. $Zc['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  466. break;
  467. case TE:
  468. $Ze['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  469. break;
  470. //纯玩产品aeab 包含A+B|A+E|A+E+B(两日)
  471. case ZAB :
  472. case ZAE:
  473. case ZAEB:
  474. $Taeab['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  475. break;
  476. case ZBC:
  477. case ZBE:
  478. $Tbcbe['hotel_list'][$v['start_res_id']]['order_list'][] = $order;
  479. break;
  480. }
  481. }
  482. }
  483. $dispatch = new dispatchAlgorithm();
  484. #region 车次库存列表
  485. $bus_stock = array();
  486. $bus_detail = array();
  487. //sql:查询所有可用的车次列表
  488. $run_date = $param['run_date'];
  489. $sql_enable_car = $this->getEnableCar($run_date); //获取当前可用的车次
  490. $car_list2 = $this->query($sql_enable_car);
  491. if ($car_list2) {
  492. #region 将接驳段的车运用到直通段的派车中
  493. $car_list = array_merge($car_list1, $car_list2);
  494. usort($car_list, function ($a, $b) {
  495. $car_list = ($b['seat_count'] - $a['seat_count']);
  496. return $car_list != 0 ? $car_list : ($a['sort_id'] - $b['sort_id']);
  497. });
  498. #endregion
  499. foreach ($car_list as $k1 => $v1) {
  500. $bus_stock[$k1] = $v1['seat_count'];
  501. $bus_detail[$k1] = array(
  502. 0 => $v1['seat_count'],
  503. 1 => $v1['bus_id'],
  504. 2 => $v1['brand_id'],
  505. 3 => $v1['bus_type_res_id']
  506. );
  507. }
  508. }
  509. #endregion
  510. $temp_order_pool = array();
  511. $white_bus_pool = array();
  512. $Te_black_order_pool = array();// 创建产品Te的黑订单池订单池
  513. $Tb_black_order_pool = array();// 创建产品Tb的黑订单池订单池
  514. $Tc_black_order_pool = array();// 创建产品Tc的黑订单池订单池
  515. $Ta_black_order_pool = array();// 创建产品Ta的黑订单池订单池
  516. $Ze_black_order_pool = array();// 创建产品Ze的黑订单池订单池->购物
  517. $Zb_black_order_pool = array();// 创建产品Zb的黑订单池订单池->购物
  518. $Zc_black_order_pool = array();// 创建产品Zc的黑订单池订单池->购物
  519. $Za_black_order_pool = array();// 创建产品Za的黑订单池订单池->购物
  520. $Taeab_two_scenic_black_order_pool = array();//a+e和a+b单日双景点黑池子
  521. $Tbcbe_two_scenic_black_order_pool = array();//b+c和b+e单日双景点黑池子
  522. /**
  523. * 以下是分别派车
  524. */
  525. if (!empty($Ze)) {
  526. // 存在Ze产品订单
  527. ZM:
  528. for (; ;) {
  529. if (!empty($Ze['hotel_list'])) {
  530. sort($Ze['hotel_list']);
  531. $tt_people = 0;
  532. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  533. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  534. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  535. }
  536. }
  537. if ($tt_people < $bus_stock["0"]) {
  538. for ($i = 0; $i < count($Ze['hotel_list']["0"]["order_list"]); $i++) {
  539. $temp_order_pool[] = $Ze['hotel_list']["0"]["order_list"][$i];
  540. }
  541. array_splice($Ze['hotel_list'], 0, 1);
  542. if (!empty($Ze['hotel_list'])) {
  543. goto ZM;
  544. }
  545. }
  546. }
  547. $orders = $dispatch->change_data_type($temp_order_pool);
  548. if (empty($bus_stock)) {
  549. $result['code'] = '1';
  550. $result['info'] = '车辆库存不足,无法自动派车!';
  551. return $result;
  552. }
  553. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  554. if ($answer["achieved_attendance"] < 0.9) {
  555. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Ze_black_order_pool);
  556. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  557. $Ze_black_order_pool = $temp_pool_answe["black_order_pool"];
  558. } else {
  559. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  560. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  561. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  562. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  563. }
  564. if (empty($temp_order_pool) && empty($Ze['hotel_list'])) {
  565. break;
  566. }
  567. }
  568. }
  569. if (!empty($Zb)) {
  570. // 存在Zb产品订单
  571. ZQ:
  572. for (; ;) {
  573. if (!empty($Zb['hotel_list'])) {
  574. sort($Zb['hotel_list']);
  575. $tt_people = 0;
  576. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  577. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  578. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  579. }
  580. }
  581. if ($tt_people < $bus_stock["0"]) {
  582. for ($i = 0; $i < count($Zb['hotel_list']["0"]["order_list"]); $i++) {
  583. $temp_order_pool[] = $Zb['hotel_list']["0"]["order_list"][$i];
  584. }
  585. array_splice($Zb['hotel_list'], 0, 1);
  586. if (!empty($Zb['hotel_list'])) {
  587. goto ZQ;
  588. }
  589. }
  590. }
  591. $orders = $dispatch->change_data_type($temp_order_pool);
  592. if (empty($bus_stock)) {
  593. $result['code'] = '1';
  594. $result['info'] = '车辆库存不足,无法自动派车!';
  595. return $result;
  596. }
  597. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  598. if ($answer["achieved_attendance"] < 0.9) {
  599. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Zb_black_order_pool);
  600. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  601. $Zb_black_order_pool = $temp_pool_answe["black_order_pool"];
  602. } else {
  603. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  604. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  605. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  606. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  607. }
  608. if (empty($temp_order_pool) && empty($Zb['hotel_list'])) {
  609. break;
  610. }
  611. }
  612. }
  613. if (!empty($Zc)) {
  614. // 存在Zc产品订单
  615. ZC:
  616. for (; ;) {
  617. if (!empty($Zc['hotel_list'])) {
  618. sort($Zc['hotel_list']);
  619. $tt_people = 0;
  620. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  621. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  622. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  623. }
  624. }
  625. if ($tt_people < $bus_stock["0"]) {
  626. for ($i = 0; $i < count($Zc['hotel_list']["0"]["order_list"]); $i++) {
  627. $temp_order_pool[] = $Zc['hotel_list']["0"]["order_list"][$i];
  628. }
  629. array_splice($Zc['hotel_list'], 0, 1);
  630. if (!empty($Zc['hotel_list'])) {
  631. goto ZC;
  632. }
  633. }
  634. }
  635. // 订单池加到满足要求
  636. $orders = $dispatch->change_data_type($temp_order_pool);
  637. if (empty($bus_stock)) {
  638. $result['code'] = '1';
  639. $result['info'] = '车辆库存不足,无法自动派车!';
  640. return $result;
  641. }
  642. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  643. if ($answer["achieved_attendance"] < 0.9) {
  644. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Zc_black_order_pool);
  645. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  646. $Zc_black_order_pool = $temp_pool_answe["black_order_pool"];
  647. } else {
  648. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  649. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  650. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  651. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  652. }
  653. if (empty($temp_order_pool) && empty($Zc['hotel_list'])) {
  654. break;
  655. }
  656. }
  657. }
  658. if (!empty($Za)) {
  659. // 存在Za产品订单
  660. ZA:
  661. for (; ;) {
  662. if (!empty($Za['hotel_list'])) {
  663. sort($Za['hotel_list']);
  664. $tt_people = 0;
  665. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  666. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  667. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  668. }
  669. }
  670. if ($tt_people < $bus_stock["0"]) {
  671. for ($i = 0; $i < count($Za['hotel_list']["0"]["order_list"]); $i++) {
  672. $temp_order_pool[] = $Za['hotel_list']["0"]["order_list"][$i];
  673. }
  674. array_splice($Za['hotel_list'], 0, 1);
  675. if (!empty($Za['hotel_list'])) {
  676. goto ZA;
  677. }
  678. }
  679. }
  680. $orders = $dispatch->change_data_type($temp_order_pool);
  681. if (empty($bus_stock)) {
  682. $result['code'] = '1';
  683. $result['info'] = '车辆库存不足,无法自动派车!';
  684. return $result;
  685. }
  686. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  687. if ($answer["achieved_attendance"] < 0.9) {
  688. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Za_black_order_pool);
  689. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  690. $Za_black_order_pool = $temp_pool_answe["black_order_pool"];
  691. } else {
  692. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  693. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  694. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  695. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  696. }
  697. if (empty($temp_order_pool) && empty($Za['hotel_list'])) {
  698. break;
  699. }
  700. }
  701. }
  702. $Min_bus_seat_number = 30;
  703. $Z_b_c_black_pool = $dispatch->merge_black_pool($Zb_black_order_pool, $Zc_black_order_pool);
  704. while (true) {
  705. if (empty($bus_stock)) {
  706. $result['code'] = '1';
  707. $result['info'] = '车辆库存不足,无法自动派车!';
  708. return $result;
  709. }
  710. $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  711. if ($dispatch->pool_count_people_number($Z_b_c_black_pool) < $stock_change_style[count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)) - 1]["bus_seat_number"] * 0.9) {
  712. break;
  713. }
  714. $attendance_arr = array();
  715. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  716. $orders = $dispatch->change_data_type($Z_b_c_black_pool);
  717. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  718. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  719. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  720. }
  721. $existence_best = 0;
  722. $best_attendance = 0;
  723. $best_attendance_jj = 0;
  724. $Max_attendance = 0;
  725. $Max_attendance_jj = 0;
  726. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  727. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($Z_b_c_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($Z_b_c_black_pool))) {
  728. if ($existence_best == 1) {
  729. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  730. $best_attendance = $attendance_arr[$temp_jj];
  731. $best_attendance_jj = $temp_jj;
  732. }
  733. } else {
  734. $existence_best = 1;
  735. $best_attendance = $attendance_arr[$temp_jj];
  736. $best_attendance_jj = $temp_jj;
  737. }
  738. }
  739. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  740. $Max_attendance = $attendance_arr[$temp_jj];
  741. $Max_attendance_jj = $temp_jj;
  742. }
  743. }
  744. $optimal_answer = array();
  745. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  746. if ($existence_best) {
  747. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  748. } else {
  749. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  750. }
  751. $optimal_bus_and_pool_answer = array();
  752. if ($existence_best) {
  753. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_b_c_black_pool, $bus_stock,
  754. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  755. } else {
  756. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_b_c_black_pool, $bus_stock,
  757. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  758. }
  759. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  760. $Z_b_c_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  761. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  762. }
  763. $Z_a_e_black_pool = $dispatch->merge_black_pool($Za_black_order_pool, $Ze_black_order_pool);
  764. while (true) {
  765. if (empty($bus_stock)) {
  766. $result['code'] = '1';
  767. $result['info'] = '车辆库存不足,无法自动派车!';
  768. return $result;
  769. }
  770. $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  771. if ($dispatch->pool_count_people_number($Z_a_e_black_pool) < $stock_change_style[count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)) - 1]["bus_seat_number"] * 0.9) {
  772. break;
  773. }
  774. $attendance_arr = array();
  775. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  776. $orders = $dispatch->change_data_type($Z_a_e_black_pool);
  777. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  778. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  779. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  780. }
  781. $existence_best = 0;
  782. $best_attendance = 0;
  783. $best_attendance_jj = 0;
  784. $Max_attendance = 0;
  785. $Max_attendance_jj = 0;
  786. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  787. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($Z_a_e_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($Z_a_e_black_pool))) {
  788. if ($existence_best == 1) {
  789. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  790. $best_attendance = $attendance_arr[$temp_jj];
  791. $best_attendance_jj = $temp_jj;
  792. }
  793. } else {
  794. $existence_best = 1;
  795. $best_attendance = $attendance_arr[$temp_jj];
  796. $best_attendance_jj = $temp_jj;
  797. }
  798. }
  799. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  800. $Max_attendance = $attendance_arr[$temp_jj];
  801. $Max_attendance_jj = $temp_jj;
  802. }
  803. }
  804. $optimal_answer = array();
  805. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  806. if ($existence_best) {
  807. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  808. } else {
  809. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  810. }
  811. $optimal_bus_and_pool_answer = array();
  812. if ($existence_best) {
  813. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_a_e_black_pool, $bus_stock,
  814. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  815. } else {
  816. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_a_e_black_pool, $bus_stock,
  817. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  818. }
  819. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  820. $Z_a_e_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  821. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  822. }
  823. $Z_all_black_pool = $dispatch->merge_black_pool($Z_a_e_black_pool, $Z_b_c_black_pool);
  824. while ($dispatch->pool_count_people_number($Z_all_black_pool) != 0) {
  825. if (empty($bus_stock)) {
  826. $result['code'] = '1';
  827. $result['info'] = '车辆库存不足,无法自动派车!';
  828. return $result;
  829. }
  830. $attendance_arr = array();
  831. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  832. $orders = $dispatch->change_data_type($Z_all_black_pool);
  833. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  834. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  835. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  836. }
  837. $existence_best = 0;
  838. $best_attendance = 0;
  839. $best_attendance_jj = 0;
  840. $Max_attendance = 0;
  841. $Max_attendance_jj = 0;
  842. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  843. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($Z_all_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($Z_all_black_pool))) {
  844. if ($existence_best == 1) {
  845. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  846. $best_attendance = $attendance_arr[$temp_jj];
  847. $best_attendance_jj = $temp_jj;
  848. }
  849. } else {
  850. $existence_best = 1;
  851. $best_attendance = $attendance_arr[$temp_jj];
  852. $best_attendance_jj = $temp_jj;
  853. }
  854. }
  855. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  856. $Max_attendance = $attendance_arr[$temp_jj];
  857. $Max_attendance_jj = $temp_jj;
  858. }
  859. }
  860. $optimal_answer = array();
  861. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  862. if ($existence_best) {
  863. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  864. } else {
  865. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  866. }
  867. $optimal_bus_and_pool_answer = array();
  868. if ($existence_best) {
  869. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_all_black_pool, $bus_stock,
  870. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  871. } else {
  872. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_all_black_pool, $bus_stock,
  873. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  874. }
  875. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  876. $Z_all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  877. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  878. }
  879. if (!empty($Te)) {
  880. // 存在Te产品订单
  881. M:
  882. for (; ;) {
  883. if (!empty($Te['hotel_list'])) {
  884. sort($Te['hotel_list']);
  885. $tt_people = 0;
  886. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  887. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  888. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  889. }
  890. }
  891. if ($tt_people < $bus_stock["0"]) {
  892. for ($i = 0; $i < count($Te['hotel_list']["0"]["order_list"]); $i++) {
  893. $temp_order_pool[] = $Te['hotel_list']["0"]["order_list"][$i];
  894. }
  895. array_splice($Te['hotel_list'], 0, 1);
  896. if (!empty($Te['hotel_list'])) {
  897. goto M;
  898. }
  899. }
  900. }
  901. $orders = $dispatch->change_data_type($temp_order_pool);
  902. if (empty($bus_stock)) {
  903. $result['code'] = '1';
  904. $result['info'] = '车辆库存不足,无法自动派车!';
  905. return $result;
  906. }
  907. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  908. if ($answer["achieved_attendance"] < 0.9) {
  909. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Te_black_order_pool);
  910. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  911. $Te_black_order_pool = $temp_pool_answe["black_order_pool"];
  912. } else {
  913. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  914. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  915. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  916. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  917. }
  918. if (empty($temp_order_pool) && empty($Te['hotel_list'])) {
  919. break;
  920. }
  921. }
  922. }
  923. if (!empty($Tb)) {
  924. // 存在Tb产品订单
  925. N:
  926. for (; ;) {
  927. if (!empty($Tb['hotel_list'])) {
  928. sort($Tb['hotel_list']);
  929. $tt_people = 0;
  930. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  931. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  932. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  933. }
  934. }
  935. if ($tt_people < $bus_stock["0"]) {
  936. for ($i = 0; $i < count($Tb['hotel_list']["0"]["order_list"]); $i++) {
  937. $temp_order_pool[] = $Tb['hotel_list']["0"]["order_list"][$i];
  938. }
  939. array_splice($Tb['hotel_list'], 0, 1);
  940. if (!empty($Tb['hotel_list'])) {
  941. goto N;
  942. }
  943. }
  944. }
  945. $orders = $dispatch->change_data_type($temp_order_pool);
  946. if (empty($bus_stock)) {
  947. $result['code'] = '1';
  948. $result['info'] = '车辆库存不足,无法自动派车!';
  949. return $result;
  950. }
  951. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  952. if ($answer["achieved_attendance"] < 0.9) {
  953. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tb_black_order_pool);
  954. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  955. $Tb_black_order_pool = $temp_pool_answe["black_order_pool"];
  956. } else {
  957. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  958. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  959. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  960. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  961. }
  962. if (empty($temp_order_pool) && empty($Tb['hotel_list'])) {
  963. break;
  964. }
  965. }
  966. }
  967. if (!empty($Tc)) {
  968. // 存在Tc产品订单
  969. Q:
  970. for (; ;) {
  971. if (!empty($Tc['hotel_list'])) {
  972. sort($Tc['hotel_list']);
  973. $tt_people = 0;
  974. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  975. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  976. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  977. }
  978. }
  979. if ($tt_people < $bus_stock["0"]) {
  980. for ($i = 0; $i < count($Tc['hotel_list']["0"]["order_list"]); $i++) {
  981. $temp_order_pool[] = $Tc['hotel_list']["0"]["order_list"][$i];
  982. }
  983. array_splice($Tc['hotel_list'], 0, 1);
  984. if (!empty($Tc['hotel_list'])) {
  985. goto Q;
  986. }
  987. }
  988. }
  989. $orders = $dispatch->change_data_type($temp_order_pool);
  990. if (empty($bus_stock)) {
  991. $result['code'] = '1';
  992. $result['info'] = '车辆库存不足,无法自动派车!';
  993. return $result;
  994. }
  995. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  996. if ($answer["achieved_attendance"] < 0.9) {
  997. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tc_black_order_pool);
  998. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  999. $Tc_black_order_pool = $temp_pool_answe["black_order_pool"];
  1000. } else {
  1001. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  1002. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  1003. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  1004. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  1005. }
  1006. if (empty($temp_order_pool) && empty($Tc['hotel_list'])) {
  1007. break;
  1008. }
  1009. }
  1010. }
  1011. if (!empty($Ta)) {
  1012. // 存在Ta产品订单
  1013. E:
  1014. for (; ;) {
  1015. if (!empty($Ta['hotel_list'])) {
  1016. sort($Ta['hotel_list']);
  1017. $tt_people = 0;
  1018. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  1019. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  1020. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  1021. }
  1022. }
  1023. if ($tt_people < $bus_stock["0"]) {
  1024. for ($i = 0; $i < count($Ta['hotel_list']["0"]["order_list"]); $i++) {
  1025. $temp_order_pool[] = $Ta['hotel_list']["0"]["order_list"][$i];
  1026. }
  1027. array_splice($Ta['hotel_list'], 0, 1);
  1028. if (!empty($Ta['hotel_list'])) {
  1029. goto E;
  1030. }
  1031. }
  1032. }
  1033. $orders = $dispatch->change_data_type($temp_order_pool);
  1034. if (empty($bus_stock)) {
  1035. $result['code'] = '1';
  1036. $result['info'] = '车辆库存不足,无法自动派车!';
  1037. return $result;
  1038. }
  1039. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  1040. if ($answer["achieved_attendance"] < 0.9) {
  1041. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Ta_black_order_pool);
  1042. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  1043. $Ta_black_order_pool = $temp_pool_answe["black_order_pool"];
  1044. } else {
  1045. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  1046. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  1047. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  1048. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  1049. }
  1050. if (empty($temp_order_pool) && empty($Ta['hotel_list'])) {
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. $Min_bus_seat_number = 30;
  1056. $b_c_black_pool = $dispatch->merge_black_pool($Tb_black_order_pool, $Tc_black_order_pool);
  1057. while (true) {
  1058. if (empty($bus_stock)) {
  1059. $result['code'] = '1';
  1060. $result['info'] = '车辆库存不足,无法自动派车!';
  1061. return $result;
  1062. }
  1063. $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1064. if ($dispatch->pool_count_people_number($b_c_black_pool) < $stock_change_style[count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)) - 1]["bus_seat_number"] * 0.9) {
  1065. break;
  1066. }
  1067. $attendance_arr = array();
  1068. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  1069. $orders = $dispatch->change_data_type($b_c_black_pool);
  1070. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1071. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  1072. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  1073. }
  1074. $existence_best = 0;
  1075. $best_attendance = 0;
  1076. $best_attendance_jj = 0;
  1077. $Max_attendance = 0;
  1078. $Max_attendance_jj = 0;
  1079. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  1080. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($b_c_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($b_c_black_pool))) {
  1081. if ($existence_best == 1) {
  1082. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  1083. $best_attendance = $attendance_arr[$temp_jj];
  1084. $best_attendance_jj = $temp_jj;
  1085. }
  1086. } else {
  1087. $existence_best = 1;
  1088. $best_attendance = $attendance_arr[$temp_jj];
  1089. $best_attendance_jj = $temp_jj;
  1090. }
  1091. }
  1092. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  1093. $Max_attendance = $attendance_arr[$temp_jj];
  1094. $Max_attendance_jj = $temp_jj;
  1095. }
  1096. }
  1097. $optimal_answer = array();
  1098. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1099. if ($existence_best) {
  1100. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1101. } else {
  1102. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1103. }
  1104. $optimal_bus_and_pool_answer = array();
  1105. if ($existence_best) {
  1106. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $b_c_black_pool, $bus_stock,
  1107. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1108. } else {
  1109. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $b_c_black_pool, $bus_stock,
  1110. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1111. }
  1112. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  1113. $b_c_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  1114. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  1115. }
  1116. $a_e_black_pool = $dispatch->merge_black_pool($Ta_black_order_pool, $Te_black_order_pool);
  1117. while (true) {
  1118. if (empty($bus_stock)) {
  1119. $result['code'] = '1';
  1120. $result['info'] = '车辆库存不足,无法自动派车!';
  1121. return $result;
  1122. }
  1123. $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1124. if ($dispatch->pool_count_people_number($a_e_black_pool) < $stock_change_style[count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)) - 1]["bus_seat_number"] * 0.9) {
  1125. break;
  1126. }
  1127. $attendance_arr = array();
  1128. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  1129. $orders = $dispatch->change_data_type($a_e_black_pool);
  1130. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1131. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  1132. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  1133. }
  1134. $existence_best = 0;
  1135. $best_attendance = 0;
  1136. $best_attendance_jj = 0;
  1137. $Max_attendance = 0;
  1138. $Max_attendance_jj = 0;
  1139. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  1140. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($a_e_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($a_e_black_pool))) {
  1141. if ($existence_best == 1) {
  1142. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  1143. $best_attendance = $attendance_arr[$temp_jj];
  1144. $best_attendance_jj = $temp_jj;
  1145. }
  1146. } else {
  1147. $existence_best = 1;
  1148. $best_attendance = $attendance_arr[$temp_jj];
  1149. $best_attendance_jj = $temp_jj;
  1150. }
  1151. }
  1152. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  1153. $Max_attendance = $attendance_arr[$temp_jj];
  1154. $Max_attendance_jj = $temp_jj;
  1155. }
  1156. }
  1157. $optimal_answer = array();
  1158. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1159. if ($existence_best) {
  1160. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1161. } else {
  1162. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1163. }
  1164. $optimal_bus_and_pool_answer = array();
  1165. if ($existence_best) {
  1166. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $a_e_black_pool, $bus_stock,
  1167. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1168. } else {
  1169. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $a_e_black_pool, $bus_stock,
  1170. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1171. }
  1172. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  1173. $a_e_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  1174. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  1175. }
  1176. $all_black_pool = $dispatch->merge_black_pool($a_e_black_pool, $b_c_black_pool);// 得到ae的合并拼车pool
  1177. while ($dispatch->pool_count_people_number($all_black_pool) != 0) {
  1178. if (empty($bus_stock)) {
  1179. $result['code'] = '1';
  1180. $result['info'] = '车辆库存不足,无法自动派车!';
  1181. return $result;
  1182. }
  1183. $attendance_arr = array();//判断筛选最优上座率
  1184. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  1185. $orders = $dispatch->change_data_type($all_black_pool);
  1186. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1187. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  1188. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];// 记录每种车型的上座率
  1189. }
  1190. $existence_best = 0;
  1191. $best_attendance = 0;
  1192. $best_attendance_jj = 0;
  1193. $Max_attendance = 0;
  1194. $Max_attendance_jj = 0;
  1195. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  1196. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($all_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($all_black_pool))) {
  1197. if ($existence_best == 1) {
  1198. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  1199. $best_attendance = $attendance_arr[$temp_jj];
  1200. $best_attendance_jj = $temp_jj;
  1201. }
  1202. } else {
  1203. $existence_best = 1;
  1204. $best_attendance = $attendance_arr[$temp_jj];
  1205. $best_attendance_jj = $temp_jj;
  1206. }
  1207. }
  1208. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  1209. $Max_attendance = $attendance_arr[$temp_jj];
  1210. $Max_attendance_jj = $temp_jj;
  1211. }
  1212. }
  1213. $optimal_answer = array();
  1214. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1215. if ($existence_best) {
  1216. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1217. } else {
  1218. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1219. }
  1220. $optimal_bus_and_pool_answer = array();
  1221. if ($existence_best) {
  1222. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $all_black_pool, $bus_stock,
  1223. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1224. } else {
  1225. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $all_black_pool, $bus_stock,
  1226. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1227. }
  1228. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  1229. $all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  1230. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  1231. }
  1232. if (!empty($Taeab)) {
  1233. // 存在$Taeab产品订单
  1234. P:
  1235. for (; ;) {
  1236. if (!empty($Taeab['hotel_list'])) {
  1237. sort($Taeab['hotel_list']);
  1238. $tt_people = 0;
  1239. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  1240. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  1241. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  1242. }
  1243. }
  1244. if ($tt_people < $bus_stock["0"]) {
  1245. for ($i = 0; $i < count($Taeab['hotel_list']["0"]["order_list"]); $i++) {
  1246. $temp_order_pool[] = $Taeab['hotel_list']["0"]["order_list"][$i];
  1247. }
  1248. array_splice($Taeab['hotel_list'], 0, 1);
  1249. if (!empty($Taeab['hotel_list'])) {
  1250. goto P;
  1251. }
  1252. }
  1253. }
  1254. $orders = $dispatch->change_data_type($temp_order_pool);
  1255. if (empty($bus_stock)) {
  1256. $result['code'] = '1';
  1257. $result['info'] = '车辆库存不足,无法自动派车!';
  1258. return $result;
  1259. }
  1260. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  1261. if ($answer["achieved_attendance"] < 0.9) {
  1262. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Taeab_two_scenic_black_order_pool);
  1263. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  1264. $Taeab_two_scenic_black_order_pool = $temp_pool_answe["black_order_pool"];
  1265. } else {
  1266. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  1267. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  1268. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  1269. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  1270. }
  1271. if (empty($temp_order_pool) && empty($Taeab['hotel_list'])) {
  1272. break;
  1273. }
  1274. }
  1275. }
  1276. if (!empty($Tbcbe)) {
  1277. // 存在$Tbcbe产品订单
  1278. O:
  1279. for (; ;) {
  1280. if (!empty($Tbcbe['hotel_list'])) {
  1281. sort($Tbcbe['hotel_list']);
  1282. $tt_people = 0;
  1283. for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) {
  1284. if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) {
  1285. $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"];
  1286. }
  1287. }
  1288. if ($tt_people < $bus_stock["0"]) {
  1289. for ($i = 0; $i < count($Tbcbe['hotel_list']["0"]["order_list"]); $i++) {
  1290. $temp_order_pool[] = $Tbcbe['hotel_list']["0"]["order_list"][$i];
  1291. }
  1292. array_splice($Tbcbe['hotel_list'], 0, 1);
  1293. if (!empty($Tbcbe['hotel_list'])) {
  1294. goto O;
  1295. }
  1296. }
  1297. }
  1298. $orders = $dispatch->change_data_type($temp_order_pool);
  1299. if (empty($bus_stock)) {
  1300. $result['code'] = '1';
  1301. $result['info'] = '车辆库存不足,无法自动派车!';
  1302. return $result;
  1303. }
  1304. $answer = $dispatch->dp($orders, $bus_stock["0"]);
  1305. if ($answer["achieved_attendance"] < 0.9) {
  1306. $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tbcbe_two_scenic_black_order_pool);
  1307. $temp_order_pool = $temp_pool_answe["temp_order_pool"];
  1308. $Tbcbe_two_scenic_black_order_pool = $temp_pool_answe["black_order_pool"];
  1309. } else {
  1310. $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock);
  1311. $white_bus_pool[] = $temp_bus_and_pool_answer["bus"];
  1312. $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"];
  1313. $bus_stock = $temp_bus_and_pool_answer["bus_stock"];
  1314. }
  1315. if (empty($temp_order_pool) && empty($Tbcbe['hotel_list'])) {
  1316. break;
  1317. }
  1318. }
  1319. }
  1320. $two_scenic_all_black_pool = $dispatch->merge_black_pool($Taeab_two_scenic_black_order_pool, $Tbcbe_two_scenic_black_order_pool);// 得到ae ab和bcbe的合并拼车pool
  1321. while ($dispatch->pool_count_people_number($two_scenic_all_black_pool) != 0) {
  1322. if (empty($bus_stock)) {
  1323. $result['code'] = '1';
  1324. $result['info'] = '车辆库存不足,无法自动派车!';
  1325. return $result;
  1326. }
  1327. $attendance_arr = array();
  1328. for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) {
  1329. $orders = $dispatch->change_data_type($two_scenic_all_black_pool);
  1330. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1331. $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]);
  1332. $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];
  1333. }
  1334. $existence_best = 0;
  1335. $best_attendance = 0;
  1336. $best_attendance_jj = 0;
  1337. $Max_attendance = 0;
  1338. $Max_attendance_jj = 0;
  1339. for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) {
  1340. if ($attendance_arr[$temp_jj] > 0.7 && ($temp_data[$temp_jj]["bus_seat_number"] > $dispatch->pool_count_people_number($two_scenic_all_black_pool) || $temp_data[$temp_jj]["bus_seat_number"] == $dispatch->pool_count_people_number($two_scenic_all_black_pool))) {
  1341. if ($existence_best == 1) {
  1342. if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) {
  1343. $best_attendance = $attendance_arr[$temp_jj];
  1344. $best_attendance_jj = $temp_jj;
  1345. }
  1346. } else {
  1347. $existence_best = 1;
  1348. $best_attendance = $attendance_arr[$temp_jj];
  1349. $best_attendance_jj = $temp_jj;
  1350. }
  1351. }
  1352. if ($attendance_arr[$temp_jj] > $Max_attendance) {
  1353. $Max_attendance = $attendance_arr[$temp_jj];
  1354. $Max_attendance_jj = $temp_jj;
  1355. }
  1356. }
  1357. $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number);
  1358. if ($existence_best) {
  1359. $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1360. } else {
  1361. $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1362. }
  1363. if ($existence_best) {
  1364. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $two_scenic_all_black_pool, $bus_stock,
  1365. $temp_data[$best_attendance_jj]["bus_seat_number"]);
  1366. } else {
  1367. $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $two_scenic_all_black_pool, $bus_stock,
  1368. $temp_data[$Max_attendance_jj]["bus_seat_number"]);
  1369. }
  1370. $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"];
  1371. $two_scenic_all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"];
  1372. $bus_stock = $optimal_bus_and_pool_answer["bus_stock"];
  1373. }
  1374. $sql_dispatch = '';
  1375. $final_info = array();
  1376. foreach ($white_bus_pool as $temp11) {
  1377. foreach ($bus_detail as $k => $detail) {
  1378. if ($temp11['bus_seat_number'] == $detail[0]) {
  1379. $temp11['info'] = $detail;
  1380. $final_info[] = $temp11;
  1381. unset($bus_detail[$k]);
  1382. break;
  1383. }
  1384. }
  1385. }
  1386. #endregion
  1387. $bus_order_id = 1; //初始化车次编号
  1388. //SQL:查询order_main中有没有当前的班次,如果有,说明不是第一次点击分成
  1389. $sql_exist = "select run_id from run_main where RUN_DATE='{$param['run_date']}' AND PROD_ID=0 LIMIT 1";
  1390. $res_exist = $this->query($sql_exist);
  1391. if ($res_exist) {//如果是今天的第二次或者多次点击自动分车 更新run_bus
  1392. #----以下---这里要对已分车的订单做处理,否则形如z(j)这样的线路订单在二次分车时会出现错误,因为它不在分车算法内,所以仅用覆盖的方法会漏掉。---温依莅
  1393. //首先得到分车算法覆盖的订单,和今日的订单做比对
  1394. #分车算法已分的子订单集合
  1395. $str_order_id = '';
  1396. foreach ($final_info as $k => $v) { //$k:派了第几辆车
  1397. $sub_order_id = '';
  1398. foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息
  1399. $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表
  1400. }
  1401. $str_order_id .= $sub_order_id;
  1402. }
  1403. $after_order_arr = explode(',', trim($str_order_id, ','));
  1404. #今日所有应分配的子订单集合
  1405. $all_sub_order_id = '';
  1406. foreach ($res['data'][0] as $k2 => $v2) { //$k:派了第几辆车
  1407. $all_sub_order_id .= $v2['sub_order_id'] . ','; //单一线路订单ID列表
  1408. }
  1409. $all_str_order_id = substr($all_sub_order_id, 0, -1);
  1410. $all_order_arr = explode(',', $all_str_order_id);
  1411. //作比较得到未参与分车的订单集合
  1412. $diff_arr = array_diff($all_order_arr, $after_order_arr);
  1413. $diff_str = implode(',', $diff_arr);
  1414. //如果非空则设置run_bus_order_id为0
  1415. if (!empty($diff_arr)) {
  1416. $sql = "update order_main set run_bus_order_id=0 where order_id in ($diff_str);";
  1417. zzcsUtils::writeLog($sql);
  1418. $tmres = $this->exec($sql);
  1419. if (false === $tmres) {
  1420. $result['code'] = '5';
  1421. $result['info'] = '重置部分订单失败';
  1422. return $result;
  1423. }
  1424. }
  1425. #----以上----#
  1426. //SQL:获取当前已经存在的所有车次
  1427. $sql_bus_order_id = "select bus_order_id from run_bus where run_id={$res_exist[0]['run_id']} AND CANCEL_FLAG=0";
  1428. $res_bus_order_id = $this->query($sql_bus_order_id);
  1429. $arr_bus_order_id = array();
  1430. foreach ($res_bus_order_id as $bus_id) {
  1431. $arr_bus_order_id[] = $bus_id['bus_order_id'];
  1432. }
  1433. //$sql_dispatch .= "delete from run_bus WHERE run_id={$res_exist[0]['run_id']};";
  1434. foreach ($final_info as $k => $v) { //$k:派了第几辆车
  1435. $seat_type = $v['bus_seat_number'];//车辆座位类型
  1436. $seated_count = $v["already_seat_number"]; //已经入坐的人数
  1437. $brand_id = $v['info'][2]; //车辆品牌ID info[0]:seat_count;info[1]:bus_id ;info[2]:brand_id
  1438. if (in_array($bus_order_id, $arr_bus_order_id)) { //当前车次号已经存在,不需要在run_bus中添加,更新就可以了
  1439. $sql_dispatch .= "update run_bus SET UPDATE_USER_ID={$user_id},UPDATE_TIME=NOW(),run_id={$res_exist[0]['run_id']},bus_order_id={$bus_order_id},
  1440. bus_type_res_id={$v['info'][3]},seat_count={$seat_type},saled_count={$seated_count},brand_res_id={$brand_id},RUN_BUS_STATUS=138,send_bus_res_id=0,send_bus_type_res_id=0,send_bus_driver_res_id=0,send_bus_no='',send_driver_name='',send_driver_mobile='',send_tour_guide_name='',send_tour_guide_res_id=0,send_tour_guide_mobile='',GROUP_LINE_FLAG=1,REAL_TOTAL_COUNT={$seated_count} WHERE run_id={$res_exist[0]['run_id']} AND BUS_ORDER_ID={$bus_order_id};";
  1441. foreach ($arr_bus_order_id as $bus_k => $bus_v) {
  1442. if ($bus_v == $bus_order_id) {
  1443. unset($arr_bus_order_id[$bus_k]);
  1444. }
  1445. }
  1446. } else {
  1447. $sql_dispatch .= "INSERT INTO run_bus(CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME,run_id,bus_order_id,bus_type_res_id,
  1448. seat_count,saled_count,brand_res_id,RUN_BUS_STATUS,GROUP_LINE_FLAG,REAL_TOTAL_COUNT) VALUES($user_id,now(),$user_id,now(),{$res_exist[0]['run_id']},$bus_order_id,{$v['info'][3]},$seat_type,$seated_count,$brand_id,138,1,{$seated_count});";
  1449. }
  1450. $sub_order_id = '';
  1451. foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息
  1452. $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表
  1453. }
  1454. $str_order_id = substr($sub_order_id, 0, -1);
  1455. $sql_dispatch .= "update order_main set UPDATE_USER_ID=$user_id,UPDATE_TIME=now(),RUN_ID={$res_exist[0]['run_id']},RUN_BUS_ORDER_ID=$bus_order_id WHERE order_id IN($str_order_id);";
  1456. $bus_order_id++;
  1457. }
  1458. $arr_bus_order_id;
  1459. if (!empty($arr_bus_order_id)) { //TODO:多次点击派车时,需要将之前派出的车次但是本次并没有用到的车的cancel_flag置为1
  1460. $cancel_bus_id = '';
  1461. foreach ($arr_bus_order_id as $v_bus) {
  1462. $cancel_bus_id .= $v_bus . ',';
  1463. }
  1464. $cancel_bus_id = substr($cancel_bus_id, 0, -1);
  1465. $sql_dispatch .= "update run_bus set CANCEL_FLAG=1 WHERE run_id={$res_exist[0]['run_id']} AND BUS_ORDER_ID in ($cancel_bus_id);";
  1466. }
  1467. } else {//第一次点击自动分车
  1468. $sql_get_run_id = "SELECT FUNC_GET_UNIQUE_ID(3,1) as run_id"; //生成新的run_id
  1469. $res_run_id = $this->query($sql_get_run_id); //得到run_id
  1470. $start_time = '';
  1471. foreach ($final_info as $k => $v) { //$k:派了第几辆车
  1472. $seat_type = $v['bus_seat_number'];//车辆座位类型
  1473. $seated_count = $v["already_seat_number"]; //已经入坐的人数
  1474. $brand_id = $v['info'][2]; //车辆品牌ID info[0]:seat_count;info[1]:bus_id ;info[2]:brand_id
  1475. $sql_dispatch .= "INSERT INTO run_bus(CREATE_USER_ID,CREATE_TIME,UPDATE_USER_ID,UPDATE_TIME,run_id,bus_order_id,bus_type_res_id,saled_count,seat_count,brand_res_id,RUN_BUS_STATUS,GROUP_LINE_FLAG,REAL_TOTAL_COUNT) VALUES($user_id,now(),$user_id,now(),{$res_run_id[0]['run_id']},$bus_order_id,{$v['info'][3]},$seated_count,$seat_type,$brand_id,138,1,{$seated_count});";
  1476. $sub_order_id = '';
  1477. foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息
  1478. $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表
  1479. }
  1480. $start_time = $v['order_list'][0]['start_time'];
  1481. $str_order_id = substr($sub_order_id, 0, -1);
  1482. $sql_dispatch .= "update order_main set UPDATE_USER_ID=$user_id,UPDATE_TIME=now(),RUN_ID={$res_run_id[0]['run_id']},RUN_BUS_ORDER_ID=$bus_order_id WHERE order_id IN($str_order_id);";
  1483. $bus_order_id++;
  1484. }
  1485. $time = explode(':', $start_time);
  1486. $run_minutes = $time[0] * 60 + $time[1];
  1487. $sql_dispatch .= "INSERT INTO run_main(run_id,run_lock_type,run_date,run_time,run_minutes,create_user_id,create_time,run_status) VALUES({$res_run_id[0]['run_id']},121,'{$param['run_date']}','{$start_time}','{$run_minutes}',$user_id,NOW(),138);";
  1488. $sql = "SELECT l.line_id,l.line_name,l.line_code,l.line_type,l.org_id,l.sale_expired_type,l.sale_expired_time,s.order_id,s.res_id,s.start_minutes,s.inout_type,s.checkport_res_id,s.area_id
  1489. FROM
  1490. opera_line AS l,
  1491. opera_station AS s
  1492. WHERE
  1493. l.line_id = s.line_id
  1494. AND l.cancel_flag = 0
  1495. AND s.cancel_flag = 0
  1496. AND l.line_id =451483";//土楼专线岛外上车(Z00): waice(450890) -> ctsdata(451483)
  1497. $res_station = $this->query($sql);
  1498. foreach ($res_station as $k_s => $v_s) {
  1499. $start_minutes = $run_minutes + $v_s['start_minutes'];
  1500. $sql_dispatch .= "insert into run_station(run_id,STATION_ORDER_ID,START_TIME,START_MINUTES,STATION_RES_ID,STATION_INOUT_TYPE,CREATE_USER_ID,CREATE_TIME,AREA_ID)
  1501. VALUES({$res_run_id[0]['run_id']},{$v_s['order_id']},'{$start_time}','{$start_minutes}',{$v_s['res_id']},{$v_s['inout_type']},$user_id,now(),{$v_s['area_id']});";
  1502. }
  1503. }
  1504. //将分车后的结果反应到相应的表中
  1505. zzcsUtils::writeLog($sql_dispatch);
  1506. $res_exec = $this->exec($sql_dispatch);
  1507. if (!$res_exec) {
  1508. $result['code'] = '1';
  1509. $result['info'] = '自动分车执行失败';
  1510. return $result;
  1511. }
  1512. $result['code'] = '0';
  1513. $result['info'] = '自动分车执行成功';;
  1514. return $result;
  1515. }
  1516. /*
  1517. * wangxj
  1518. * 组合线路+车,影响run_bus表
  1519. * @run_id 班次ID
  1520. *
  1521. */
  1522. public function addBus($params)
  1523. {
  1524. $user_id = $this->user_id;
  1525. $valid = zzcsUtils::validateParams(array(
  1526. 'run_date' => 'empty'
  1527. ));
  1528. if (!$valid['status']) {
  1529. $result['code'] = (string)$valid['status'];
  1530. $result['info'] = $valid['info'];
  1531. return $result;
  1532. }
  1533. $run_date = $params['run_date'];
  1534. //$sql = "select bus_id,brand_id,seat_count from base_bus WHERE BUS_STATE=336 ORDER BY seat_count DESC LIMIT 1";
  1535. $sql = $this->getEnableCar($run_date); //获取当前可用的车次
  1536. $res = $this->query($sql);
  1537. if ($res) {
  1538. $seat_count = $res[0]['seat_count'];
  1539. $bus_type_res_id = $res[0]['bus_type_res_id'];
  1540. $sql = "SELECT b.run_id,BUS_ORDER_ID,BUS_TYPE_RES_ID from run_bus b LEFT join run_main m on m.run_id = b.run_id where m.RUN_DATE='$run_date' and m.PROD_ID = 0 ORDER BY b.BUS_ORDER_ID DESC LIMIT 1";
  1541. $run_bus = $this->query($sql);
  1542. if ($run_bus) {
  1543. $bus_order_id = $run_bus[0]['BUS_ORDER_ID'] + 1;
  1544. $run_id = $run_bus[0]['run_id'];
  1545. $sql = "insert into run_bus( create_user_id, create_time, update_user_id, update_time, run_id, bus_order_id, saled_count, seat_count, brand_res_id,run_bus_status, BUS_TYPE_RES_ID)"
  1546. . "VALUES( $user_id, now(), $user_id, now(), $run_id, $bus_order_id, 0, $seat_count, 0,138, $bus_type_res_id)";
  1547. $result = $this->insert($sql);
  1548. if ($result === false) {
  1549. $json["code"] = "1";
  1550. $json["info"] = "加车失败!";
  1551. return $json;
  1552. } else {
  1553. $json["code"] = "0";
  1554. $json["info"] = "加车成功!";
  1555. return $json;
  1556. }
  1557. } else {
  1558. $json["code"] = "1";
  1559. $json["info"] = "加车失败!";
  1560. return $json;
  1561. }
  1562. } else {
  1563. $result['code'] = '1';
  1564. $result['info'] = '车辆库存不足!';
  1565. return $result;
  1566. }
  1567. }
  1568. /*
  1569. * wangxj
  1570. * 组合线路减车,影响run_bus表
  1571. * @run_date 日期
  1572. * @bus_order_id 序号
  1573. *
  1574. */
  1575. public function delBus($params)
  1576. {
  1577. $user_id = $this->user_id;
  1578. $valid = zzcsUtils::validateParams(array(
  1579. 'run_date,bus_order_id' => 'empty',
  1580. ));
  1581. if (!$valid['status']) {
  1582. $result['code'] = (string)$valid['status'];
  1583. $result['info'] = $valid['info'];
  1584. return $result;
  1585. }
  1586. $run_date = $params['run_date'];
  1587. $bus_order_id = $params['bus_order_id'];
  1588. $sql = "select id, b.SALED_COUNT SALED_COUNT from run_bus b right JOIN run_main m on m.run_id = b.run_id "
  1589. . "where m.run_date='$run_date' and m.prod_id=0 and b.bus_order_id in ($bus_order_id) ";
  1590. $res = $this->query($sql);
  1591. if ($res) {
  1592. if ($res[0]['SALED_COUNT'] == 0) {
  1593. $id = $res[0]['id'];
  1594. $sql = "update run_bus b set cancel_flag = 1, update_user_id=$user_id and update_time=now() where id=$id";
  1595. $result = $this->exec($sql);
  1596. zzcsUtils::writeLog($sql);
  1597. if ($result === false) {
  1598. $json["code"] = "1";
  1599. $json["info"] = "减车失败!";
  1600. return $json;
  1601. } else {
  1602. $json["code"] = "0";
  1603. $json["info"] = "减车成功!";
  1604. return $json;
  1605. }
  1606. } else {
  1607. $json["code"] = "1";
  1608. $json["info"] = "座位没有清空,无法减车!";
  1609. return $json;
  1610. }
  1611. } else {
  1612. $result['code'] = '1';
  1613. $result['info'] = '无法减车!';
  1614. return $result;
  1615. }
  1616. }
  1617. /**
  1618. * 组合线路获取可用车次::这里限制组合线路分车车次仅限佰廉车队
  1619. * @param $run_date 日期
  1620. * @return $sql
  1621. * User: Steven
  1622. */
  1623. private function getEnableCar($run_date)
  1624. {
  1625. if (date('Y-m-d', strtotime($run_date)) == date('Y-m-d', time())) { //派今天的车
  1626. //SQL:查询今日可用车次
  1627. $sql = "select bus_id,bus_type_res_id,bus_no, seat_count, brand_id ,2 as sort_id
  1628. from base_bus
  1629. where bus_state = 336 and cancel_flag = 0 and org_id=417 and bus_id not in (
  1630. select b.send_bus_res_id
  1631. from run_main m, run_bus b
  1632. where m.run_id = b.run_id and m.run_date = '{$run_date}' and b.run_bus_status in (138,139,140) and b.send_bus_res_id > 0)
  1633. order by seat_count desc;";
  1634. } else {
  1635. //SQL:查询非今日可用车次
  1636. $sql = "select bus_id,bus_type_res_id,bus_no, seat_count, brand_id,2 as sort_id
  1637. from base_bus a
  1638. where a.bus_state = 336 and a.cancel_flag = 0 and a.org_id=417 and a.bus_id not in (
  1639. select b.send_bus_res_id
  1640. from run_main m, run_bus b, run_station s
  1641. where m.run_id = b.run_id and m.run_id = s.RUN_ID and m.prod_id = s.prod_id and m.run_date = '{$run_date}' and m.prod_id > 0 and b.send_bus_res_id > 0
  1642. group by m.run_id,b.send_bus_res_id
  1643. having max(START_MINUTES) > (
  1644. select min(prod_start_station_time_minutes)
  1645. from order_main
  1646. where parent_order_id = 0 and prod_start_station_date = '{$run_date}' and parent_prod_id in (
  1647. select line_id
  1648. from opera_line
  1649. where line_type = 316 and cancel_flag = 0) and order_valid_status = 1 and cancel_flag = 0))
  1650. order by seat_count desc;";
  1651. }
  1652. return $sql;
  1653. }
  1654. /**
  1655. * 组合线路可派车次列表
  1656. * @param $param
  1657. * @return mixed
  1658. * User: Steven
  1659. */
  1660. public function getVehicleList($param)
  1661. {
  1662. #region 获取渠道权限
  1663. $user_id = $this->user_id;
  1664. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  1665. $opera_org_id_result = $this->query($opera_org_id_sql);
  1666. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  1667. if($opera_org_id == ''){
  1668. $and_sql = '';
  1669. }else{
  1670. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  1671. }
  1672. #endregion
  1673. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  1674. $company = isset($param['company']) ? (empty($param['company']) ? "0" : $param['company']) : "0";
  1675. $salecount = isset($param['salecount']) ? (empty($param['salecount']) ? "0" : $param['salecount']) : "0";
  1676. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  1677. //$run_time = isset($param['run_time']) ? (empty($param['run_time']) ? "" : $param['run_time']) : "";
  1678. $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : '';
  1679. $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : '';
  1680. if ($run_id1 == '' || $run_id2 == '') {
  1681. $sql = "select bus_id as res_id,bus_no as vihicle_number,
  1682. ifnull((select res_name from base_resource where res_id = base_bus.brand_id and res_type_id = 134 and cancel_flag =0),'') as vihicle_brand,seat_desc as vihicle_seat,
  1683. ifnull((select res_name from base_resource where res_id = base_bus.org_id and res_type_id = 18 and cancel_flag =0),'') as company_name,seat_count,bus_state as bus_status
  1684. from base_bus
  1685. where cancel_flag = 0 and bus_state = 336 and bus_id not in (
  1686. select ifnull(b.send_bus_res_id,0) as send_bus_res_id
  1687. from run_main m, run_station s ,run_bus b
  1688. where m.run_id = s.run_id and m.run_id = b.run_id and m.run_date = '{$run_date}'
  1689. and m.prod_id > 0 -- 单一线路
  1690. and m.prod_id not in (select distinct sub_line_id from opera_line a,opera_line_group b where a.line_id = b.sub_line_id and a.line_type = 256 )
  1691. and b.send_bus_res_id > 0 and b.cancel_flag = 0
  1692. group by m.run_id,b.bus_order_id
  1693. having max(s.start_minutes) > (select min(prod_start_station_time_minutes)
  1694. from order_main
  1695. where parent_order_id = 0 and prod_start_station_date = '{$run_date}'
  1696. and parent_prod_id in (select line_id from opera_line where line_type = 316 and cancel_flag = 0) and order_valid_status = 1 and cancel_flag = 0)
  1697. )
  1698. and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%'))
  1699. " . $and_sql . "
  1700. and if({$company}<=0,0=0,org_id = {$company}) ";
  1701. } else {
  1702. $sql = "select bus_id as res_id,bus_no as vihicle_number,
  1703. ifnull((select res_name from base_resource where res_id = base_bus.brand_id and res_type_id = 134 and cancel_flag =0),'') as vihicle_brand,seat_desc as vihicle_seat,
  1704. ifnull((select res_name from base_resource where res_id = base_bus.org_id and res_type_id = 18 and cancel_flag =0),'') as company_name,seat_count,bus_state as bus_status
  1705. from base_bus
  1706. where cancel_flag = 0 and bus_state = 336 and bus_id not in (
  1707. select ifnull(b.send_bus_res_id,0) as send_bus_res_id
  1708. from run_main m, run_station s ,run_bus b
  1709. where m.run_id = s.run_id and m.run_id = b.run_id and m.run_date = '{$run_date}' and m.run_id not in ($run_id1,$run_id2) and m.prod_id > 0 -- 单一线路
  1710. and b.send_bus_res_id > 0
  1711. and b.cancel_flag = 0
  1712. group by m.run_id,b.bus_order_id
  1713. having max(s.start_minutes) > (select run_minutes from run_main where run_id = $run_id1)
  1714. union all
  1715. select send_bus_res_id
  1716. from run_bus
  1717. where run_id = $run_id1)
  1718. and seat_count >= $salecount
  1719. " . $and_sql . "
  1720. and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%'))
  1721. and if({$company}<=0,0=0,org_id = {$company}) ";
  1722. }
  1723. zzcsUtils::writeLog($sql);
  1724. $result = $this->query($sql);
  1725. if (false === $result) {
  1726. $json['code'] = '1';
  1727. $json['info'] = '获取可派车次列表失败';
  1728. } else {
  1729. $json['code'] = '0';
  1730. $json['info'] = '获取可派车次列表成功';
  1731. $json['vehicle_list'] = $result;
  1732. }
  1733. return $json;
  1734. }
  1735. /**
  1736. * 组合线路(根据导游姓名手机号和公司)获取可用导游列表
  1737. * @param $param
  1738. * @return mixed
  1739. * User: Steven
  1740. */
  1741. public function getGuideList($param)
  1742. {
  1743. #region 获取渠道权限
  1744. $user_id = $this->user_id;
  1745. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  1746. $opera_org_id_result = $this->query($opera_org_id_sql);
  1747. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  1748. if($opera_org_id == ''){
  1749. $and_sql = '';
  1750. }else{
  1751. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  1752. }
  1753. #endregion
  1754. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  1755. $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0';
  1756. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  1757. $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : '';
  1758. $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : '';
  1759. //SQL:获取组合线路可用导游列表(包括接驳段用过的导游)
  1760. if ($run_id1 == '' || $run_id2 == '') { //初始加载(不传入run_id)
  1761. $sql = "select guide_id as res_id,guide_name,phone_no as guide_phone,(select supplier_name from base_supplier where id = a.org_id) as company_name
  1762. from base_guide a
  1763. where a.cancel_flag = 0
  1764. " . $and_sql . "
  1765. and a.guide_id not in (
  1766. select b.send_tour_guide_res_id
  1767. from run_main m, run_bus b, run_station s
  1768. where m.run_id = b.run_id and m.run_id = s.RUN_ID and m.prod_id = s.prod_id and m.run_date = '{$run_date}' and m.prod_id > 0 and b.send_tour_guide_res_id > 0
  1769. group by m.run_id,b.send_tour_guide_res_id
  1770. having max(START_MINUTES) > (
  1771. select min(prod_start_station_time_minutes)
  1772. from order_main
  1773. where parent_order_id = 0 and prod_start_station_date = '{$run_date}'
  1774. and parent_prod_id in (select line_id from opera_line where line_type = 316 and cancel_flag = 0) and order_valid_status = 1 and cancel_flag = 0))
  1775. AND IF(length(trim({$keyword}))<=0,0=0,(guide_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%')))
  1776. AND IF({$company}<=0,0=0,a.org_id={$company})";
  1777. } else {
  1778. $sql = "select guide_id as res_id,guide_name,phone_no as guide_phone,(select supplier_name from base_supplier where id = a.org_id) as company_name
  1779. from base_guide a
  1780. where a.cancel_flag = 0
  1781. " . $and_sql . "
  1782. and a.guide_id not in (
  1783. select b.send_tour_guide_res_id
  1784. from run_main m, run_station s ,run_bus b
  1785. where m.run_id = s.run_id and m.run_id = b.run_id and m.run_date = '{$run_id1}' and m.run_id not in ($run_id1,$run_id2) and m.prod_id > 0 -- 单一线路
  1786. and b.send_tour_guide_res_id > 0 and b.cancel_flag = 0
  1787. group by m.run_id,b.bus_order_id
  1788. having max(s.start_minutes) > (select run_minutes from run_main where run_id = {$run_id1})
  1789. union all
  1790. select send_tour_guide_res_id
  1791. from run_bus
  1792. where run_id = {$run_id1})
  1793. AND IF(length(trim({$keyword}))<=0,0=0,(guide_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%')))
  1794. AND IF({$company}<=0,0=0,org_id={$company})";
  1795. }
  1796. zzcsUtils::writeLog($sql);
  1797. $result = $this->query($sql);
  1798. if (false === $result) {
  1799. $json['code'] = '1';
  1800. $json['info'] = '数据库错误';
  1801. } else {
  1802. $json['code'] = '0';
  1803. $json['info'] = '返回数据成功';
  1804. $json['guide_list'] = $result;
  1805. }
  1806. return $json;
  1807. }
  1808. /**
  1809. * 组合线路(根据导游姓名手机号和公司)获取可用司机列表
  1810. * @param $param
  1811. * @return mixed
  1812. * User: Steven
  1813. */
  1814. public function getDriverList($param)
  1815. {
  1816. #region 获取渠道权限
  1817. $user_id = $this->user_id;
  1818. $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0";
  1819. $opera_org_id_result = $this->query($opera_org_id_sql);
  1820. $opera_org_id = $opera_org_id_result[0]['opera_org_id'];
  1821. if($opera_org_id == ''){
  1822. $and_sql = '';
  1823. }else{
  1824. $and_sql = " and org_id in (" . $opera_org_id . ") ";
  1825. }
  1826. #endregion
  1827. $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''";
  1828. $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0';
  1829. $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : "";
  1830. $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : '';
  1831. $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : '';
  1832. if ($run_id1 == '' || $run_id2 == '') { //初始加载(不传入run_id)
  1833. $sql = "select driver_id as res_id,driver_name,driver_number,ifnull(phone_no,'') as driver_phone,(select supplier_name from base_supplier where id = a.org_id) as company_name
  1834. from base_driver a
  1835. where a.cancel_flag = 0
  1836. " . $and_sql . "
  1837. and a.driver_id not in (
  1838. select b.send_bus_driver_res_id
  1839. from run_main m, run_bus b, run_station s
  1840. where m.run_id = b.run_id and m.run_id = s.RUN_ID and m.prod_id = s.prod_id and m.run_date = '{$run_date}' and m.prod_id > 0 and b.send_bus_driver_res_id > 0
  1841. group by m.run_id,b.send_bus_driver_res_id
  1842. having max(START_MINUTES) > (
  1843. select min(prod_start_station_time_minutes)
  1844. from order_main
  1845. where parent_order_id = 0 and prod_start_station_date = '{$run_date}'
  1846. and parent_prod_id in (select line_id from opera_line where line_type = 316 and cancel_flag = 0) and order_valid_status = 1 and cancel_flag = 0))
  1847. AND IF(length(trim({$keyword}))<=0,0=0,(driver_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%')))
  1848. AND IF({$company}<=0,0=0,a.org_id={$company})";
  1849. } else { //点击输入框(传入run_id)
  1850. $sql = "select driver_id as res_id,driver_name,driver_number,ifnull(phone_no,'') as driver_phone,(select supplier_name from base_supplier where id = base_driver.org_id) as company_name
  1851. from base_driver
  1852. where cancel_flag = 0
  1853. " . $and_sql . "
  1854. and driver_id not in (
  1855. select ifnull(b.send_bus_driver_res_id,0) as send_bus_driver_res_id
  1856. from run_main m, run_station s ,run_bus b
  1857. where m.run_id = s.run_id and m.run_id = b.run_id and m.run_date = '{$run_date}' and m.run_id not in ($run_id1,$run_id2) and m.prod_id > 0 -- 单一线路
  1858. and b.send_bus_driver_res_id > 0 and b.cancel_flag = 0
  1859. group by m.run_id,b.bus_order_id
  1860. having max(s.start_minutes) > (select run_minutes from run_main where run_id = {$run_id1})
  1861. union all
  1862. select send_bus_driver_res_id
  1863. from run_bus
  1864. where run_id = {$run_id1})
  1865. AND IF(length(trim({$keyword}))<=0,0=0,(driver_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%')))
  1866. AND IF({$company}<=0,0=0,org_id={$company});";
  1867. }
  1868. zzcsUtils::writeLog($sql);
  1869. $result = $this->query($sql);
  1870. if (false === $result) {
  1871. $json['code'] = '1';
  1872. $json['info'] = '司机列表获取失败';
  1873. } else {
  1874. $json['code'] = '0';
  1875. $json['info'] = '司机列表获取成功';
  1876. $json['driver_list'] = $result;
  1877. }
  1878. return $json;
  1879. }
  1880. }