|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/9/19
- * Time: 13:07
- */
- require_once 'common.php';
-
- class submitOrder extends virtifyUsers
- {
- function setOrder($prodID, $runID, $orderID, $run_date, $num, $station_start, $station_end)
- {
- $lineInfo = array(
- "449860" => array( //元通浦口线:五塘广场->
- "location_str" => "32.1107459388,118.7773547217;31.9958864195,118.7214606940;32.0669047363,118.6480796003;32.1066028030,118.6864933063;32.2440220358,118.7538198552;32.1262075684,120.6999317242;32.0572268781,120.7459405916;32.0230078984,120.9027142484;31.9860627150,120.8867945067;31.9732029880,120.8984345866",
- "station_str" => "五塘广场;元通地铁站;南工大地铁站;明发城市广场;葛塘客运站;九华收费站;九圩港客运站;校西客运站;政务中心;中南世纪城",
- "station_type" => "0;0;0;0;0;1;1;1;1;1",
- "station_time" => "0,20,14,15,20,126,18,25,10,18"
- ),
- "450036" => array(//南站仙林 南京南站-》
- "location_str" => "31.9716001666,118.7971965314;32.0496327360,118.8945605812;32.0848861808,118.9048846157;32.0988533068,118.9304284265;32.1262075684,120.6999317242;32.0572268781,120.7459405916;32.0230078984,120.9027142484;31.9860627150,120.8867945067;31.9732029880,120.8984345866",
- "station_str" => "南京南站;马群地铁站;仙鹤门地铁站;仙林中心站;九华收费站;九圩港客运站;校西客运站;政务中心;中南世纪城",
- "station_type" => "0;0;0;0;1;1;1;1;1",
- "station_time" => "0,20,17,10,126,18,25,10,18"
- ),
- "450037" => array(//南站仙林线 南通大学-》
- "location_str" => "31.9732029880,120.8984345866;31.9860627150,120.8867945067;32.0230078984,120.9027142484;32.0572268781,120.7459405916;32.1262075684,120.6999317242;32.0988533068,118.9304284265;32.0848861808,118.9048846157;32.0496327360,118.8945605812;31.9716001666,118.7971965314",
- "station_str" => "中南世纪城;政务中心;校西客运站;九圩港客运站;九华收费站;仙林中心站;仙鹤门地铁站;马群地铁站;南京南站",
- "station_type" => "0;0;0;0;0;1;1;1;1",
- "station_time" => "0,18,10,25,18,126,10,17,20"
- ),
- "449865" => array(//元通浦口线:南通大学->
- "location_str" => "31.9732029880,120.8984345866;31.9860627150,120.8867945067;32.0230078984,120.9027142484;32.0572268781,120.7459405916;32.1262075684,120.6999317242;32.2440220358,118.7538198552;32.1066028030,118.6864933063;32.0669047363,118.6480796003;31.9958864195,118.7214606940;32.1107459388,118.7773547217",
- "station_str" => "中南世纪城;政务中心;校西客运站;九圩港客运站;九华收费站;葛塘客运站;明发城市广场;南工大地铁站;元通地铁站;五塘广场",
- "station_type" => "0;0;0;0;0;1;1;1;1;1",
- "station_time" => "0,18,10,25,18,126,20,15,14,20"
- )
- );
-
- //线路1订单列表 元通浦口线:五塘广场->元通地铁站->南工大地铁站->明发城市广场->葛塘客运站->||九华收费站->九圩港客运站->校西客运站->政务中心->南通大学
- $order["449860"] = array("1,0,0", "1,0,0", "1,0,0", "1,0,0", "1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0"); //"上车或者下车,订单列表,订单人数"
- //线路2
- $order["450036"] = array("1,0,0", "1,0,0", "1,0,0", "1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0");
- //线路3
- $order["449865"] = array("1,0,0", "1,0,0", "1,0,0", "1,0,0", "1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0");
- //线路4
- $order["450037"] = array("1,0,0", "1,0,0", "1,0,0", "1,0,0", "1,0,0", "-1,0,0", "-1,0,0", "-1,0,0", "-1,0,0");
-
- $orderService = new createOrderService();
- $mem = new Memcache();
- $mem->connect('127.0.0.1', 11211);
- $res = $mem->get("orderList[$runID]");
- if ($res) {//该班次已经有班次
- $i = 0;
- foreach ($res as $k => $v) { //$k:车号 $v:车上的订单号列表
- //及算当前车里面的人数
- foreach ($v as $item) {
- $arr = explode(",", $item);
- if ($arr[0] = "1") //说明是上车点
- {
- $i += $arr[2]; //该车上的总人数
- }
- }
- if ($i >= 6) {
- continue;
- }
-
- //将该订单添加到当前的车,并更新数据库表run_bus_station_view
- $str_order = "";
- foreach ($v as $station_id => $station_str) { //$station_id:站点ID $station_str:站点信息
- $order_arr = explode(",", $station_str);
- if ($station_start == $station_id) { //上车点
- if ($order_arr[1] == 0) {
- $v[$station_id] = "1" . "," . $orderID . "," . ($order_arr[2] + $num);
- $str_order .= $orderID . ";";
- } else {
- $v[$station_id] = "1" . "," . $order_arr[1] . "|" . $orderID . "," . ($order_arr[2] + $num);
- $str_order .= $order_arr[1] . "|" . $orderID . ";";
- }
- } elseif ($station_end == $station_id) //下车点
- {
- if ($order_arr[1] == 0) {
- $v[$station_id] = "-1" . "," . $orderID . "," . "0";
- $str_order .= $orderID . ";";
- } else {
- $v[$station_id] = "-1" . "," . $order_arr[1] . "|" . $orderID . "," . "0";
- $str_order .= $order_arr[1] . "|" . $orderID . ";";
- }
- } else {
- $str_order .= $order_arr[1] . ";";
- }
- /*if ($order_arr[1] == 0) {
- $str_order .= $order_arr[1] . ";";
- } else {
- $str_order .= $order_arr[1] . "|" . $orderID . ";";
- }*/
-
- }
- $str_order = rtrim($str_order, ';');
- $bus_order[$k] = $v;
- $mem->set("orderList[$runID]", $bus_order);
-
-
- $ress = $this->set_run_station($runID, $k, $prodID, $str_order);
- if ($ress) {
- $data['code'] = '0';
- $data['info'] = '派车成功';
- $res_arr['order_id'] = $orderID;
- $res_arr['bus_no'] = $k;
- $data['result'] = $res_arr;
- return $data;
- } else {
- $data['code'] = '102';
- $data['info'] = '插入run_bus_station_view失败,派车失败';
- return $data;
- }
- }
- //增派新的车
- $stock = $orderService->stock($runID);
- if ($stock['bus_num'] < 1) {
- $data['code'] = '101';
- $data['info'] = '当前班次无可派车辆';
- return $data;
- }
- $str_station_time = "";
- $station_time = $run_date;
- $arr_station_time = explode(",", $lineInfo[$prodID]['station_time']);
- foreach ($arr_station_time as $v) {
- $station_time = date("Y-m-d H:i", strtotime($station_time) + $v * 60); //上下车时间
- $str_station_time .= $station_time . ";";
- }
-
- //拼接订单列表串
- $str_order = "";
- foreach ($order[$prodID] as $k => $item) {
- if ($station_start == $k) { //上车点
- $order[$prodID][$k] = "1" . "," . $orderID . "," . $num;
- }
- if ($station_end == $k) //下车点
- {
- $order[$prodID][$k] = "-1" . "," . $orderID . "," . 0;
- }
- $order_arr = explode(",", $order[$prodID][$k]);
- $str_order .= $order_arr[1] . ";";
- }
- $str_order = rtrim($str_order, ';');
- $bus_order[$stock['next_blank_car']] = $order[$prodID];
- $mem->set("orderList[$runID]", $bus_order);
- //TODO:将订单信息存入数据库中
- $result = $this->set_run_station($runID, $stock['next_blank_car'], $prodID, $str_order, $lineInfo[$prodID]['station_str'], $lineInfo[$prodID]['location_str'], $lineInfo[$prodID]['station_type'], $str_station_time);
- if ($result) {
- $data['code'] = '0';
- $data['info'] = '派车成功';
- $res_arr['order_id'] = $orderID;
- $res_arr['bus_no'] = $stock['next_blank_car'];
- $data['result'] = $res_arr;
- return $data;
- } else {
- $data['code'] = '102';
- $data['info'] = '插入run_bus_station_view失败,派车失败';
- return $data;
- }
-
- } else { //该班次的第一单
- $stock = $orderService->stock($runID);
- if ($stock['bus_num'] > 1) {
- $data['code'] = '101';
- $data['info'] = '当前班次无可派车辆';
- return $data;
- }
- $str_station_time = "";
- $station_time = $run_date;
- $arr_station_time = explode(",", $lineInfo[$prodID]['station_time']);
- foreach ($arr_station_time as $v) {
- $station_time = date("Y-m-d H:i", strtotime($station_time) + $v * 60); //上下车时间
- $str_station_time .= $station_time . ";";
- }
-
- $str_order = "";
- foreach ($order[$prodID] as $k => $item) {
- if ($station_start == $k) { //上车点
- $order[$prodID][$k] = "1" . "," . $orderID . "," . $num;
- }
- if ($station_end == $k) //下车点
- {
- $order[$prodID][$k] = "-1" . "," . $orderID . "," . "0";
- }
- $order_arr = explode(",", $order[$prodID][$k]);
- $str_order .= $order_arr[1] . ";";
- }
- $str_order = rtrim($str_order, ';');
-
- $bus_order[$stock['next_blank_car']] = $order[$prodID];
- $mem->set("orderList[$runID]", $bus_order);
- //TODO:将订单信息存入数据库中
- /*echo $sql = "INSERT into run_bus_station_view(run_id,bus_no,prod_id,order_id,station,lat_long,station_type,station_time,update_time) VALUES(" . $runID . ",'" . $stock['next_blank_car'] . "','" . $prodID . "','" . $str_order . "','" . $lineInfo[$prodID]['station_str'] . "','" . $lineInfo[$prodID]['location_str'] . "','" . $lineInfo[$prodID]['station_type'] . "','" . $str_station_time . "',NOW());";*/
- $result = $this->set_run_station($runID, $stock['next_blank_car'], $prodID, $str_order, $lineInfo[$prodID]['station_str'], $lineInfo[$prodID]['location_str'], $lineInfo[$prodID]['station_type'], $str_station_time);
- if ($result) {
- $data['code'] = '0';
- $data['info'] = '派车成功';
- $res_arr['order_id'] = $orderID;
- $res_arr['bus_no'] = $stock['next_blank_car'];
- $data['result'] = $res_arr;
- return $data;
- } else {
- $data['code'] = '102';
- $data['info'] = '插入run_bus_station_view失败,派车失败';
- return $data;
- }
- }
- }
-
- public function set_run_station($run_id, $bus_no, $prod_id, $order_id, $station = "", $lat_long = "", $station_type = "", $station_time = "")
- {
- $pdo = conn();
- $sql = "SELECT id from run_bus_station_view where run_id = '" . $run_id . "' and bus_no='" . $bus_no . "'";
- $result = $pdo->query($sql);
- $row = $result->fetchAll(PDO::FETCH_ASSOC);
- if (!isset($row[0]['id'])) {
- $sql = "INSERT into run_bus_station_view(run_id,bus_no,prod_id,order_id,station,lat_long,station_type,station_time,update_time) VALUES(" . $run_id . ",'" . $bus_no . "','" . $prod_id . "','" . $order_id . "','" . $station . "','" . $lat_long . "','" . $station_type . "','" . $station_time . "',NOW());";
- writeLog("更新run_bus_station_view的sql语句" . json_encode($sql));
- $result = $pdo->query($sql);
- if (!$result) {
- echo $sql;
- return false;
- }
- } else {
- $sql = "UPDATE run_bus_station_view set cancel_flag =0,order_id='" . $order_id . "',update_time=NOW() where run_id =" . $run_id . " and bus_no =" . $bus_no;
- $result = $pdo->query($sql);
- writeLog("更新run_bus_station_view的sql语句" . json_encode($sql));
- if (!$result) {
- echo $sql;
- return FALSE;
- }
- }
- return true;
- }
- }
-
- $prodID = isset($_REQUEST['prodID']) ? $_REQUEST['prodID'] : false;
- $runID = isset($_REQUEST['runID']) ? $_REQUEST['runID'] : false;
- $orderID = isset($_REQUEST['orderID']) ? $_REQUEST['orderID'] : false;
- $run_date = isset($_REQUEST['run_date']) ? $_REQUEST['run_date'] : false;
- $num = isset($_REQUEST['num']) ? $_REQUEST['num'] : false;
- $station_start = $_REQUEST['station_start'];
- $station_end = $_REQUEST['station_end'];
- /*$station_start = isset($_REQUEST['station_start']) ? $_REQUEST['station_start'] : false;
- $station_end = isset($_REQUEST['station_end']) ? $_REQUEST['station_end'] : false;*/
- if ($prodID && $runID && $orderID && $run_date && $num) {
- $a = new submitOrder();
- $res = $a->setOrder($prodID, $runID, $orderID, $run_date, $num, $station_start, $station_end);
- echo json_encode($res);
- } else {
- echo $prodID . "--" . $runID . "--" . $orderID . "--" . $run_date . "--" . $num . "--" . $station_start . "--" . $station_end;
- }
|