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.
 
 
 
 
 
 

173 lines
8.1 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/9/20
  6. * Time: 14:20
  7. */
  8. require_once __DIR__ . '/common.php';
  9. class cancelOrder extends virtifyUsers
  10. {
  11. public function cancel_order($runID, $busID, $station_start, $station_end, $orderID, $order_num)
  12. {
  13. //需要将内存中的订单号和乘客人数删除
  14. $mem = new Memcache();
  15. $mem->connect('127.0.0.1', 11211);
  16. $order_list = $mem->get("orderList[$runID]");
  17. //将该订单从订单池中移除
  18. if (!$order_list) {
  19. return false;
  20. }
  21. $current_bus_order_list = $order_list[$busID];
  22. foreach ($current_bus_order_list as $key => $value) {
  23. if ($key == $station_start) { //更新上车点的订单列表和乘客人数
  24. $orderInfo = explode(",", $value);
  25. if ($orderInfo[1] == 0) {
  26. //不存在该订单
  27. //当前站点没有任何订单,所以查不到该订单
  28. $data['code'] = 101;
  29. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  30. $data['info'] = "上车点:当前站点没有任何订单,所以查不到该订单";
  31. return $data;
  32. }
  33. $orderList = explode("|", $orderInfo[1]);
  34. if (count($orderList) == 1) //说明该站点只有当前这一个订单
  35. {
  36. if ($orderList[0] != $orderID) {
  37. $data['code'] = 101;
  38. $data['data']=$orderInfo;
  39. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  40. $data['info'] = "上车点:当前站点只有一个订单,但不包含你要取消的订单";
  41. return $data;
  42. }
  43. $current_bus_order_list[$station_start] = "1,0,0";
  44. } else { //该站点的订单人数大于1
  45. if (!in_array($orderID, $orderList)) {
  46. //不存在该订单
  47. $data['code'] = 101;
  48. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  49. $data['info'] = "上车点:当前站点有多个订单,但不包含你要取消的订单";
  50. return $data;
  51. }
  52. $re_order_list = "";
  53. //将该订单从订单列表中移除
  54. foreach ($orderList as $v) {
  55. if ($v != $orderID) {
  56. $re_order_list .= $v . "|";
  57. }
  58. }
  59. $res = "1," . rtrim($re_order_list, '|') . "," . ($orderInfo[2] - $order_num);
  60. $current_bus_order_list[$station_start] = $res;
  61. }
  62. $bus_list[$busID] = $current_bus_order_list;
  63. $mem->set("orderList[$runID]", $bus_list);
  64. } elseif ($key == $station_end) //更新下车点的订单列表和乘客人数
  65. {
  66. $orderInfo = explode(",", $value);
  67. if ($orderInfo[1] == 0) {
  68. $data['code'] = 101;
  69. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  70. $data['info'] = "下车点:当前站点没有任何订单,所以查不到该订单";
  71. return $data;
  72. }
  73. $orderList = explode("|", $orderInfo[1]);
  74. if (count($orderList) == 1) //说明该站点只有当前这一个订单
  75. {
  76. if ($orderList[0] != $orderID) {
  77. $data['code'] = 101;
  78. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  79. $data['data'] = $orderList[0];
  80. $data['info'] = "下车点:当前站点只有一个订单,但不包含你要取消的订单";
  81. return $data;
  82. }
  83. $current_bus_order_list[$station_end] = "-1,0,0";
  84. } else { //该站点的订单数大于1
  85. if (!in_array($orderID, $orderList)) {
  86. //不存在该订单
  87. $data['code'] = 101;
  88. $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
  89. $data['info'] = "下车点:当前站点有多个订单,但不包含你要取消的订单";
  90. return $data;
  91. }
  92. $re_order_list = "";
  93. //将该订单从订单列表中移除
  94. foreach ($orderList as $v) {
  95. if ($v != $orderID) {
  96. $re_order_list .= $v . "|";
  97. }
  98. }
  99. $res = "-1," . rtrim($re_order_list, '|') . "," . 0;
  100. $current_bus_order_list[$station_end] = $res;
  101. }
  102. $bus_list[$busID] = $current_bus_order_list;
  103. $mem->set("orderList[$runID]", $bus_list);
  104. } else {
  105. }
  106. }
  107. //将表run_bus_station_view中的订单信息删除
  108. $dt_order_list_start = ""; //上车站修改后的订单列表拼接字符串
  109. $dt_order_list_end = "";//下车站修改后的订单列表拼接字符串
  110. $total_order_list = ""; //总的站点订单列表
  111. $pdo = conn();
  112. $sql = "select order_id from run_bus_station_view where run_id=" . $runID . " AND bus_no=" . $busID;
  113. $result = $pdo->query($sql);
  114. $row = $result->fetchAll(PDO::FETCH_ASSOC);
  115. if (isset($row[0]['order_id'])) {
  116. $data_order_list = $row[0]['order_id'];
  117. $arr_order_list = explode(";", $data_order_list);
  118. $arr_start = explode("|", $arr_order_list[$station_start]);
  119. foreach ($arr_start as $v) {
  120. if ($v != $orderID) {
  121. $dt_order_list_start .= $v . "|";
  122. }
  123. }
  124. $dt_order_list_start = rtrim($dt_order_list_start, '|');
  125. if ($dt_order_list_start == "") //取消该订单后该站点无其他订单,将此处置为0
  126. {
  127. $dt_order_list_start = 0;
  128. }
  129. $arr_order_list[$station_start] = $dt_order_list_start;
  130. $arr_end = explode("|", $arr_order_list[$station_end]);
  131. foreach ($arr_end as $v) {
  132. if ($v != $orderID) {
  133. $dt_order_list_end .= $v . "|";
  134. }
  135. }
  136. $dt_order_list_end = rtrim($dt_order_list_end, '|');
  137. if ($dt_order_list_end == "") {
  138. $dt_order_list_end = 0;
  139. }
  140. $arr_order_list[$station_end] = $dt_order_list_end;
  141. foreach ($arr_order_list as $v) {
  142. $total_order_list .= $v . ";";
  143. }
  144. $total_order_list = rtrim($total_order_list, ";"); //将最后一个‘;’移除
  145. $sql1 = "update run_bus_station_view set order_id='{$total_order_list}',update_time=NOW() where RUN_ID=$runID and bus_no=$busID";
  146. $result = $pdo->query($sql1);
  147. if (!$result) {
  148. $data['code'] = 102;
  149. $data['info'] = "更新run_bus_station_view失败:" . $sql1;
  150. return $data;
  151. } else {
  152. $data['code'] = 0;
  153. $data['info'] = "取消成功" . $sql1;
  154. return $data;
  155. }
  156. } else {
  157. $data['code'] = 103;
  158. $data['info'] = "查询失败:" . $sql;
  159. return $data;
  160. }
  161. }
  162. }
  163. /*$qa = new cancelOrder();
  164. //$qa->cancel_order(612102, 1, $station_start, $station_end, $orderID = "", $order_num);
  165. $qa->cancel_order(612102, 1, 3, 6, 111111, 1);*/