|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/9/7
- * Time: 19:28
- */
- require_once __DIR__ . '/common.php';
- require_once __DIR__ . '/dispatch_algorithm.php';
-
- class getTimeByLoc extends virtifyUsers
- {
- public static $NJ_NT_LINE_ID = "449860";
- public static $NT_NJ_LINE_ID = "449865";
-
- public function getTimeByLocation($prodID, $runID, $orderID, $num, $beginX_Y, $endX_Y, $run_date)
- {
- $mem = new Memcache();
- $mem->connect('127.0.0.1', 11211);
- $PoolStatus = $mem->get("orderPoolStatus[$runID]"); //添加runid标记是为了区别是哪个时间的班次
- $unlock_orderlist = $mem->get("orderList[$runID]"); //拿到当前的未锁定的订单池进行进一步操作
- $orderService = new createOrderService();
- if ($PoolStatus) //存在订单状态池
- {
- foreach ($PoolStatus as $k => $v) {
- if (isset($v['status']) && $v['status'] == 1) { //还有未锁定的订单池
- $value = $unlock_orderlist[$k];
- $pool_passager_num = $orderService->poolNum($value); //计算该订单池中总共的乘客数
- if (!$value || $pool_passager_num + $num > 6) {//说明该订单池不能加入该订单
- continue;
- }
- $begin_x_y = $orderService->timeMatrix($value, $beginX_Y, 1); //获取所有起点时间矩阵
- $end_x_y = $orderService->timeMatrix($value, $endX_Y, 2); //获取所有终点时间矩阵
- $new_order = array("order_id" => $orderID, "num" => $num, "startx_y" => $beginX_Y, "endx_y" => $endX_Y);
- $da = new dispatch_algorithm();
- $res = $da->dispatch($prodID, $value, $new_order, $begin_x_y, $end_x_y, $run_date, true);//调用调配订单算法
- if (!$res) {
- continue;
- }
- $temp_result = array();
- $temp_i = 0;
- foreach ($res as $res_temp) {
- if ($res_temp["order_id"] == $orderID) {
- //$temp_result[$temp_i]["order_id"] = $orderID;
- $temp_result[$temp_i] = $res_temp["time"];
- $temp_i++;
- }
- }
- $result['code'] = '0';
- $result['info'] = '时间预估成功';
- $result['result'] = array(date("H:i", strtotime($temp_result[0])), date("H:i", strtotime($temp_result[1])));
- $start1 = strtotime($temp_result[0]) + 5 * 60;
- $start2 = strtotime($temp_result[0]) - 10 * 60;
- $end1 = strtotime($temp_result[1]) + 5 * 60;
- $end2 = strtotime($temp_result[1]) - 10 * 60;
- $result['str_time'] = array(date("H:i", $start2) . '--' . date("H:i", $start1), date("H:i", $end2) . '--' . date("H:i", $end1));
- return $result;
- }
- }
- //如果该订单均不能符合当前存在的任意订单池,需要加车,那么只需要算当前这个订单的始终点时间
- $stock = $orderService->stock($runID);
- if ($stock['bus_num'] < 1) { //如果没有库存,虚拟一辆空车,也需要返回上下车时间
- $result['code'] = '101';
- $result['info'] = '无可派车辆';
- }
- $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
- return $res;
- } else { //不存在当前班次的订单池,直接创建新的订单池以及订单状态池
- //这里还需要进行判断有没有可以派的车(即有没有超出规定车辆数量的限制) 需要从数据库读取当前
- $stock = $orderService->stock($runID);
- if ($stock['bus_num'] < 1) {
- $result['code'] = '101';
- $result['info'] = '无可派车辆';
- }
- //只需要算当前这个订单的始终点时间
- $res = $orderService->firstOrderNeedTime($beginX_Y, $endX_Y, $run_date);
- return $res;
- }
- }
- }
-
- $gtb = new getTimeByLoc();
- $prodID = isset($_POST['prod_id']) ? $_POST['prod_id'] : false;
- $runID = isset($_POST['run_id']) ? $_POST['run_id'] : false;
- $num = isset($_POST['num']) ? $_POST['num'] : false;
- $beginX_Y = isset($_POST['startx_y']) ? $_POST['startx_y'] : false;
- $endX_Y = isset($_POST['endx_y']) ? $_POST['endx_y'] : false;
- $run_date = isset($_POST['run_date']) ? $_POST['run_date'] : false;
-
- //先判断是否属于规定的市区
- if (!$beginX_Y || !$endX_Y) {
- exit();
- }
- $start_area = commonUtils::GeocodingAPI($beginX_Y);
- $end_area = commonUtils::GeocodingAPI($endX_Y);
- if (($prodID == getTimeByLoc::$NJ_NT_LINE_ID && $start_area == "南京市" && $end_area == "南通市") || ($prodID == getTimeByLoc::$NT_NJ_LINE_ID && $start_area == "南通市" && $end_area == "南京市")) {
- if ($prodID && $runID && $num && $beginX_Y && $endX_Y && $run_date) {
- $orderID = date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
- $res = $gtb->getTimeByLocation($prodID, $runID, $orderID, $num, $beginX_Y, $endX_Y, $run_date);
- echo json_encode($res);
- }
- } else {
- $result['code'] = 1;
- $result['info'] = "所选地点不在规划范围内";
- echo json_encode($result);
- }
-
-
|