supplier_id = $supplier_id; } } /** * Function Description:我要找车,获取巴士位置信息 * Function Name: GetBusPosition * @param $order_id * @param $run_date * * @return array * * @author 娄梦宁 */ public function GetBusPosition($order_id, $run_date) { if (preg_match("/^[1-9][0-9]{0,10}$/", $order_id) == false || preg_match("/^[0-9]{4}-(((0[13578]|(10|12))-(0[1-9]|[1-2][0-9]|3[0-1]))|(02-(0[1-9]|[1-2][0-9]))|((0[469]|11)-(0[1-9]|[1-2][0-9]|30)))$/", $run_date) == false) { return [ 'code' => 1, 'info' => '参数错误', 'list' => [], ]; } $order_main = new OrderMain(); $res = $order_main->get_bus_position_info($order_id, $run_date); $list = [ 'res' => [ 'address' => $res['address'] == null ? '' : $res['address'], 'res_id' => $res['res_id'], 'res_name' => $res['res_name'], 'longitude' => $res['longitude'], 'latitude' => $res['latitude'], ], 'bus' => [ 'bus_id' => $res['bus_id'] == null ? '' : $res['res_id'], 'bus_no' => $res['bus_no'], 'seat_no' => explode(",", $res['seat_list']), 'driver_name' => $res['driver_name'], 'driver_mobile' => $res['driver_mobile'], 'color' => $res['color'] == null ? '' : $res['color'], 'img_url' => $res['img_url'] == null ? '' : $res['img_url'], 'bus_name' => $res['bus_name'], 'lng' => $res['lng'] == null ? '' : $res['lng'], 'lat' => $res['lat'] == null ? '' : $res['lat'], ], 'wx_flag' => [ 'appoint_message' => $res['appoint_message'], 'click_send_message' => $res['click_send_message'] ], "send_bus_flag" => 1 ]; if ($res['bus_id'] == null || $res['bus_no'] == "") { $list["send_bus_flag"] = 0; } return [ 'code' => 0, 'info' => '数据获取成功', 'list' => $list, ]; } /** * Function Description:获取产品某一天的票种价格 * Function Name: GetPriceDateOne * @param $tourist_id * @param $run_date * * @return array * * @author 娄梦宁 */ public function GetPriceDateOne($tourist_id, $run_date,$userId) { $list = $this->GetPriceDate($tourist_id, $run_date,$userId); if (!$list) { return [ 'code' => 1, 'info' => '数据获取失败' ]; } return [ 'code' => 0, 'info' => '数据获取成功', 'list' => array_values($list) ]; } public function addMinPriceToTouristArray($tourist_array, $next_days = 14,$userId=2) { $return_array = array(); foreach ($tourist_array as $tourist_id => $tourist_info) { $mini_price = $this->getMiniPriceNextDays($tourist_id, $next_days,$userId); if ($mini_price == -1) { continue; } $tourist_info["mini_price"] = $mini_price; $return_array[$tourist_id] = $tourist_info; } return $return_array; } public function getMiniPriceNextDays($tourist_id, $next_days,$userId=2) { $mini_price = 99999; $price_array = $this->GetPriceNextDays($tourist_id, $next_days,$userId); if ($price_array["code"] == 0) { if (count($price_array["list"]) <= 0) { return -1; } foreach ($price_array["list"] as $price_info) { $mini_price = $price_info["mini_price"] < $mini_price ? $price_info["mini_price"] : $mini_price; } } return $mini_price; } public function GetPriceNextDays($tourist_id, $next_days,$userId = 2) { $next_days = $next_days < 1 ? 1 : $next_days; $list = []; for ($i = 1; $i < $next_days; $i++) { $tmp_date = date('Y-m-d', strtotime("+$i day")); $tmp_list = $this->GetPriceDate($tourist_id, $tmp_date,$userId); if (!$tmp_list) { // $list[]=[ // 'ticket_date'=>$tmp_date, // 'mini_price'=>99999, // 'ticket_num'=>0, // ]; } else { $list[] = [ 'ticket_date' => $tmp_date, 'mini_price' => $tmp_list['adult']['ticket_price'], 'child_price' => $tmp_list['child']['ticket_price'], 'ticket_num' => $tmp_list['adult']['ticket_num'], ]; } } return [ 'code' => 0, 'info' => '数据获取成功', 'list' => $list, ]; } public function GetPriceDateMonth($tourist_id,$userId=2) { return $this->GetPriceNextDays($tourist_id, 60,$userId); } /** * Function Description:获取特定日期产品价格通用方法 * Function Name: GetPriceDate * @param $tourist_id * @param $run_date * @param $userId * * @return array|bool * * @author 娄梦宁 */ public function GetPriceDate($tourist_id, $run_date,$userId =2) { $get_tourist_stock = new GetTouristStock; $opera_tourist_run = new OperaTouristRun(); //调用组合产品库存成本接口 $stock = $get_tourist_stock->getTouristStock($tourist_id, $run_date, $this->supplier_id, $userId); if ($stock['code'] != 0) { return false; } $sale_type = $opera_tourist_run->get_sale_type($tourist_id, $run_date,$this->supplier_id); $list = [ 'prod_id' => 'TR-' . $tourist_id . '-1', 'ticket_price' => $stock['list']['adult_cost'], 'ticket_num' => $stock['list']['limit_adult_num'], 'ticket_all_num' => $stock['list']['limit_total_num'], ]; $list1 = [ 'prod_id' => 'TR-' . $tourist_id . '-2', 'ticket_price' => $stock['list']['child_cost'], 'ticket_num' => $stock['list']['limit_adult_num'], 'ticket_all_num' => $stock['list']['limit_total_num'], ]; $is_booking = Util::checkBookTime($sale_type['pre_days'], $sale_type['pre_time'], $run_date); //预订时间已过 if (!$is_booking) { //产品当天下架 $list['ticket_num'] = 0; $list['ticket_all_num'] = 0; $list1['ticket_num'] = 0; $list1['ticket_all_num'] = 0; return [ 'adult' => $list, 'child' => $list1, ]; } if (empty($sale_type)) { //当天没有价格日历,直接用默认值 $tourist_profit = Yii::$app->params['tourist_profit']; $list['ticket_price'] = floor($stock['list']['adult_cost'] * (1 + $tourist_profit * 0.01)); $list1['ticket_price'] = floor($stock['list']['child_cost'] * (1 + $tourist_profit * 0.01)); } else { if ($sale_type['is_onsale'] == 0) { //产品当天下架 $list['ticket_num'] = 0; $list['ticket_all_num'] = 0; $list1['ticket_num'] = 0; $list1['ticket_all_num'] = 0; } else { //产品正常可售 if ($sale_type['sale_type_child'] == 2) { //百分比加价 $list1['ticket_price'] = floor($stock['list']['child_cost'] * ($sale_type['diff_para_child'] * 0.01 + 1)); } else { //固定加价 $list1['ticket_price'] = floor($stock['list']['child_cost'] + $sale_type['diff_para_child']); } if ($sale_type['sale_type_adult'] == 2) { //百分比加价 $list['ticket_price'] = floor($stock['list']['adult_cost'] * ($sale_type['diff_para_adult'] * 0.01 + 1)); } else { //固定加价 $list['ticket_price'] = floor($stock['list']['adult_cost'] + $sale_type['diff_para_adult']); } } } return [ 'adult' => $list, 'child' => $list1, ]; } /** * Function Description:获取可否换座类型 * Function Name: getChangeSeatType * @param $order_id * * @return array * * @author 娄梦宁 */ public function getChangeSeatType($order_id) { $order_main = new OrderMain(); $opera_line = new OperaLine(); $run_main = new RunMain(); $order_info = $order_main->getOrderInfoForGetSeat($order_id); try { #1:判断线路、巴士是否支持选座# $line_allow_seat = $opera_line->getLineSeatAllow($order_info['line_id']); if ($line_allow_seat['allow_select_seat'] == 0) { return [ 'code' => 0, 'info' => '该线路不支持换座!', 'data' => [ 'change_seat_type' => 1 ] ]; } #2:判断是否选过座# #run_x表表名# $run_x = 'run_' . substr($order_info['run_date'], 0, 4) . substr($order_info['run_date'], 5, 2); #endregion $is_choose = $run_main->GetRunxAllowSelectSeat($run_x, $order_info['run_id'], explode(',', $order_info['son_order'])); foreach ($is_choose as $val) { if ($val['allow_select_seat'] != 156) { return [ 'code' => 0, 'info' => '该订单已经进行过选座!', 'data' => [ 'change_seat_type' => 2, ] ]; } } #3:判断是否在选座时间内# #发车前一个小时的时间戳 $bus_start_time = strtotime($order_info['run_date'] . ' ' . $order_info['prod_start_station_time']) - 3600; #发车前一天晚上六点的时间戳 $start_change_seat_time = strtotime($order_info['run_date']) - 19800; if (time() < $start_change_seat_time) { return [ 'code' => 0, 'info' => '乘坐车辆暂未派车,请在发车前一天18点30分后进行选座!', 'data' => [ 'change_seat_type' => 3 ] ]; } elseif (time() > $bus_start_time) { return [ 'code' => 0, 'info' => '座位已经自动选择', 'data' => [ 'change_seat_type' => 4 ] ]; } return [ 'code' => 0, 'info' => '可以选座', 'data' => [ 'change_seat_type' => 0 ] ]; } catch (Exception $e) { return [ 'code' => 1, 'info' => '后台接口错误!', ]; } } /** * Function Description:获取自由行保险价格 * Function Name: getFreeWalkDays * @param $tourist_id * @param $run_date * @return array * @author 田玲菲 */ public function getFreeWalkDays($tourist_id, $run_date) { //获取行程天数 $operaTouristCommon = new OperaTouristCommon(); $result = $operaTouristCommon->getDays($tourist_id); $days = $result['day_num']; if (empty($days)) { return [ 'code' => 1, 'info' => '获取出行天数失败' ]; } //根据天数获取prod_id $params = Yii::$app->params; $prod_id = $params['tourist_insurance']['sun_prod_id'][$days - 1]; if (!$prod_id) { return [ 'code' => 2, 'info' => '获取保险产品id失败', 'prod_id' => $prod_id, 'days' => $days, ]; } //根据prod_id和run_date去取保险价格 $operaProductRun = new OperaProductRun(); $rst = $operaProductRun->getRunInfoByProdIdAndDate($prod_id, $run_date); if (count($rst) > 0 && $rst['is_onsale'] == 1) { return [ 'code' => 0, 'info' => '获取价格成功', 'price' => $rst['cus_price'] ]; } else { return [ 'code' => 3, 'info' => '获取价格失败', ]; } } }