Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

105 wiersze
5.5 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/9/8
  6. * Time: 19:21
  7. */
  8. require_once __DIR__ . '/common.php';
  9. class cancelOrder extends virtifyUsers
  10. {
  11. function funCancelOrder($prodID, $runID, $busID, $orderID, $run_date)
  12. {
  13. //return $prodID."||" .$runID."||". $busID."||". $orderID."||". $run_date;
  14. $orderService = new createOrderService();
  15. $mem = new Memcache();
  16. $mem->connect('127.0.0.1', 11211);
  17. $orderlist = $mem->get("orderList[$runID]");
  18. //将该订单从订单池中移除
  19. if (!$orderlist) {
  20. return false;
  21. }
  22. $current_bus_order_list = $orderlist[$busID];
  23. foreach ($current_bus_order_list as $k => $order) {
  24. if ($order["order_id"] == $orderID) {
  25. array_splice($current_bus_order_list, $k, 1);
  26. if (count($current_bus_order_list) == 0) {
  27. unset($orderlist[$busID]);
  28. }
  29. if (count($orderlist) == 0) {
  30. $mem->delete("orderList[$runID]");
  31. $mem->delete("orderPoolStatus[$runID]");
  32. $res = $orderService->makeOrder($mem, $runID, false, $busID, $prodID);
  33. return $res;
  34. } else {
  35. $orderlist[$busID] = $current_bus_order_list;
  36. $mem->set("orderList[$runID]", $orderlist);
  37. }
  38. }
  39. }
  40. //如果当前订单池已经锁定,将该订单池解除锁定
  41. $PoolStatus = $mem->get("orderPoolStatus[$runID]"); //添加runid标记是为了区别是哪个时间的班次
  42. if ($PoolStatus) {
  43. foreach ($PoolStatus as $k => $v) {
  44. if ($k == $busID) {
  45. if ($v['status'] == 0) { //状态值:0:已锁定;1:未锁定
  46. $PoolStatus[$k]['status'] = 1;
  47. $mem->set("orderPoolStatus[$runID]", $PoolStatus);
  48. }
  49. }
  50. }
  51. }
  52. //重新计算线路,但是此时不用计算冗余时间
  53. $new_order_list = $mem->get("orderList[$runID]");
  54. $current_bus_order_list = $new_order_list[$busID];
  55. if (is_array($current_bus_order_list) && count($current_bus_order_list) == 1) { //退订的订单是该车上的倒数第二个订单
  56. //更新order_main中该车的里面的其他订单的上车时间和下车时间
  57. $time = $orderService->firstOrderNeedTime($current_bus_order_list[0]['startx_y'], $current_bus_order_list[0]['endx_y'], $run_date);
  58. $pdo = conn();
  59. $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'];
  60. $pdo->exec($sql);
  61. $station = $current_bus_order_list[0]['begin_name'] . ";" . $current_bus_order_list[0]['end_name'];
  62. $lat_long = $current_bus_order_list[0]['startx_y'] . ";" . $current_bus_order_list[0]['endx_y'];
  63. $station_type = "0;1";
  64. $station_time = $time['result'][0] . ";" . $time['result'][1];
  65. $orderId_list = $current_bus_order_list[0]['order_id'] . ";" . $current_bus_order_list[0]['order_id'];
  66. $orderService->set_run_station($runID, $busID, $prodID, $orderId_list, $station, $lat_long, $station_type, $station_time);//更新run_bus_station_view表
  67. return true;
  68. }
  69. if (!is_array($current_bus_order_list)) { //最后的一个订单也移除之后,则不进行更新order_main,直接更新run_bus_station_view表
  70. $orderService->makeOrder($mem, $runID, $current_bus_order_list, $busID, $prodID);//更新run_bus_station_view表
  71. return true;
  72. }
  73. //取消后剩余的订单数大于二时,执行下面逻辑
  74. $first_order = array_splice($current_bus_order_list, -1, 1);
  75. $array_start = $orderService->timeMatrix($current_bus_order_list, $first_order[0]['startx_y'], 1); //获取所有起点时间矩阵
  76. $array_end = $orderService->timeMatrix($current_bus_order_list, $first_order[0]['endx_y'], 2); //获取所有终点时间矩阵
  77. //将剩下的订单重新加入算法进行计算(注意这里不再计算冗余时间)
  78. $re_cal_line = new dispatch_algorithm();
  79. $res_time = $re_cal_line->dispatch($prodID, $current_bus_order_list, $first_order[0], $array_start, $array_end, $run_date, false);
  80. $this->update_ordermain_time($res_time, $orderService);//更新order_main中该车的里面的其他订单的上车时间和下车时间
  81. //更新run_bus_station_view表
  82. $res = $orderService->makeOrder($mem, $runID, $res_time, $busID, $prodID);
  83. return $res;
  84. }
  85. //更新order_main中该车的里面的其他订单的上车时间和下车时间
  86. function update_ordermain_time($res_time, $orderService)
  87. {
  88. $start_end_time = array();
  89. foreach ($res_time as $id => $arr) {
  90. if (!isset($start_end_time[$arr['order_id']])) {
  91. $start_end_time[$arr['order_id']] = array();
  92. $start_end_time[$arr['order_id']]["start_time"] = $arr['time'];
  93. } else {
  94. $start_end_time[$arr['order_id']]["end_time"] = $arr['time'];
  95. $orderService->update_order_time($arr['order_id'], $start_end_time[$arr['order_id']]["start_time"], $arr['time']);
  96. }
  97. }
  98. }
  99. }