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.
 
 
 
 
 
 

110 lines
5.4 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. $da = new dispatch_algorithm();
  34. $res = $da->dispatch($prodID, $value, $new_order, $begin_x_y, $end_x_y, $run_date, true);//调用调配订单算法
  35. if (!$res) {
  36. continue;
  37. }
  38. $temp_result = array();
  39. $temp_i = 0;
  40. foreach ($res as $res_temp) {
  41. if ($res_temp["order_id"] == $orderID) {
  42. //$temp_result[$temp_i]["order_id"] = $orderID;
  43. $temp_result[$temp_i] = $res_temp["time"];
  44. $temp_i++;
  45. }
  46. }
  47. $result['code'] = '0';
  48. $result['info'] = '时间预估成功';
  49. $result['result'] = array(date("H:i", strtotime($temp_result[0])), date("H:i", strtotime($temp_result[1])));
  50. $start1 = strtotime($temp_result[0]) + 5 * 60;
  51. $start2 = strtotime($temp_result[0]) - 10 * 60;
  52. $end1 = strtotime($temp_result[1]) + 5 * 60;
  53. $end2 = strtotime($temp_result[1]) - 10 * 60;
  54. $result['str_time'] = array(date("H:i", $start2) . '--' . date("H:i", $start1), date("H:i", $end2) . '--' . date("H:i", $end1));
  55. return $result;
  56. }
  57. }
  58. //如果该订单均不能符合当前存在的任意订单池,需要加车,那么只需要算当前这个订单的始终点时间
  59. $stock = $orderService->stock($runID);
  60. if ($stock['bus_num'] < 1) { //如果没有库存,虚拟一辆空车,也需要返回上下车时间
  61. $result['code'] = '101';
  62. $result['info'] = '无可派车辆';
  63. }
  64. $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
  65. return $res;
  66. } else { //不存在当前班次的订单池,直接创建新的订单池以及订单状态池
  67. //这里还需要进行判断有没有可以派的车(即有没有超出规定车辆数量的限制) 需要从数据库读取当前
  68. $stock = $orderService->stock($runID);
  69. if ($stock['bus_num'] < 1) {
  70. $result['code'] = '101';
  71. $result['info'] = '无可派车辆';
  72. }
  73. //只需要算当前这个订单的始终点时间
  74. $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
  75. return $res;
  76. }
  77. }
  78. }
  79. $gtb = new getTimeByLoc();
  80. $prodID = isset($_POST['prod_id']) ? $_POST['prod_id'] : false;
  81. $runID = isset($_POST['run_id']) ? $_POST['run_id'] : false;
  82. $num = isset($_POST['num']) ? $_POST['num'] : false;
  83. $beginX_Y = isset($_POST['startx_y']) ? $_POST['startx_y'] : false;
  84. $endX_Y = isset($_POST['endx_y']) ? $_POST['endx_y'] : false;
  85. $run_date = isset($_POST['run_date']) ? $_POST['run_date'] : false;
  86. //先判断是否属于规定的市区
  87. if (!$beginX_Y || !$endX_Y) {
  88. exit();
  89. }
  90. $start_area = commonUtils::GeocodingAPI($beginX_Y);
  91. $end_area = commonUtils::GeocodingAPI($endX_Y);
  92. if (($prodID == getTimeByLoc::$NJ_NT_LINE_ID && $start_area == "南京市" && $end_area == "南通市") || ($prodID == getTimeByLoc::$NT_NJ_LINE_ID && $start_area == "南通市" && $end_area == "南京市")) {
  93. if ($prodID && $runID && $num && $beginX_Y && $endX_Y && $run_date) {
  94. $orderID = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  95. $res = $gtb->getTimeByLocation($prodID, $runID, $orderID, $num, $beginX_Y, $endX_Y, $run_date);
  96. echo json_encode($res);
  97. }
  98. } else {
  99. $result['code'] = 1;
  100. $result['info'] = "所选地点不在规划范围内";
  101. echo json_encode($result);
  102. }