25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

submitOrder.php 14 KiB

3 년 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/9/19
  6. * Time: 13:07
  7. */
  8. require_once 'common.php';
  9. class submitOrder extends virtifyUsers
  10. {
  11. function setOrder($prodID, $runID, $orderID, $run_date, $num, $station_start, $station_end)
  12. {
  13. $lineInfo = array(
  14. "449860" => array( //元通浦口线:五塘广场->
  15. "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",
  16. "station_str" => "五塘广场;元通地铁站;南工大地铁站;明发城市广场;葛塘客运站;九华收费站;九圩港客运站;校西客运站;政务中心;中南世纪城",
  17. "station_type" => "0;0;0;0;0;1;1;1;1;1",
  18. "station_time" => "0,20,14,15,20,126,18,25,10,18"
  19. ),
  20. "450036" => array(//南站仙林 南京南站-》
  21. "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",
  22. "station_str" => "南京火车南站;马群地铁站;仙鹤门地铁站;仙林中心站;九华收费站;九圩港客运站;校西客运站;政务中心;中南世纪城",
  23. "station_type" => "0;0;0;0;1;1;1;1;1",
  24. "station_time" => "0,20,17,10,126,18,25,10,18"
  25. ),
  26. "450037" => array(//南站仙林线 南通大学-》
  27. "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",
  28. "station_str" => "中南世纪城;政务中心;校西客运站;九圩港客运站;九华收费站;仙林中心站;仙鹤门地铁站;马群地铁站;南京火车南站",
  29. "station_type" => "0;0;0;0;0;1;1;1;1",
  30. "station_time" => "0,18,10,25,18,126,10,17,20"
  31. ),
  32. "449865" => array(//元通浦口线:南通大学->
  33. "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",
  34. "station_str" => "中南世纪城;政务中心;校西客运站;九圩港客运站;九华收费站;葛塘客运站;明发城市广场;南工大地铁站;元通地铁站;五塘广场",
  35. "station_type" => "0;0;0;0;0;1;1;1;1;1",
  36. "station_time" => "0,18,10,25,18,126,20,15,14,20"
  37. ),
  38. "450544" => array( //淮安到南京
  39. "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",
  40. "station_str" => "淮安汽车总站;市二院公交站;解放东路站台;富春西门站台;淮安汽车南站;葛塘;江苏省政府;南京禄口机场",
  41. "station_type" => "0;0;0;0;0;1;1;1",
  42. "station_time" => "0,5,5,5,15,90,40,60"
  43. ),
  44. "450539" => array( //南京到淮安
  45. "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",
  46. "station_str" => "南京禄口机场;江苏省政府;葛塘;淮安汽车南站;富春西门站台;解放东路站台;市二院公交站;淮安汽车总站",
  47. "station_type" => "0;0;0;1;1;1;1;1",
  48. "station_time" => "0,60,40,90,15,5,5,5"
  49. )
  50. );
  51. //线路1订单列表 元通浦口线:五塘广场->元通地铁站->南工大地铁站->明发城市广场->葛塘客运站->||九华收费站->九圩港客运站->校西客运站->政务中心->南通大学
  52. $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"); //"上车或者下车,订单列表,订单人数"
  53. //线路2
  54. $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");
  55. //线路3
  56. $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");
  57. //线路4
  58. $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");
  59. //线路5
  60. $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");
  61. //线路6
  62. $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");
  63. $orderService = new createOrderService();
  64. $mem = new Memcache();
  65. $mem->connect('127.0.0.1', 11211);
  66. $res = $mem->get("orderList[$runID]");
  67. if ($res) {//该班次已经有班次
  68. $i = 0;
  69. foreach ($res as $k => $v) { //$k:车号 $v:车上的订单号列表
  70. //及算当前车里面的人数
  71. foreach ($v as $item) {
  72. $arr = explode(",", $item);
  73. if ($arr[0] = "1") //说明是上车点
  74. {
  75. $i += $arr[2]; //该车上的总人数
  76. }
  77. }
  78. if (($i + $num) > 6) {
  79. continue;
  80. }
  81. //将该订单添加到当前的车,并更新数据库表run_bus_station_view
  82. $str_order = "";
  83. foreach ($v as $station_id => $station_str) { //$station_id:站点ID $station_str:站点信息
  84. $order_arr = explode(",", $station_str);
  85. if ($station_start == $station_id) { //上车点
  86. if ($order_arr[1] == 0) {
  87. $v[$station_id] = "1" . "," . $orderID . "," . ($order_arr[2] + $num);
  88. $str_order .= $orderID . ";";
  89. } else {
  90. $v[$station_id] = "1" . "," . $order_arr[1] . "|" . $orderID . "," . ($order_arr[2] + $num);
  91. $str_order .= $order_arr[1] . "|" . $orderID . ";";
  92. }
  93. } elseif ($station_end == $station_id) //下车点
  94. {
  95. if ($order_arr[1] == 0) {
  96. $v[$station_id] = "-1" . "," . $orderID . "," . "0";
  97. $str_order .= $orderID . ";";
  98. } else {
  99. $v[$station_id] = "-1" . "," . $order_arr[1] . "|" . $orderID . "," . "0";
  100. $str_order .= $order_arr[1] . "|" . $orderID . ";";
  101. }
  102. } else {
  103. $str_order .= $order_arr[1] . ";";
  104. }
  105. /*if ($order_arr[1] == 0) {
  106. $str_order .= $order_arr[1] . ";";
  107. } else {
  108. $str_order .= $order_arr[1] . "|" . $orderID . ";";
  109. }*/
  110. }
  111. $str_order = rtrim($str_order, ';');
  112. $bus_order[$k] = $v;
  113. $mem->set("orderList[$runID]", $bus_order);
  114. $ress = $this->set_run_station($runID, $k, $prodID, $str_order);
  115. if ($ress) {
  116. $data['code'] = '0';
  117. $data['info'] = '派车成功';
  118. $res_arr['order_id'] = $orderID;
  119. $res_arr['bus_no'] = $k;
  120. $data['result'] = $res_arr;
  121. return $data;
  122. } else {
  123. $data['code'] = '102';
  124. $data['info'] = '插入run_bus_station_view失败,派车失败';
  125. return $data;
  126. }
  127. }
  128. //增派新的车
  129. $stock = $orderService->stock($runID);
  130. if ($stock['bus_num'] < 1) {
  131. $data['code'] = '101';
  132. $data['info'] = '当前班次无可派车辆';
  133. return $data;
  134. }
  135. $str_station_time = "";
  136. $station_time = $run_date;
  137. $arr_station_time = explode(",", $lineInfo[$prodID]['station_time']);
  138. foreach ($arr_station_time as $v) {
  139. $station_time = date("Y-m-d H:i", strtotime($station_time) + $v * 60); //上下车时间
  140. $str_station_time .= $station_time . ";";
  141. }
  142. //拼接订单列表串
  143. $str_order = "";
  144. foreach ($order[$prodID] as $k => $item) {
  145. if ($station_start == $k) { //上车点
  146. $order[$prodID][$k] = "1" . "," . $orderID . "," . $num;
  147. }
  148. if ($station_end == $k) //下车点
  149. {
  150. $order[$prodID][$k] = "-1" . "," . $orderID . "," . 0;
  151. }
  152. $order_arr = explode(",", $order[$prodID][$k]);
  153. $str_order .= $order_arr[1] . ";";
  154. }
  155. $str_order = rtrim($str_order, ';');
  156. $bus_order[$stock['next_blank_car']] = $order[$prodID];
  157. $mem->set("orderList[$runID]", $bus_order);
  158. //TODO:将订单信息存入数据库中
  159. $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);
  160. if ($result) {
  161. $data['code'] = '0';
  162. $data['info'] = '派车成功';
  163. $res_arr['order_id'] = $orderID;
  164. $res_arr['bus_no'] = $stock['next_blank_car'];
  165. $data['result'] = $res_arr;
  166. return $data;
  167. } else {
  168. $data['code'] = '102';
  169. $data['info'] = '插入run_bus_station_view失败,派车失败';
  170. return $data;
  171. }
  172. } else { //该班次的第一单
  173. $stock = $orderService->stock($runID);
  174. if ($stock['bus_num'] > 1) {
  175. $data['code'] = '101';
  176. $data['info'] = '当前班次无可派车辆';
  177. return $data;
  178. }
  179. $str_station_time = "";
  180. $station_time = $run_date;
  181. $arr_station_time = explode(",", $lineInfo[$prodID]['station_time']);
  182. foreach ($arr_station_time as $v) {
  183. $station_time = date("Y-m-d H:i", strtotime($station_time) + $v * 60); //上下车时间
  184. $str_station_time .= $station_time . ";";
  185. }
  186. $str_order = "";
  187. foreach ($order[$prodID] as $k => $item) {
  188. if ($station_start == $k) { //上车点
  189. $order[$prodID][$k] = "1" . "," . $orderID . "," . $num;
  190. }
  191. if ($station_end == $k) //下车点
  192. {
  193. $order[$prodID][$k] = "-1" . "," . $orderID . "," . "0";
  194. }
  195. $order_arr = explode(",", $order[$prodID][$k]);
  196. $str_order .= $order_arr[1] . ";";
  197. }
  198. $str_order = rtrim($str_order, ';');
  199. $bus_order[$stock['next_blank_car']] = $order[$prodID];
  200. $mem->set("orderList[$runID]", $bus_order);
  201. //TODO:将订单信息存入数据库中
  202. /*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());";*/
  203. $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);
  204. if ($result) {
  205. $data['code'] = '0';
  206. $data['info'] = '派车成功';
  207. $res_arr['order_id'] = $orderID;
  208. $res_arr['bus_no'] = $stock['next_blank_car'];
  209. $data['result'] = $res_arr;
  210. return $data;
  211. } else {
  212. $data['code'] = '102';
  213. $data['info'] = '插入run_bus_station_view失败,派车失败';
  214. return $data;
  215. }
  216. }
  217. }
  218. public function set_run_station($run_id, $bus_no, $prod_id, $order_id, $station = "", $lat_long = "", $station_type = "", $station_time = "")
  219. {
  220. $pdo = conn();
  221. $sql = "SELECT id from run_bus_station_view where run_id = '" . $run_id . "' and bus_no='" . $bus_no . "'";
  222. $result = $pdo->query($sql);
  223. $row = $result->fetchAll(PDO::FETCH_ASSOC);
  224. if (!isset($row[0]['id'])) {
  225. $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());";
  226. writeLog("更新run_bus_station_view的sql语句" . json_encode($sql));
  227. $result = $pdo->query($sql);
  228. if (!$result) {
  229. return false;
  230. }
  231. } else {
  232. $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;
  233. $result = $pdo->query($sql);
  234. writeLog("更新run_bus_station_view的sql语句" . json_encode($sql));
  235. if (!$result) {
  236. return FALSE;
  237. }
  238. }
  239. return true;
  240. }
  241. }
  242. /*$a = new submitOrder();
  243. $a->setOrder('450036', '612102', '444444', '2016-09-30 08:00', 1,3,6);*/