productLine(); if ($res) { $json['code'] = '0'; $json['info'] = '产品线获取成功'; $json['base_info'] = $res; return $json; } } /** * 获取某天某特定组合线路的订单信息 * 温依莅 * 2016.11.03 * @param $param * start_date(date) 出发日期 * line_id(int) 组合订单id * @return * 成功返回参数 * code(str) * info(str) * list_order(array): * order_id(int) 订单id * run_bus_id(int) 车次id,如果无,返回'' * line_codes(str) 订单所对应组合线路编码 * day(int) 标示今天是该订单第几天的行程 * start_station(str) 订单所对应组合线路出发站点 * tran_id(int) 接驳线路id * num(int) 符合条件该线路订单人数 * list_bus(array): 车次及相应剩余座位数 * --run_bus_id(int) 车次id * --stock(int) 余票数 */ public function getOrderDetail($param) { /* start_date:出发日期 line_id:组合订单id */ $start_date = isset($param['start_date']) ? $param['start_date'] : false; $line_id = isset($param['line_id']) ? $param['line_id'] : false; $product_id = isset($param['product_id']) ? $param['product_id'] : false; //判断参数是否缺少 if (false === $start_date || false === $line_id || !trim($start_date) || !trim($line_id)) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //判断日期格式正确 $tmp_arr = explode('-', $start_date); $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期 if (!$bool) { $json['code'] = '1'; $json['info'] = '日期格式不正确'; return $json; } //根据日期和组合线路id得到该日组合订单 分拆后的 订单信息 if($line_id== -1){ $where=''; }else{ $where=" a.PARENT_PROD_ID=$line_id AND "; } $sql = " SELECT *,convert(x.trans_name using gbk) 't1',convert(x.start_station using gbk) 't2' from( SELECT a.order_id, a.customer_mobile as tel, (DATEDIFF('$start_date',a.prod_start_station_date)+1) as day, 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, 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, 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, a.prod_start_station_res_name AS start_station, b.line_code AS line_codes, IFNULL(SUBSTRING_INDEX(a.order_description,'|',-1),0) AS num FROM order_main a LEFT JOIN opera_line b ON a.parent_prod_id = b.line_id WHERE $where '$start_date' IN ( SELECT prod_start_station_date FROM order_main WHERE parent_order_id=a.order_id) AND a.order_valid_status=1 AND a.order_status<>148 AND b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1 ) x ORDER BY t1,t2;"; $order_info = $this->query($sql); if (false === $order_info) { $json['code'] = '1'; $json['info'] = '数据库错误'; return $json; } //若查询无信息 if (count($order_info) == 0) { $json['code'] = '1'; $json['info'] = '无符合条件的线路订单信息'; $json['list'] = array(); return $json; } //处理得到今日车次信息 $sql2 = "SELECT 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 FROM order_main a,run_bus b, opera_line c,run_main d WHERE a.run_id = b.run_id AND a.PARENT_PROD_ID = c.line_id AND b.run_id = d.run_id AND d.prod_id = 0 AND d.run_date = '$start_date' AND c.line_type = 255 AND b.cancel_flag = 0 group by b.bus_order_id 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);"; $bus_info = $this->query($sql2); if (false === $bus_info) { $json['code'] = '1'; $json['info'] = '数据库出错'; $json['list'] = array(); return $json; } //若查询无车次信息 if (count($bus_info) == 0) { //这里如果尚未派车,无车次信息,则返回一个空的bus_info数组 /*$json['code'] = '1'; $json['info'] = '无符合条件的车次信息'; $json['list'] = array(); return $json;*/ $bus_info = array(); } //处理run_bus_id返回值 foreach ($order_info as $k => $v) { if ($v['run_bus_id'] == 0) { $order_info[$k]['run_bus_id'] = ''; } } $json['code'] = '0'; $json['info'] = '返回线路订单信息成功'; $json['list_order'] = $order_info; $json['list_bus'] = $bus_info; return $json; } /** * 获取某一天的组合线路的所有线路的订单统计信息 * 温依莅 * 2016.11.01 * @param $param * start_date(date) 出发日期 * product_type(int) 产品线 --若为'-1'则表示所有 * @return * 成功返回参数 * code(str) * info(str) * total_num(int) 符合条件订单总人数 * list(array): * line_id(int) 订单id * line_name(str) 订单名字 * line_code(str) 订单编码 * num(int) 符合条件该线路订单总人数 */ public function getOrderList($param) { /* start_date:出发日期 product_type:产品线 --若为'-1'则表示所有 */ $start_date = isset($param['start_date']) ? $param['start_date'] : false; $product_type = isset($param['product_type']) ? $param['product_type'] : false; //判断参数是否缺少 if (false === $start_date || false === $product_type || !trim($start_date) || !trim($product_type)) { $json['code'] = '2'; $json['info'] = '缺少必要参数'; return $json; } //判断日期格式正确 $tmp_arr = explode('-', $start_date); $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期 if (!$bool) { $json['code'] = '1'; $json['info'] = '日期格式不正确'; return $json; } //从数据库取得该天组合线路统计信息 //如果是所有产品线 $sql = "SELECT b.line_id,b.line_code,IFNULL(sum(SUBSTRING_INDEX(a.order_description,'|',-1)),0) AS num FROM order_main a RIGHT JOIN opera_line b ON 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) WHERE b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1 AND "; if ($product_type == '-1') { $sql .= "b.product_type IN (select id from dict_type where parent_id=323) GROUP BY b.line_id;"; } else { $sql .= "b.product_type=$product_type GROUP BY b.line_id;"; } $order_info = $this->query($sql); if (false === $order_info) { $json['code'] = '1'; $json['info'] = '数据库错误'; return $json; } //若查询无信息 if (count($order_info) == 0) { $json['code'] = '1'; $json['info'] = '无符合条件的线路信息'; $json['list'] = array(); return $json; } //处理得到符合条件总计数 $total_num = 0; foreach ($order_info as $k => $v) { $total_num += $v['num']; } $json['code'] = '0'; $json['info'] = '返回票种信息成功'; $json['total_num'] = $total_num; $json['list'] = $order_info; return $json; } /** * 获取组合线路接驳段的分车信息 * @param run_date 出发日期 * @param product_id 产品线ID * @param current_page 当前页 * @param page_size 每页显示条数 * @return mixed * User: Steven */ public function getSingleResult($param) { $valid = zzcsUtils::validateParams(array('run_date,product_id,current_page,page_size' => 'empty'), $param); //参数验证 if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } $start_row = ($param['current_page'] - 1) * $param['page_size']; //SQL:查询组合线路中接驳段的分车结果 $sql = "select b.id, (select RES_NAME from base_resource where res_id=b.start_zone_id limit 1) as line_code, b.run_id, -- 班次ID m.run_date, -- 出发日期 b.bus_order_id as run_bus_order_id, -- 车号 (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, -- 指派车型名称 b.SEAT_COUNT AS seat_count, b.SALED_COUNT AS order_cnt, -- 已售座位数 (b.SEAT_COUNT-b.SALED_COUNT) AS remain_cnt, b.SEND_BUS_RES_ID AS send_bus_res_id, -- 实派车辆资源ID b.SEND_BUS_NO AS send_bus_res_name, -- 实派车辆车牌号 b.SEND_BUS_DRIVER_RES_ID AS send_bus_driver_res_id, -- 司机资源ID b.SEND_DRIVER_NAME AS send_driver_name, -- 司机姓名 b.SEND_TOUR_GUIDE_RES_ID AS send_tour_guide_res_id, -- 导游 b.SEND_TOUR_GUIDE_NAME As send_tour_guide_name -- 导游 from run_bus b left join run_main m on b.run_id = m.run_id where m.run_date = '{$param['run_date']}' and b.group_line_flag = 1 and b.cancel_flag = 0 and m.prod_id > 0 and b.run_id in ( 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']}) ) order by b.bus_order_id"; /*$sql = "select distinct s.id as id, -- CONCAT(l.LINE_CODE,' ',l.LINE_NAME) as line_code, (select RES_NAME from base_resource where res_id=s.start_zone_id limit 1) as line_code, b.run_id, -- 班次ID b.run_date, -- 出发日期 b.run_bus_order_id, -- 车号 (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, -- 指派车型名称 s.SEAT_COUNT AS seat_count, s.SALED_COUNT AS order_cnt, -- 已售座位数 (s.SEAT_COUNT-s.SALED_COUNT) AS remain_cnt, s.SEND_BUS_RES_ID AS send_bus_res_id, -- 实派车辆资源ID s.SEND_BUS_NO AS send_bus_res_name, -- 实派车辆车牌号 s.SEND_BUS_DRIVER_RES_ID AS send_bus_driver_res_id, -- 司机资源ID s.SEND_DRIVER_NAME AS send_driver_name, -- 司机姓名 s.SEND_TOUR_GUIDE_RES_ID AS send_tour_guide_res_id, -- 导游 s.SEND_TOUR_GUIDE_NAME As send_tour_guide_name -- 导游 from opera_tickets a, run_bus s,order_main b, opera_line l where a.ticket_id = b.prod_id and s.run_id = b.RUN_ID and s.bus_order_id = b.run_bus_order_id and b.parent_prod_id = l.LINE_ID and l.line_type = 256 and l.cancel_flag =0 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) -- 组合线路 and b.run_date = '{$param['run_date']}' order by b.run_bus_order_id,s.SEAT_COUNT";*/ $sql_query = $sql . " limit $start_row,{$param['page_size']}"; $sql_count = "SELECT COUNT(*) as count from (" . $sql . ") as a"; zzcsUtils::writeLog($sql_query); $res_query = $this->query($sql_query); $res_count = $this->query($sql_count); if (false === $sql_query) { $result['code'] = '1'; $result['info'] = '获取接驳段自动分车结果失败'; return $result; } $total_page = ceil($res_count[0]['count'] / $param['page_size']); $result['code'] = '0'; $result['info'] = '获取接驳段自动分车结果成功'; $result['data'] = $res_query; $result['page'] = array( 'page_size' => $param['page_size'], 'current_page' => $param['current_page'], 'total_count' => $res_count[0]['count'], 'total_page' => $total_page ); return $result; } /** * 获取组合线路直通段分车的结果 * @param run_date 出发日期 * @param product_id 产品线ID * @param current_page 当前页 * @param page_size 每页显示条数 * @return mixed * User: Steven */ public function getDispatchResult($param) { $valid = zzcsUtils::validateParams(array('run_date,product_id,current_page,page_size' => 'empty'), $param); //参数验证 if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } $start_row = ($param['current_page'] - 1) * $param['page_size']; //SQL:查询组合线路直通段的分车后的结果 $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, 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 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 from run_main m,run_bus s 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 left join (select distinct a.parent_order_id, b.parent_prod_id,b.line_code, b.order_cnt, a.run_id,a.run_bus_order_id from order_main a, (select order_id,parent_prod_id,l.line_code,l.line_name, substring_index(order_description,'|',-1) as order_cnt from order_main m,opera_line l 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 where a.parent_order_id = b.order_id and a.run_date = '{$param['run_date']}' and a.cancel_flag = 0 and a.order_valid_status = 1 and a.parent_prod_id not in (select line_id from opera_line where line_type = 256 and cancel_flag = 0) ) t on r.run_id = t.run_id and r.bus_order_id = t.run_bus_order_id group by r.run_id, r.bus_order_id, r.seat_count"; //SQL:查询组合线路直通段的分车结果包括分页 $sql_query = $sql . " LIMIT $start_row,{$param['page_size']}"; $sql_count = "SELECT COUNT(*) as count from (" . $sql . ") as a"; zzcsUtils::writeLog($sql_query); $res_query = $this->query($sql_query); $res_count = $this->query($sql_count); if (false === $sql_query) { $result['code'] = '1'; $result['info'] = '获取直通段自动分车结果失败'; return $result; } $total_page = ceil($res_count[0]['count'] / $param['page_size']); $result['code'] = '0'; $result['info'] = '获取直通段自动分车结果成功'; $result['data'] = $res_query; $result['page'] = array( 'page_size' => $param['page_size'], 'current_page' => $param['current_page'], 'total_count' => $res_count[0]['count'], 'total_page' => $total_page ); return $result; } /** * 组合线路车辆调度算法 * @param run_date 出发日期 * @param product_id 产品线ID * @return mixed * User: Steven */ public function dispatch($param) { $user_id = $this->user_id; $valid = zzcsUtils::validateParams(array('run_date,product_id' => 'empty'), $param); //参数验证 if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } //接驳段的分车算法 并返回被占用的车辆信息 $sql_jiebo = "CALL sp_bus_dispatch_for_group_line($user_id,'{$param['run_date']}',{$param['product_id']})"; zzcsUtils::writeLog($sql_jiebo); $res_jiebo = $this->procQuery($sql_jiebo); if ($res_jiebo['code'] != 0) { //存储过程执行出错 $json["code"] = (string)$res_jiebo['code']; $json["info"] = $res_jiebo['info']; return $json; } $car_list1 = $res_jiebo['data'][0]; //得到接驳段的车辆信息列表 //TODO:进行组合线路直通段的分车 //sql:获取需要加入分车算法的订单信息 $sql_zhitong = "CALL SP_GET_LINE_GROUP_DISTRIB_RULE('{$param['run_date']}',{$param['product_id']})"; zzcsUtils::writeLog($sql_zhitong); $res = $this->procQuery($sql_zhitong); if ($res['code'] != 0) { $json['code'] = '1'; $json['info'] = '订单数据获取失败'; return $json; } #region TODO: 以下是组合线路分车算法 $Ta = array(); $Tb = array(); $Tc = array(); $Te = array(); $Za = array(); $Zb = array(); $Zc = array(); $Ze = array(); $Taeab = array(); $Tbcbe = array(); if ($res['data'][0]) { foreach ($res['data'][0] as $k => $v) { $order = array( 'order_number' => $v['parent_order_id'], // 组合订单ID 'sub_order_id' => $v['sub_order_id'], //单一线路ID 'passenger_number' => $v['order_cnt'], //订单中的人数 'superior_hotel' => $v['start_res_id'], //上车站点ID(酒店ID) 'superior_product' => $v['sub_line_id'], //组合线路ID A+B+E(两天) 第一天A+B该字段显示的是A+B线路的ID 'group_line_id' => $v['group_line_id'], //组合线路ID 'start_time' => $v['start_time'] //发车时间 ); switch ($v['sub_line_id']) { case ZA: //纯玩产品a $Ta对应ZA $Ta['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case ZB: $Tb['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case ZC: $Tc['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case ZE: $Te['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case TA: $Za['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case TB: $Zb['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case TC: $Zc['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case TE: $Ze['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; //纯玩产品aeab 包含A+B|A+E|A+E+B(两日) case ZAB : case ZAE: case ZAEB: $Taeab['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; case ZBC: case ZBE: $Tbcbe['hotel_list'][$v['start_res_id']]['order_list'][] = $order; break; } } } $dispatch = new dispatchAlgorithm(); #region 车次库存列表 $bus_stock = array(); $bus_detail = array(); //sql:查询所有可用的车次列表 $run_date = $param['run_date']; $sql_enable_car = $this->getEnableCar($run_date); //获取当前可用的车次 $car_list2 = $this->query($sql_enable_car); if ($car_list2) { #region 将接驳段的车运用到直通段的派车中 $car_list = array_merge($car_list1, $car_list2); usort($car_list, function ($a, $b) { $car_list = ($b['seat_count'] - $a['seat_count']); return $car_list != 0 ? $car_list : ($a['sort_id'] - $b['sort_id']); }); #endregion foreach ($car_list as $k1 => $v1) { $bus_stock[$k1] = $v1['seat_count']; $bus_detail[$k1] = array( 0 => $v1['seat_count'], 1 => $v1['bus_id'], 2 => $v1['brand_id'], 3 => $v1['bus_type_res_id'] ); } } #endregion $temp_order_pool = array(); $white_bus_pool = array(); $Te_black_order_pool = array();// 创建产品Te的黑订单池订单池 $Tb_black_order_pool = array();// 创建产品Tb的黑订单池订单池 $Tc_black_order_pool = array();// 创建产品Tc的黑订单池订单池 $Ta_black_order_pool = array();// 创建产品Ta的黑订单池订单池 $Ze_black_order_pool = array();// 创建产品Ze的黑订单池订单池->购物 $Zb_black_order_pool = array();// 创建产品Zb的黑订单池订单池->购物 $Zc_black_order_pool = array();// 创建产品Zc的黑订单池订单池->购物 $Za_black_order_pool = array();// 创建产品Za的黑订单池订单池->购物 $Taeab_two_scenic_black_order_pool = array();//a+e和a+b单日双景点黑池子 $Tbcbe_two_scenic_black_order_pool = array();//b+c和b+e单日双景点黑池子 /** * 以下是分别派车 */ if (!empty($Ze)) { // 存在Ze产品订单 ZM: for (; ;) { if (!empty($Ze['hotel_list'])) { sort($Ze['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Ze['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Ze['hotel_list']["0"]["order_list"][$i]; } array_splice($Ze['hotel_list'], 0, 1); if (!empty($Ze['hotel_list'])) { goto ZM; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Ze_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Ze_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Ze['hotel_list'])) { break; } } } if (!empty($Zb)) { // 存在Zb产品订单 ZQ: for (; ;) { if (!empty($Zb['hotel_list'])) { sort($Zb['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Zb['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Zb['hotel_list']["0"]["order_list"][$i]; } array_splice($Zb['hotel_list'], 0, 1); if (!empty($Zb['hotel_list'])) { goto ZQ; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Zb_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Zb_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Zb['hotel_list'])) { break; } } } if (!empty($Zc)) { // 存在Zc产品订单 ZC: for (; ;) { if (!empty($Zc['hotel_list'])) { sort($Zc['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Zc['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Zc['hotel_list']["0"]["order_list"][$i]; } array_splice($Zc['hotel_list'], 0, 1); if (!empty($Zc['hotel_list'])) { goto ZC; } } } // 订单池加到满足要求 $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Zc_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Zc_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Zc['hotel_list'])) { break; } } } if (!empty($Za)) { // 存在Za产品订单 ZA: for (; ;) { if (!empty($Za['hotel_list'])) { sort($Za['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Za['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Za['hotel_list']["0"]["order_list"][$i]; } array_splice($Za['hotel_list'], 0, 1); if (!empty($Za['hotel_list'])) { goto ZA; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Za_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Za_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Za['hotel_list'])) { break; } } } $Min_bus_seat_number = 30; $Z_b_c_black_pool = $dispatch->merge_black_pool($Zb_black_order_pool, $Zc_black_order_pool); while (true) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); 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) { break; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($Z_b_c_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_b_c_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_b_c_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $Z_b_c_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } $Z_a_e_black_pool = $dispatch->merge_black_pool($Za_black_order_pool, $Ze_black_order_pool); while (true) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); 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) { break; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($Z_a_e_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_a_e_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_a_e_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $Z_a_e_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } $Z_all_black_pool = $dispatch->merge_black_pool($Z_a_e_black_pool, $Z_b_c_black_pool); while ($dispatch->pool_count_people_number($Z_all_black_pool) != 0) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($Z_all_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_all_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $Z_all_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $Z_all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } if (!empty($Te)) { // 存在Te产品订单 M: for (; ;) { if (!empty($Te['hotel_list'])) { sort($Te['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Te['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Te['hotel_list']["0"]["order_list"][$i]; } array_splice($Te['hotel_list'], 0, 1); if (!empty($Te['hotel_list'])) { goto M; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Te_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Te_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Te['hotel_list'])) { break; } } } if (!empty($Tb)) { // 存在Tb产品订单 N: for (; ;) { if (!empty($Tb['hotel_list'])) { sort($Tb['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Tb['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Tb['hotel_list']["0"]["order_list"][$i]; } array_splice($Tb['hotel_list'], 0, 1); if (!empty($Tb['hotel_list'])) { goto N; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tb_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Tb_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Tb['hotel_list'])) { break; } } } if (!empty($Tc)) { // 存在Tc产品订单 Q: for (; ;) { if (!empty($Tc['hotel_list'])) { sort($Tc['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Tc['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Tc['hotel_list']["0"]["order_list"][$i]; } array_splice($Tc['hotel_list'], 0, 1); if (!empty($Tc['hotel_list'])) { goto Q; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tc_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Tc_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Tc['hotel_list'])) { break; } } } if (!empty($Ta)) { // 存在Ta产品订单 E: for (; ;) { if (!empty($Ta['hotel_list'])) { sort($Ta['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Ta['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Ta['hotel_list']["0"]["order_list"][$i]; } array_splice($Ta['hotel_list'], 0, 1); if (!empty($Ta['hotel_list'])) { goto E; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Ta_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Ta_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Ta['hotel_list'])) { break; } } } $Min_bus_seat_number = 30; $b_c_black_pool = $dispatch->merge_black_pool($Tb_black_order_pool, $Tc_black_order_pool); while (true) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); 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) { break; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($b_c_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $b_c_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $b_c_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $b_c_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } $a_e_black_pool = $dispatch->merge_black_pool($Ta_black_order_pool, $Te_black_order_pool); while (true) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $stock_change_style = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); 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) { break; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($a_e_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $a_e_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $a_e_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $a_e_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } $all_black_pool = $dispatch->merge_black_pool($a_e_black_pool, $b_c_black_pool);// 得到ae的合并拼车pool while ($dispatch->pool_count_people_number($all_black_pool) != 0) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $attendance_arr = array();//判断筛选最优上座率 for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($all_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"];// 记录每种车型的上座率 } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $optimal_answer = array(); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $optimal_bus_and_pool_answer = array(); if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $all_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $all_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } if (!empty($Taeab)) { // 存在$Taeab产品订单 P: for (; ;) { if (!empty($Taeab['hotel_list'])) { sort($Taeab['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Taeab['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Taeab['hotel_list']["0"]["order_list"][$i]; } array_splice($Taeab['hotel_list'], 0, 1); if (!empty($Taeab['hotel_list'])) { goto P; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Taeab_two_scenic_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Taeab_two_scenic_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Taeab['hotel_list'])) { break; } } } if (!empty($Tbcbe)) { // 存在$Tbcbe产品订单 O: for (; ;) { if (!empty($Tbcbe['hotel_list'])) { sort($Tbcbe['hotel_list']); $tt_people = 0; for ($temp_peo_i = 0; $temp_peo_i < count($temp_order_pool); $temp_peo_i++) { if (isset($temp_order_pool[$temp_peo_i]["passenger_number"])) { $tt_people = $tt_people + $temp_order_pool[$temp_peo_i]["passenger_number"]; } } if ($tt_people < $bus_stock["0"]) { for ($i = 0; $i < count($Tbcbe['hotel_list']["0"]["order_list"]); $i++) { $temp_order_pool[] = $Tbcbe['hotel_list']["0"]["order_list"][$i]; } array_splice($Tbcbe['hotel_list'], 0, 1); if (!empty($Tbcbe['hotel_list'])) { goto O; } } } $orders = $dispatch->change_data_type($temp_order_pool); if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $answer = $dispatch->dp($orders, $bus_stock["0"]); if ($answer["achieved_attendance"] < 0.9) { $temp_pool_answe = $dispatch->path_to_update_temp_and_black_pool($answer, $temp_order_pool, $Tbcbe_two_scenic_black_order_pool); $temp_order_pool = $temp_pool_answe["temp_order_pool"]; $Tbcbe_two_scenic_black_order_pool = $temp_pool_answe["black_order_pool"]; } else { $temp_bus_and_pool_answer = $dispatch->path_to_update_temp_order_and_aboard($answer, $temp_order_pool, $bus_stock); $white_bus_pool[] = $temp_bus_and_pool_answer["bus"]; $temp_order_pool = $temp_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $temp_bus_and_pool_answer["bus_stock"]; } if (empty($temp_order_pool) && empty($Tbcbe['hotel_list'])) { break; } } } $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 while ($dispatch->pool_count_people_number($two_scenic_all_black_pool) != 0) { if (empty($bus_stock)) { $result['code'] = '1'; $result['info'] = '车辆库存不足,无法自动派车!'; return $result; } $attendance_arr = array(); for ($temp_ii = 0; $temp_ii < count($dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number)); $temp_ii++) { $orders = $dispatch->change_data_type($two_scenic_all_black_pool); $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); $temp_answer = $dispatch->dp($orders, $temp_data[$temp_ii]["bus_seat_number"]); $attendance_arr[$temp_ii] = $temp_answer["achieved_attendance"]; } $existence_best = 0; $best_attendance = 0; $best_attendance_jj = 0; $Max_attendance = 0; $Max_attendance_jj = 0; for ($temp_jj = 0; $temp_jj < count($attendance_arr); $temp_jj++) { 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))) { if ($existence_best == 1) { if ($temp_data[$temp_jj]["bus_seat_number"] < $temp_data[$best_attendance_jj]["bus_seat_number"]) { $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } else { $existence_best = 1; $best_attendance = $attendance_arr[$temp_jj]; $best_attendance_jj = $temp_jj; } } if ($attendance_arr[$temp_jj] > $Max_attendance) { $Max_attendance = $attendance_arr[$temp_jj]; $Max_attendance_jj = $temp_jj; } } $temp_data = $dispatch->bus_stock_change_style($bus_stock, $Min_bus_seat_number); if ($existence_best) { $optimal_answer = $dispatch->dp($orders, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_answer = $dispatch->dp($orders, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } if ($existence_best) { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $two_scenic_all_black_pool, $bus_stock, $temp_data[$best_attendance_jj]["bus_seat_number"]); } else { $optimal_bus_and_pool_answer = $dispatch->path_to_update_mix_order_and_aboard($optimal_answer, $two_scenic_all_black_pool, $bus_stock, $temp_data[$Max_attendance_jj]["bus_seat_number"]); } $white_bus_pool[] = $optimal_bus_and_pool_answer["bus"]; $two_scenic_all_black_pool = $optimal_bus_and_pool_answer["temp_order_pool"]; $bus_stock = $optimal_bus_and_pool_answer["bus_stock"]; } $sql_dispatch = ''; $final_info = array(); foreach ($white_bus_pool as $temp11) { foreach ($bus_detail as $k => $detail) { if ($temp11['bus_seat_number'] == $detail[0]) { $temp11['info'] = $detail; $final_info[] = $temp11; unset($bus_detail[$k]); break; } } } #endregion $bus_order_id = 1; //初始化车次编号 //SQL:查询order_main中有没有当前的班次,如果有,说明不是第一次点击分成 $sql_exist = "select run_id from run_main where RUN_DATE='{$param['run_date']}' AND PROD_ID=0 LIMIT 1"; $res_exist = $this->query($sql_exist); if ($res_exist) {//如果是今天的第二次或者多次点击自动分车 更新run_bus #----以下---这里要对已分车的订单做处理,否则形如z(j)这样的线路订单在二次分车时会出现错误,因为它不在分车算法内,所以仅用覆盖的方法会漏掉。---温依莅 //首先得到分车算法覆盖的订单,和今日的订单做比对 #分车算法已分的子订单集合 $str_order_id = ''; foreach ($final_info as $k => $v) { //$k:派了第几辆车 $sub_order_id = ''; foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息 $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表 } $str_order_id .= $sub_order_id; } $after_order_arr = explode(',', trim($str_order_id, ',')); #今日所有应分配的子订单集合 $all_sub_order_id = ''; foreach ($res['data'][0] as $k2 => $v2) { //$k:派了第几辆车 $all_sub_order_id .= $v2['sub_order_id'] . ','; //单一线路订单ID列表 } $all_str_order_id = substr($all_sub_order_id, 0, -1); $all_order_arr = explode(',', $all_str_order_id); //作比较得到未参与分车的订单集合 $diff_arr = array_diff($all_order_arr, $after_order_arr); $diff_str = implode(',', $diff_arr); //如果非空则设置run_bus_order_id为0 if (!empty($diff_arr)) { $sql = "update order_main set run_bus_order_id=0 where order_id in ($diff_str);"; zzcsUtils::writeLog($sql); $tmres = $this->exec($sql); if (false === $tmres) { $result['code'] = '5'; $result['info'] = '重置部分订单失败'; return $result; } } #----以上----# //SQL:获取当前已经存在的所有车次 $sql_bus_order_id = "select bus_order_id from run_bus where run_id={$res_exist[0]['run_id']} AND CANCEL_FLAG=0"; $res_bus_order_id = $this->query($sql_bus_order_id); $arr_bus_order_id = array(); foreach ($res_bus_order_id as $bus_id) { $arr_bus_order_id[] = $bus_id['bus_order_id']; } //$sql_dispatch .= "delete from run_bus WHERE run_id={$res_exist[0]['run_id']};"; foreach ($final_info as $k => $v) { //$k:派了第几辆车 $seat_type = $v['bus_seat_number'];//车辆座位类型 $seated_count = $v["already_seat_number"]; //已经入坐的人数 $brand_id = $v['info'][2]; //车辆品牌ID info[0]:seat_count;info[1]:bus_id ;info[2]:brand_id if (in_array($bus_order_id, $arr_bus_order_id)) { //当前车次号已经存在,不需要在run_bus中添加,更新就可以了 $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}, 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};"; foreach ($arr_bus_order_id as $bus_k => $bus_v) { if ($bus_v == $bus_order_id) { unset($arr_bus_order_id[$bus_k]); } } } else { $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, 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});"; } $sub_order_id = ''; foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息 $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表 } $str_order_id = substr($sub_order_id, 0, -1); $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);"; $bus_order_id++; } $arr_bus_order_id; if (!empty($arr_bus_order_id)) { //TODO:多次点击派车时,需要将之前派出的车次但是本次并没有用到的车的cancel_flag置为1 $cancel_bus_id = ''; foreach ($arr_bus_order_id as $v_bus) { $cancel_bus_id .= $v_bus . ','; } $cancel_bus_id = substr($cancel_bus_id, 0, -1); $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);"; } } else {//第一次点击自动分车 $sql_get_run_id = "SELECT FUNC_GET_UNIQUE_ID(3,1) as run_id"; //生成新的run_id $res_run_id = $this->query($sql_get_run_id); //得到run_id $start_time = ''; foreach ($final_info as $k => $v) { //$k:派了第几辆车 $seat_type = $v['bus_seat_number'];//车辆座位类型 $seated_count = $v["already_seat_number"]; //已经入坐的人数 $brand_id = $v['info'][2]; //车辆品牌ID info[0]:seat_count;info[1]:bus_id ;info[2]:brand_id $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});"; $sub_order_id = ''; foreach ($v['order_list'] as $k1 => $v1) { // $v1: 订单信息 $sub_order_id .= $v1['sub_order_id'] . ','; //单一线路订单ID列表 } $start_time = $v['order_list'][0]['start_time']; $str_order_id = substr($sub_order_id, 0, -1); $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);"; $bus_order_id++; } $time = explode(':', $start_time); $run_minutes = $time[0] * 60 + $time[1]; $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);"; $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 FROM opera_line AS l, opera_station AS s WHERE l.line_id = s.line_id AND l.cancel_flag = 0 AND s.cancel_flag = 0 AND l.line_id =451483";//土楼专线岛外上车(Z00): waice(450890) -> ctsdata(451483) $res_station = $this->query($sql); foreach ($res_station as $k_s => $v_s) { $start_minutes = $run_minutes + $v_s['start_minutes']; $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) 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']});"; } } //将分车后的结果反应到相应的表中 zzcsUtils::writeLog($sql_dispatch); $res_exec = $this->exec($sql_dispatch); if (!$res_exec) { $result['code'] = '1'; $result['info'] = '自动分车执行失败'; return $result; } $result['code'] = '0'; $result['info'] = '自动分车执行成功';; return $result; } /* * wangxj * 组合线路+车,影响run_bus表 * @run_id 班次ID * */ public function addBus($params) { $user_id = $this->user_id; $valid = zzcsUtils::validateParams(array( 'run_date' => 'empty' )); if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } $run_date = $params['run_date']; //$sql = "select bus_id,brand_id,seat_count from base_bus WHERE BUS_STATE=336 ORDER BY seat_count DESC LIMIT 1"; $sql = $this->getEnableCar($run_date); //获取当前可用的车次 $res = $this->query($sql); if ($res) { $seat_count = $res[0]['seat_count']; $bus_type_res_id = $res[0]['bus_type_res_id']; $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"; $run_bus = $this->query($sql); if ($run_bus) { $bus_order_id = $run_bus[0]['BUS_ORDER_ID'] + 1; $run_id = $run_bus[0]['run_id']; $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)" . "VALUES( $user_id, now(), $user_id, now(), $run_id, $bus_order_id, 0, $seat_count, 0,138, $bus_type_res_id)"; $result = $this->insert($sql); if ($result === false) { $json["code"] = "1"; $json["info"] = "加车失败!"; return $json; } else { $json["code"] = "0"; $json["info"] = "加车成功!"; return $json; } } else { $json["code"] = "1"; $json["info"] = "加车失败!"; return $json; } } else { $result['code'] = '1'; $result['info'] = '车辆库存不足!'; return $result; } } /* * wangxj * 组合线路减车,影响run_bus表 * @run_date 日期 * @bus_order_id 序号 * */ public function delBus($params) { $user_id = $this->user_id; $valid = zzcsUtils::validateParams(array( 'run_date,bus_order_id' => 'empty', )); if (!$valid['status']) { $result['code'] = (string)$valid['status']; $result['info'] = $valid['info']; return $result; } $run_date = $params['run_date']; $bus_order_id = $params['bus_order_id']; $sql = "select id, b.SALED_COUNT SALED_COUNT from run_bus b right JOIN run_main m on m.run_id = b.run_id " . "where m.run_date='$run_date' and m.prod_id=0 and b.bus_order_id in ($bus_order_id) "; $res = $this->query($sql); if ($res) { if ($res[0]['SALED_COUNT'] == 0) { $id = $res[0]['id']; $sql = "update run_bus b set cancel_flag = 1, update_user_id=$user_id and update_time=now() where id=$id"; $result = $this->exec($sql); zzcsUtils::writeLog($sql); if ($result === false) { $json["code"] = "1"; $json["info"] = "减车失败!"; return $json; } else { $json["code"] = "0"; $json["info"] = "减车成功!"; return $json; } } else { $json["code"] = "1"; $json["info"] = "座位没有清空,无法减车!"; return $json; } } else { $result['code'] = '1'; $result['info'] = '无法减车!'; return $result; } } /** * 组合线路获取可用车次::这里限制组合线路分车车次仅限佰廉车队 * @param $run_date 日期 * @return $sql * User: Steven */ private function getEnableCar($run_date) { if (date('Y-m-d', strtotime($run_date)) == date('Y-m-d', time())) { //派今天的车 //SQL:查询今日可用车次 $sql = "select bus_id,bus_type_res_id,bus_no, seat_count, brand_id ,2 as sort_id from base_bus where bus_state = 336 and cancel_flag = 0 and org_id=417 and bus_id not in ( select b.send_bus_res_id from run_main m, run_bus b 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) order by seat_count desc;"; } else { //SQL:查询非今日可用车次 $sql = "select bus_id,bus_type_res_id,bus_no, seat_count, brand_id,2 as sort_id from base_bus a where a.bus_state = 336 and a.cancel_flag = 0 and a.org_id=417 and a.bus_id not in ( select b.send_bus_res_id from run_main m, run_bus b, run_station s 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 group by m.run_id,b.send_bus_res_id having max(START_MINUTES) > ( select min(prod_start_station_time_minutes) from order_main where parent_order_id = 0 and prod_start_station_date = '{$run_date}' 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)) order by seat_count desc;"; } return $sql; } /** * 组合线路可派车次列表 * @param $param * @return mixed * User: Steven */ public function getVehicleList($param) { #region 获取渠道权限 $user_id = $this->user_id; $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0"; $opera_org_id_result = $this->query($opera_org_id_sql); $opera_org_id = $opera_org_id_result[0]['opera_org_id']; if($opera_org_id == ''){ $and_sql = ''; }else{ $and_sql = " and org_id in (" . $opera_org_id . ") "; } #endregion $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''"; $company = isset($param['company']) ? (empty($param['company']) ? "0" : $param['company']) : "0"; $salecount = isset($param['salecount']) ? (empty($param['salecount']) ? "0" : $param['salecount']) : "0"; $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : ""; //$run_time = isset($param['run_time']) ? (empty($param['run_time']) ? "" : $param['run_time']) : ""; $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : ''; $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : ''; if ($run_id1 == '' || $run_id2 == '') { $sql = "select bus_id as res_id,bus_no as vihicle_number, 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, 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 from base_bus where cancel_flag = 0 and bus_state = 336 and bus_id not in ( select ifnull(b.send_bus_res_id,0) as send_bus_res_id from run_main m, run_station s ,run_bus b where m.run_id = s.run_id and m.run_id = b.run_id and m.run_date = '{$run_date}' and m.prod_id > 0 -- 单一线路 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 ) and b.send_bus_res_id > 0 and b.cancel_flag = 0 group by m.run_id,b.bus_order_id having max(s.start_minutes) > (select min(prod_start_station_time_minutes) from order_main where parent_order_id = 0 and prod_start_station_date = '{$run_date}' 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) ) and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%')) " . $and_sql . " and if({$company}<=0,0=0,org_id = {$company}) "; } else { $sql = "select bus_id as res_id,bus_no as vihicle_number, 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, 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 from base_bus where cancel_flag = 0 and bus_state = 336 and bus_id not in ( select ifnull(b.send_bus_res_id,0) as send_bus_res_id from run_main m, run_station s ,run_bus b 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 -- 单一线路 and b.send_bus_res_id > 0 and b.cancel_flag = 0 group by m.run_id,b.bus_order_id having max(s.start_minutes) > (select run_minutes from run_main where run_id = $run_id1) union all select send_bus_res_id from run_bus where run_id = $run_id1) and seat_count >= $salecount " . $and_sql . " and if(length(trim({$keyword}))=0,0=0,bus_no like concat('%',{$keyword},'%')) and if({$company}<=0,0=0,org_id = {$company}) "; } zzcsUtils::writeLog($sql); $result = $this->query($sql); if (false === $result) { $json['code'] = '1'; $json['info'] = '获取可派车次列表失败'; } else { $json['code'] = '0'; $json['info'] = '获取可派车次列表成功'; $json['vehicle_list'] = $result; } return $json; } /** * 组合线路(根据导游姓名手机号和公司)获取可用导游列表 * @param $param * @return mixed * User: Steven */ public function getGuideList($param) { #region 获取渠道权限 $user_id = $this->user_id; $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0"; $opera_org_id_result = $this->query($opera_org_id_sql); $opera_org_id = $opera_org_id_result[0]['opera_org_id']; if($opera_org_id == ''){ $and_sql = ''; }else{ $and_sql = " and org_id in (" . $opera_org_id . ") "; } #endregion $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''"; $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0'; $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : ""; $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : ''; $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : ''; //SQL:获取组合线路可用导游列表(包括接驳段用过的导游) if ($run_id1 == '' || $run_id2 == '') { //初始加载(不传入run_id) $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 from base_guide a where a.cancel_flag = 0 " . $and_sql . " and a.guide_id not in ( select b.send_tour_guide_res_id from run_main m, run_bus b, run_station s 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 group by m.run_id,b.send_tour_guide_res_id having max(START_MINUTES) > ( select min(prod_start_station_time_minutes) from order_main where parent_order_id = 0 and prod_start_station_date = '{$run_date}' 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)) AND IF(length(trim({$keyword}))<=0,0=0,(guide_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%'))) AND IF({$company}<=0,0=0,a.org_id={$company})"; } else { $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 from base_guide a where a.cancel_flag = 0 " . $and_sql . " and a.guide_id not in ( select b.send_tour_guide_res_id from run_main m, run_station s ,run_bus b 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 -- 单一线路 and b.send_tour_guide_res_id > 0 and b.cancel_flag = 0 group by m.run_id,b.bus_order_id having max(s.start_minutes) > (select run_minutes from run_main where run_id = {$run_id1}) union all select send_tour_guide_res_id from run_bus where run_id = {$run_id1}) AND IF(length(trim({$keyword}))<=0,0=0,(guide_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%'))) AND IF({$company}<=0,0=0,org_id={$company})"; } zzcsUtils::writeLog($sql); $result = $this->query($sql); if (false === $result) { $json['code'] = '1'; $json['info'] = '数据库错误'; } else { $json['code'] = '0'; $json['info'] = '返回数据成功'; $json['guide_list'] = $result; } return $json; } /** * 组合线路(根据导游姓名手机号和公司)获取可用司机列表 * @param $param * @return mixed * User: Steven */ public function getDriverList($param) { #region 获取渠道权限 $user_id = $this->user_id; $opera_org_id_sql = "select opera_org_id from base_user where id = " . $user_id . " and cancel_flag = 0"; $opera_org_id_result = $this->query($opera_org_id_sql); $opera_org_id = $opera_org_id_result[0]['opera_org_id']; if($opera_org_id == ''){ $and_sql = ''; }else{ $and_sql = " and org_id in (" . $opera_org_id . ") "; } #endregion $keyword = isset($param['keyword']) ? "'" . $param['keyword'] . "'" : "''"; $company = isset($param['company']) ? (empty($param['company']) ? '0' : $param['company']) : '0'; $run_date = isset($param['run_date']) ? (empty($param['run_date']) ? "" : $param['run_date']) : ""; $run_id1 = isset($param['run_id1']) ? $param['run_id1'] : ''; $run_id2 = isset($param['run_id2']) ? $param['run_id2'] : ''; if ($run_id1 == '' || $run_id2 == '') { //初始加载(不传入run_id) $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 from base_driver a where a.cancel_flag = 0 " . $and_sql . " and a.driver_id not in ( select b.send_bus_driver_res_id from run_main m, run_bus b, run_station s 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 group by m.run_id,b.send_bus_driver_res_id having max(START_MINUTES) > ( select min(prod_start_station_time_minutes) from order_main where parent_order_id = 0 and prod_start_station_date = '{$run_date}' 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)) AND IF(length(trim({$keyword}))<=0,0=0,(driver_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%'))) AND IF({$company}<=0,0=0,a.org_id={$company})"; } else { //点击输入框(传入run_id) $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 from base_driver where cancel_flag = 0 " . $and_sql . " and driver_id not in ( select ifnull(b.send_bus_driver_res_id,0) as send_bus_driver_res_id from run_main m, run_station s ,run_bus b 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 -- 单一线路 and b.send_bus_driver_res_id > 0 and b.cancel_flag = 0 group by m.run_id,b.bus_order_id having max(s.start_minutes) > (select run_minutes from run_main where run_id = {$run_id1}) union all select send_bus_driver_res_id from run_bus where run_id = {$run_id1}) AND IF(length(trim({$keyword}))<=0,0=0,(driver_name LIKE CONCAT('%',{$keyword},'%') OR phone_no LIKE CONCAT('%',{$keyword},'%'))) AND IF({$company}<=0,0=0,org_id={$company});"; } zzcsUtils::writeLog($sql); $result = $this->query($sql); if (false === $result) { $json['code'] = '1'; $json['info'] = '司机列表获取失败'; } else { $json['code'] = '0'; $json['info'] = '司机列表获取成功'; $json['driver_list'] = $result; } return $json; } }