|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/9/20
- * Time: 14:20
- */
-
- require_once __DIR__ . '/common.php';
-
- class cancelOrder extends virtifyUsers
- {
- public function cancel_order($runID, $busID, $station_start, $station_end, $orderID, $order_num)
- {
- //需要将内存中的订单号和乘客人数删除
- $mem = new Memcache();
- $mem->connect('127.0.0.1', 11211);
- $order_list = $mem->get("orderList[$runID]");
- //将该订单从订单池中移除
- if (!$order_list) {
- return false;
- }
- $current_bus_order_list = $order_list[$busID];
- foreach ($current_bus_order_list as $key => $value) {
- if ($key == $station_start) { //更新上车点的订单列表和乘客人数
- $orderInfo = explode(",", $value);
- if ($orderInfo[1] == 0) {
- //不存在该订单
- //当前站点没有任何订单,所以查不到该订单
- $data['code'] = 101;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['info'] = "上车点:当前站点没有任何订单,所以查不到该订单";
- return $data;
- }
- $orderList = explode("|", $orderInfo[1]);
- if (count($orderList) == 1) //说明该站点只有当前这一个订单
- {
- if ($orderList[0] != $orderID) {
- $data['code'] = 101;
- $data['data']=$orderInfo;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['info'] = "上车点:当前站点只有一个订单,但不包含你要取消的订单";
- return $data;
- }
- $current_bus_order_list[$station_start] = "1,0,0";
- } else { //该站点的订单人数大于1
- if (!in_array($orderID, $orderList)) {
- //不存在该订单
- $data['code'] = 101;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['info'] = "上车点:当前站点有多个订单,但不包含你要取消的订单";
- return $data;
- }
- $re_order_list = "";
- //将该订单从订单列表中移除
- foreach ($orderList as $v) {
- if ($v != $orderID) {
- $re_order_list .= $v . "|";
- }
- }
- $res = "1," . rtrim($re_order_list, '|') . "," . ($orderInfo[2] - $order_num);
- $current_bus_order_list[$station_start] = $res;
- }
- $bus_list[$busID] = $current_bus_order_list;
- $mem->set("orderList[$runID]", $bus_list);
- } elseif ($key == $station_end) //更新下车点的订单列表和乘客人数
- {
- $orderInfo = explode(",", $value);
- if ($orderInfo[1] == 0) {
- $data['code'] = 101;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['info'] = "下车点:当前站点没有任何订单,所以查不到该订单";
- return $data;
- }
- $orderList = explode("|", $orderInfo[1]);
- if (count($orderList) == 1) //说明该站点只有当前这一个订单
- {
- if ($orderList[0] != $orderID) {
- $data['code'] = 101;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['data'] = $orderList[0];
- $data['info'] = "下车点:当前站点只有一个订单,但不包含你要取消的订单";
- return $data;
- }
- $current_bus_order_list[$station_end] = "-1,0,0";
- } else { //该站点的订单数大于1
- if (!in_array($orderID, $orderList)) {
- //不存在该订单
- $data['code'] = 101;
- $data['param'] = $runID . "||" . $busID . "||" . $station_start . "||" . $station_end . "||" . $orderID . "||" . $order_num;
- $data['info'] = "下车点:当前站点有多个订单,但不包含你要取消的订单";
- return $data;
- }
- $re_order_list = "";
- //将该订单从订单列表中移除
- foreach ($orderList as $v) {
- if ($v != $orderID) {
- $re_order_list .= $v . "|";
- }
- }
- $res = "-1," . rtrim($re_order_list, '|') . "," . 0;
- $current_bus_order_list[$station_end] = $res;
- }
- $bus_list[$busID] = $current_bus_order_list;
- $mem->set("orderList[$runID]", $bus_list);
- } else {
- }
- }
- //将表run_bus_station_view中的订单信息删除
- $dt_order_list_start = ""; //上车站修改后的订单列表拼接字符串
- $dt_order_list_end = "";//下车站修改后的订单列表拼接字符串
- $total_order_list = ""; //总的站点订单列表
- $pdo = conn();
- $sql = "select order_id from run_bus_station_view where run_id=" . $runID . " AND bus_no=" . $busID;
- $result = $pdo->query($sql);
- $row = $result->fetchAll(PDO::FETCH_ASSOC);
- if (isset($row[0]['order_id'])) {
- $data_order_list = $row[0]['order_id'];
- $arr_order_list = explode(";", $data_order_list);
- $arr_start = explode("|", $arr_order_list[$station_start]);
- foreach ($arr_start as $v) {
- if ($v != $orderID) {
- $dt_order_list_start .= $v . "|";
- }
- }
- $dt_order_list_start = rtrim($dt_order_list_start, '|');
- if ($dt_order_list_start == "") //取消该订单后该站点无其他订单,将此处置为0
- {
- $dt_order_list_start = 0;
- }
- $arr_order_list[$station_start] = $dt_order_list_start;
-
- $arr_end = explode("|", $arr_order_list[$station_end]);
- foreach ($arr_end as $v) {
- if ($v != $orderID) {
- $dt_order_list_end .= $v . "|";
- }
- }
- $dt_order_list_end = rtrim($dt_order_list_end, '|');
- if ($dt_order_list_end == "") {
- $dt_order_list_end = 0;
- }
- $arr_order_list[$station_end] = $dt_order_list_end;
-
- foreach ($arr_order_list as $v) {
- $total_order_list .= $v . ";";
- }
- $total_order_list = rtrim($total_order_list, ";"); //将最后一个‘;’移除
-
- $sql1 = "update run_bus_station_view set order_id='{$total_order_list}',update_time=NOW() where RUN_ID=$runID and bus_no=$busID";
- $result = $pdo->query($sql1);
- if (!$result) {
- $data['code'] = 102;
- $data['info'] = "更新run_bus_station_view失败:" . $sql1;
- return $data;
- } else {
- $data['code'] = 0;
- $data['info'] = "取消成功" . $sql1;
- return $data;
- }
-
- } else {
- $data['code'] = 103;
- $data['info'] = "查询失败:" . $sql;
- return $data;
-
- }
- }
- }
-
- /*$qa = new cancelOrder();
- //$qa->cancel_order(612102, 1, $station_start, $station_end, $orderID = "", $order_num);
- $qa->cancel_order(612102, 1, 3, 6, 111111, 1);*/
|