connect('127.0.0.1', 11211); $orderlist = $mem->get("orderList[$runID]"); //将该订单从订单池中移除 if (!$orderlist) { return false; } $current_bus_order_list = $orderlist[$busID]; foreach ($current_bus_order_list as $k => $order) { if ($order["order_id"] == $orderID) { array_splice($current_bus_order_list, $k, 1); if (count($current_bus_order_list) == 0) { unset($orderlist[$busID]); } if (count($orderlist) == 0) { $mem->delete("orderList[$runID]"); $mem->delete("orderPoolStatus[$runID]"); $res = $orderService->makeOrder($mem, $runID, false, $busID, $prodID); return $res; } else { $orderlist[$busID] = $current_bus_order_list; $mem->set("orderList[$runID]", $orderlist); } } } //如果当前订单池已经锁定,将该订单池解除锁定 $PoolStatus = $mem->get("orderPoolStatus[$runID]"); //添加runid标记是为了区别是哪个时间的班次 if ($PoolStatus) { foreach ($PoolStatus as $k => $v) { if ($k == $busID) { if ($v['status'] == 0) { //状态值:0:已锁定;1:未锁定 $PoolStatus[$k]['status'] = 1; $mem->set("orderPoolStatus[$runID]", $PoolStatus); } } } } //重新计算线路,但是此时不用计算冗余时间 $new_order_list = $mem->get("orderList[$runID]"); $current_bus_order_list = $new_order_list[$busID]; if (is_array($current_bus_order_list) && count($current_bus_order_list) == 1) { //退订的订单是该车上的倒数第二个订单 //更新order_main中该车的里面的其他订单的上车时间和下车时间 $time = $orderService->firstOrderNeedTime($current_bus_order_list[0]['startx_y'], $current_bus_order_list[0]['endx_y'], $run_date); $pdo = conn(); $sql = "update order_main set PROD_START_STATION_TIME = '" . $time['result'][0] . "',PROD_END_STATION_TIME = '" . $time['result'][1] . "' where order_id =" . $current_bus_order_list[0]['order_id'] . " or parent_order_id =" . $current_bus_order_list[0]['order_id']; $pdo->exec($sql); $station = $current_bus_order_list[0]['begin_name'] . ";" . $current_bus_order_list[0]['end_name']; $lat_long = $current_bus_order_list[0]['startx_y'] . ";" . $current_bus_order_list[0]['endx_y']; $station_type = "0;1"; $station_time = $time['result'][0] . ";" . $time['result'][1]; $orderId_list = $current_bus_order_list[0]['order_id'] . ";" . $current_bus_order_list[0]['order_id']; $orderService->set_run_station($runID, $busID, $prodID, $orderId_list, $station, $lat_long, $station_type, $station_time);//更新run_bus_station_view表 return true; } if (!is_array($current_bus_order_list)) { //最后的一个订单也移除之后,则不进行更新order_main,直接更新run_bus_station_view表 $orderService->makeOrder($mem, $runID, $current_bus_order_list, $busID, $prodID);//更新run_bus_station_view表 return true; } //取消后剩余的订单数大于二时,执行下面逻辑 $first_order = array_splice($current_bus_order_list, -1, 1); $array_start = $orderService->timeMatrix($current_bus_order_list, $first_order[0]['startx_y'], 1); //获取所有起点时间矩阵 $array_end = $orderService->timeMatrix($current_bus_order_list, $first_order[0]['endx_y'], 2); //获取所有终点时间矩阵 //将剩下的订单重新加入算法进行计算(注意这里不再计算冗余时间) $re_cal_line = new dispatch_algorithm(); $res_time = $re_cal_line->dispatch($prodID, $current_bus_order_list, $first_order[0], $array_start, $array_end, $run_date, false); $this->update_ordermain_time($res_time, $orderService);//更新order_main中该车的里面的其他订单的上车时间和下车时间 //更新run_bus_station_view表 $res = $orderService->makeOrder($mem, $runID, $res_time, $busID, $prodID); return $res; } //更新order_main中该车的里面的其他订单的上车时间和下车时间 function update_ordermain_time($res_time, $orderService) { $start_end_time = array(); foreach ($res_time as $id => $arr) { if (!isset($start_end_time[$arr['order_id']])) { $start_end_time[$arr['order_id']] = array(); $start_end_time[$arr['order_id']]["start_time"] = $arr['time']; } else { $start_end_time[$arr['order_id']]["end_time"] = $arr['time']; $orderService->update_order_time($arr['order_id'], $start_end_time[$arr['order_id']]["start_time"], $arr['time']); } } } }