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.
 
 
 
 
 

106 lines
5.0 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/9/7
  6. * Time: 19:28
  7. */
  8. require_once __DIR__ . '/common.php';
  9. require_once __DIR__ . '/dispatch_algorithm.php';
  10. class getTimeByLoc extends virtifyUsers
  11. {
  12. public static $NJ_NT_LINE_ID="449860";
  13. public static $NT_NJ_LINE_ID="449865";
  14. public function getTimeByLocation($prodID, $runID, $orderID, $num, $beginX_Y, $endX_Y, $run_date)
  15. {
  16. $mem = new Memcache();
  17. $mem->connect('127.0.0.1', 11211);
  18. $PoolStatus = $mem->get("orderPoolStatus[$runID]"); //添加runid标记是为了区别是哪个时间的班次
  19. $unlock_orderlist = $mem->get("orderList[$runID]"); //拿到当前的未锁定的订单池进行进一步操作
  20. $orderService = new createOrderService();
  21. if ($PoolStatus) //存在订单状态池
  22. {
  23. foreach ($PoolStatus as $k => $v) {
  24. if (isset($v['status']) && $v['status'] == 1) { //还有未锁定的订单池
  25. $value = $unlock_orderlist[$k];
  26. $pool_passager_num = $orderService->poolNum($value); //计算该订单池中总共的乘客数
  27. if (!$value || $pool_passager_num + $num > 6) {//说明该订单池不能加入该订单
  28. continue;
  29. }
  30. $begin_x_y = $orderService->timeMatrix($value, $beginX_Y, 1); //获取所有起点时间矩阵
  31. $end_x_y = $orderService->timeMatrix($value, $endX_Y, 2); //获取所有终点时间矩阵
  32. $new_order = array("order_id" => $orderID, "num" => $num, "startx_y" => $beginX_Y, "endx_y" => $endX_Y);
  33. die;
  34. $da = new dispatch_algorithm();
  35. $res = $da->dispatch($prodID, $value, $new_order, $begin_x_y, $end_x_y, $run_date, true);//调用调配订单算法
  36. if (!$res) {
  37. continue;
  38. }
  39. $temp_result = array();
  40. $temp_i = 0;
  41. foreach ($res as $res_temp) {
  42. if ($res_temp["order_id"] == $orderID) {
  43. //$temp_result[$temp_i]["order_id"] = $orderID;
  44. $temp_result[$temp_i] = $res_temp["time"];
  45. $temp_i++;
  46. }
  47. }
  48. $result['code'] = '0';
  49. $result['info'] = '时间预估成功';
  50. $result['result'] = array(date("H:i", strtotime($temp_result[0])), date("H:i", strtotime($temp_result[1])));
  51. return $result;
  52. }
  53. }
  54. //如果该订单均不能符合当前存在的任意订单池,需要加车,那么只需要算当前这个订单的始终点时间
  55. $stock = $orderService->stock($runID);
  56. if ($stock['bus_num'] < 1) { //如果没有库存,虚拟一辆空车,也需要返回上下车时间
  57. $result['code'] = '101';
  58. $result['info'] = '无可派车辆';
  59. }
  60. $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
  61. return $res;
  62. } else { //不存在当前班次的订单池,直接创建新的订单池以及订单状态池
  63. //这里还需要进行判断有没有可以派的车(即有没有超出规定车辆数量的限制) 需要从数据库读取当前
  64. $stock = $orderService->stock($runID);
  65. if ($stock['bus_num'] < 1) {
  66. $result['code'] = '101';
  67. $result['info'] = '无可派车辆';
  68. }
  69. //只需要算当前这个订单的始终点时间
  70. $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
  71. return $res;
  72. }
  73. }
  74. }
  75. $gtb = new getTimeByLoc();
  76. $prodID = isset($_POST['prod_id']) ? $_POST['prod_id'] : false;
  77. $runID = isset($_POST['run_id']) ? $_POST['run_id'] : false;
  78. $num = isset($_POST['num']) ? $_POST['num'] : false;
  79. $beginX_Y = isset($_POST['startx_y']) ? $_POST['startx_y'] : false;
  80. $endX_Y = isset($_POST['endx_y']) ? $_POST['endx_y'] : false;
  81. $run_date = isset($_POST['run_date']) ? $_POST['run_date'] : false;
  82. //先判断是否属于规定的市区
  83. if (!$beginX_Y || !$endX_Y) {
  84. exit();
  85. }
  86. $start_area = commonUtils::GeocodingAPI($beginX_Y);
  87. $end_area = commonUtils::GeocodingAPI($endX_Y);
  88. if (($prodID ==getTimeByLoc::$NJ_NT_LINE_ID && $start_area == "南京市" && $end_area == "南通市") || ($prodID == getTimeByLoc::$NT_NJ_LINE_ID && $start_area == "南通市" && $end_area == "南京市")) {
  89. if ($prodID && $runID && $num && $beginX_Y && $endX_Y && $run_date) {
  90. $orderID = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  91. $res = $gtb->getTimeByLocation($prodID, $runID, $orderID, $num, $beginX_Y, $endX_Y, $run_date);
  92. echo json_encode($res);
  93. }
  94. } else {
  95. $result['code'] = 1;
  96. $result['info'] = "所选地点不在规划范围内";
  97. echo json_encode($result);
  98. }