|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <?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"
- ),
- "450544" => array( //淮安到南京
- "location_str" => "33.5435191204,119.0305519272;33.5873176700,119.0299018475;33.5798716700,119.0343818475;33.5783009300,119.0416947149;33.5435191204,119.0305519272;32.2438270358,118.7542868552;32.0607615820,118.7627673779;31.7304993041,118.8766786916",
- "station_str" => "淮安汽车总站;市二院公交站;解放东路站台;富春西门站台;淮安汽车南站;葛塘;江苏省政府;南京禄口机场",
- "station_type" => "0;0;0;0;0;1;1;1",
- "station_time" => "0,5,5,5,15,90,40,60"
- ),
- "450539" => array( //南京到淮安
- "location_str" => "31.7304993041,118.8766786916;32.0607615820,118.7627673779;32.2438270358,118.7542868552;33.5435191204,119.0305519272;33.5783009300,119.0416947149;33.5798716700,119.0343818475;33.5873176700,119.0299018475;33.6054623298,119.0221313820",
- "station_str" => "南京禄口机场;江苏省政府;葛塘;淮安汽车南站;富春西门站台;解放东路站台;市二院公交站;淮安汽车总站",
- "station_type" => "0;0;0;1;1;1;1;1",
- "station_time" => "0,60,40,90,15,5,5,5"
- )
- );
-
- //线路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");
- //线路5
- $order["450544"] = 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");
- //线路6
- $order["450539"] = 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");
-
-
- $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 + $num) > 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) {
- 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) {
- return FALSE;
- }
- }
- return true;
- }
- }
-
- /*$a = new submitOrder();
- $a->setOrder('450036', '612102', '444444', '2016-09-30 08:00', 1,3,6);*/
|