|
|
|
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
|
|
exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class innerTrainSearch extends CI_Controller{
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
parent::__construct();
|
|
|
|
header('Access-Control-Allow-Origin:*');
|
|
|
|
header('Access-Control-Allow-Methods:POST, GET');
|
|
|
|
header('Access-Control-Max-Age:0');
|
|
|
|
header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
|
|
|
|
header('Access-Control-Allow-Credentials:true');
|
|
|
|
$this->load->helper('train');
|
|
|
|
$this->start_time = microtime(true);
|
|
|
|
//$this->load->model("BIZ_intel_train_model");//国际火车模型
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index(){
|
|
|
|
exit('你走错了!');
|
|
|
|
}
|
|
|
|
|
|
|
|
//查询选择
|
|
|
|
public function search(){
|
|
|
|
//接收参数
|
|
|
|
$date = $this->input->get_post('date');
|
|
|
|
$from = $this->input->get_post('from');
|
|
|
|
$to = $this->input->get_post('to');
|
|
|
|
|
|
|
|
if(!$date || !$from || !$to){
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
|
|
|
}else{
|
|
|
|
//根据选择的接口供应商调用对应的接口,默认使用携程的接口
|
|
|
|
$supplier = $this->input->get_post('supplier');
|
|
|
|
|
|
|
|
switch ($supplier){
|
|
|
|
case 'juhe':
|
|
|
|
$this->juheApi($date,$from,$to);
|
|
|
|
break;
|
|
|
|
case 'ctrip':
|
|
|
|
$this->ctripApi($date,$from,$to);
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
$this->juheApi($date,$from,$to);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//聚合数据接口
|
|
|
|
public function juheApi($train_date=null,$fromStation=null,$toStation=null,$return=false){
|
|
|
|
//定义一些变量
|
|
|
|
$flag = true;
|
|
|
|
$juheTrainInfo = '';
|
|
|
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
//判断数据是否合法
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
exit('传参不能为空!');
|
|
|
|
}else{
|
|
|
|
if(strlen($fromStation) != 3){
|
|
|
|
exit('fromStation:参数错误!');
|
|
|
|
}
|
|
|
|
if(strlen($toStation) != 3){
|
|
|
|
exit('toStation:参数错误!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$api_start_time = microtime(true);
|
|
|
|
|
|
|
|
//调用查询模块
|
|
|
|
$search_return = $this->Searchtrain($train_date,$fromStation,$toStation);
|
|
|
|
$api_end_time = microtime(true);
|
|
|
|
|
|
|
|
//调用拼接处理模块
|
|
|
|
$trainjson = $this->createTrainJson($search_return);
|
|
|
|
$end_time = microtime(true);
|
|
|
|
|
|
|
|
//聚合接口相应时间
|
|
|
|
$api_responsive_time = $api_end_time - $api_start_time;
|
|
|
|
|
|
|
|
//我们的接口相应时间
|
|
|
|
$responsive_time = $end_time - $this->start_time;
|
|
|
|
log_message('error','TRAINSPEED|请求url:'.$this->url.'|聚合相应时间:'.$api_responsive_time.'s|接口运行时间:'.$responsive_time.'s|+7天:'.$this->seveth);
|
|
|
|
|
|
|
|
if($return){
|
|
|
|
return ($trainjson);
|
|
|
|
}else{
|
|
|
|
echo ($trainjson);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//搜索模块
|
|
|
|
function Searchtrain($train_date,$fromStation,$toStation){
|
|
|
|
$this->train_date = $train_date;
|
|
|
|
$now_time = time();
|
|
|
|
$this->differ_time = (strtotime($train_date) - $now_time) / 86400;
|
|
|
|
$this->seveth = false;
|
|
|
|
//屏蔽掉超过预售期的搜索,提高速度
|
|
|
|
if($this->differ_time > 29){
|
|
|
|
$train_date = date('Y-m-d',strtotime('+7day'));
|
|
|
|
$this->seveth = true;
|
|
|
|
}
|
|
|
|
$this->url = JUHE_TRAIN_CX_API.'?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
|
|
|
|
$train_info = GetPost_http($this->url);
|
|
|
|
return $train_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
//字符串拼接模块
|
|
|
|
function createTrainJson($returnjson){
|
|
|
|
$return_data = new stdClass();
|
|
|
|
$return_data->data = new stdClass();
|
|
|
|
$return_data->data->httpstatus = 200;
|
|
|
|
$return_data->data->seveth = $this->seveth;
|
|
|
|
$return_data->data->supplier = 'juhe';
|
|
|
|
$return_data->data->result = array();
|
|
|
|
$return_data->data->map = new stdClass();
|
|
|
|
$obj = array();
|
|
|
|
$i = 0;
|
|
|
|
$pricestr = '';
|
|
|
|
if(!empty($returnjson)){
|
|
|
|
if(!empty(json_decode($returnjson)->result->list)){
|
|
|
|
foreach (json_decode($returnjson)->result->list as $value){
|
|
|
|
$obj[$value->from_station_code] = $value->from_station_name;
|
|
|
|
$obj[$value->to_station_code] = $value->to_station_name;
|
|
|
|
$seat_type = '';
|
|
|
|
if(isset($value->gjrw_price)){
|
|
|
|
if($value->gjrw_price > 0){
|
|
|
|
$gjrwPrice = $value->gjrw_price * 10;
|
|
|
|
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->qtxb_price)){
|
|
|
|
if($value->qtxb_price > 0){
|
|
|
|
$seat_type .= '"H":"¥'.$value->qtxb_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->rw_price)){
|
|
|
|
if($value->rw_price > 0){
|
|
|
|
$rwPrice = $value->rw_price * 10;
|
|
|
|
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->rz_price)){
|
|
|
|
if($value->rz_price > 0){
|
|
|
|
$rzPrice = $value->rz_price * 10;
|
|
|
|
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->tdz_price)){
|
|
|
|
if($value->tdz_price > 0){
|
|
|
|
$seat_type .= '"P":"¥'.$value->tdz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->wz_price)){
|
|
|
|
if($value->wz_price > 0){
|
|
|
|
$wzPrice = $value->wz_price * 10;
|
|
|
|
$seat_type .= '"WZ":"¥'.$value->wz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->yw_price)){
|
|
|
|
if($value->yw_price > 0){
|
|
|
|
$ywPrice = $value->yw_price * 10;
|
|
|
|
$seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->yz_price)){
|
|
|
|
if($value->yz_price > 0){
|
|
|
|
$yzPrice = $value->yz_price * 10;
|
|
|
|
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->edz_price)){
|
|
|
|
if($value->edz_price > 0){
|
|
|
|
$seat_type .= '"O":"¥'.$value->edz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->ydz_price)){
|
|
|
|
if($value->ydz_price > 0){
|
|
|
|
$seat_type .= '"M":"¥'.$value->ydz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->swz_price)){
|
|
|
|
if($value->swz_price > 0){
|
|
|
|
$swzPrice = $value->swz_price * 10;
|
|
|
|
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isset($value->dw_price)){
|
|
|
|
if($value->dw_price > 0){
|
|
|
|
$seat_type .= '"F":"¥'.$value->dw_price.'",';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"';
|
|
|
|
//余票字符串
|
|
|
|
$this->can_buy_now = $value->can_buy_now;
|
|
|
|
$return_data->data->result[$i] = '|预定|'.$value->train_no.'|'.$value->train_code.'|'.$value->from_station_name.'|'.$value->to_station_name.'|'.$value->from_station_code.'|'.$value->to_station_code.'|'.$value->start_time.'|'.$value->arrive_time.'|'.$value->run_time.'|'.$value->can_buy_now.'||'.$this->train_date.'||||||||'.ticket_exchange($value->gjrw_price,$value->gjrw_num,$this->seveth).'|'.ticket_exchange($value->qtxb_price,$value->qtxb_num,$this->seveth).'|'.ticket_exchange($value->rw_price,$value->rw_num,$this->seveth).'|'.ticket_exchange($value->rz_price,$value->rz_num,$this->seveth).'|'.ticket_exchange($value->tdz_price,$value->tdz_num,$this->seveth).'|'.ticket_exchange($value->wz_price,$value->wz_num,$this->seveth).'||'.ticket_exchange($value->yw_price,$value->yw_num,$this->seveth).'|'.ticket_exchange($value->yz_price,$value->yz_num,$this->seveth).'|'.ticket_exchange($value->edz_price,$value->edz_num,$this->seveth).'|'.ticket_exchange($value->ydz_price,$value->ydz_num,$this->seveth).'|'.ticket_exchange($value->swz_price,$value->swz_num,$this->seveth).'|'.ticket_exchange($value->dw_price,$value->dw_num,$this->seveth).'||';
|
|
|
|
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
|
|
|
|
$return_data->data->price[$i] = $data;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$return_data->data->map = (object)$obj;
|
|
|
|
return json_encode($return_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//携程数据接口
|
|
|
|
public function ctripApi($date=null,$from=null,$to=null,$return=false){
|
|
|
|
if(!$date || !$from || !$to){
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
|
|
|
}else{
|
|
|
|
$isCache = false;
|
|
|
|
$iseven = false;
|
|
|
|
$cachedata = false;
|
|
|
|
$now_time = time();
|
|
|
|
$differ = (strtotime($date) - $now_time) / 86400;
|
|
|
|
if($differ > 29){
|
|
|
|
$date = date('Y-m-d',strtotime('+7day'));
|
|
|
|
$iseven = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//转换三字码为中文
|
|
|
|
$this->load->model("ctrip_model");
|
|
|
|
$FromName = $this->ctrip_model->ReplaceCodeToName($from);
|
|
|
|
$ToName = $this->ctrip_model->ReplaceCodeToName($to);
|
|
|
|
|
|
|
|
|
|
|
|
if(!$FromName || !$ToName){
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
|
|
|
}else{
|
|
|
|
$FromName = $FromName->station_name;
|
|
|
|
$ToName = $ToName->station_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
//生成请求链接
|
|
|
|
$TimeStamp = time();
|
|
|
|
$Sign = md5($TimeStamp.DATAKEY);
|
|
|
|
|
|
|
|
$url = JSONRETURN.'SearchS2S/?From='.urlencode($FromName).'&To='.urlencode($ToName).'&DepartDate='.$date.'&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
|
|
|
|
|
|
|
$api_start_time = microtime(true);
|
|
|
|
|
|
|
|
//获取数据
|
|
|
|
$ResponseJson = GetPost_http($url,'','GET');
|
|
|
|
|
|
|
|
$api_end_time = microtime(true);
|
|
|
|
|
|
|
|
$ResponseData = json_decode($ResponseJson);
|
|
|
|
|
|
|
|
$api_responsive_time = $api_end_time - $api_start_time;
|
|
|
|
|
|
|
|
if(empty($ResponseData->Trains)){
|
|
|
|
log_message('error','ctrip_trian|status:trains is empty |相应时间:'.$api_responsive_time);
|
|
|
|
}else{
|
|
|
|
log_message('error','ctrip_trian|status:'.$ResponseData->ResponseStatus->Ack.'|相应时间:'.$api_responsive_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
//定义返回的json
|
|
|
|
$ReturnData = new stdClass();
|
|
|
|
$ReturnData->httpstatus = 200;
|
|
|
|
$ReturnData->data = new stdClass();
|
|
|
|
$ReturnData->data->seven = $iseven;
|
|
|
|
$ReturnData->data->cache = $isCache;
|
|
|
|
$ReturnData->data->supplier = 'ctrip';
|
|
|
|
$ReturnData->data->result = array();
|
|
|
|
$ReturnData->data->map = new stdClass();
|
|
|
|
$obj = array();
|
|
|
|
$i = 0;
|
|
|
|
$PriceStr = '';
|
|
|
|
|
|
|
|
//数据解析
|
|
|
|
if(!empty($ResponseData->Trains)){
|
|
|
|
foreach ($ResponseData->Trains as $TrainInfo){
|
|
|
|
$obj[$TrainInfo->FromTelcode] = $TrainInfo->FromStationName;
|
|
|
|
$obj[$TrainInfo->ToTelcode] = $TrainInfo->ToStationName;
|
|
|
|
$SeaType = '';
|
|
|
|
//余数初始化为空
|
|
|
|
$gjrwNum = $rwNum = $rzNum = $tdzNum = $wzNum = $yzNum = $edzNum = $ydzNum = $swzNum = $ywNum = $dwNum = $ydwNum = $edzNum = null;
|
|
|
|
foreach($TrainInfo->Seats as $Seats){
|
|
|
|
//从香港出发的 D/G 火车加价3%
|
|
|
|
if($from == 'XJA'){
|
|
|
|
if(stripos($TrainInfo->TrainNo, "G") !== false || stripos($TrainInfo->TrainNo, "D") !== false){
|
|
|
|
$Seats->Price = $Seats->Price * 1.03;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '高级软卧上'){
|
|
|
|
$gjrwXiaPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"6":"'.$gjrwXiaPrice.'","A6":"¥'.$Seats->Price.'",';
|
|
|
|
$gjrwNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '软卧上'){
|
|
|
|
$rwPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"4":"'.$rwPrice.'","A4":"¥'.$Seats->Price.'",';
|
|
|
|
$rwNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '一等双软上'){
|
|
|
|
$SeaType .= '"YDW":"¥'.$Seats->Price.'",';
|
|
|
|
$ydwNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '软座'){
|
|
|
|
$rzPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"2":"'.$rzPrice.'","A2":"¥'.$Seats->Price.'",';
|
|
|
|
$rzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '特等座'){
|
|
|
|
$SeaType .= '"P":"¥'.$Seats->Price.'",';
|
|
|
|
$tdzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '无座'){
|
|
|
|
$SeaType .= '"WZ":"¥'.$Seats->Price.'",';
|
|
|
|
$wzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '硬座'){
|
|
|
|
$yzPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"1":"'.$yzPrice.'","A1":"¥'.$Seats->Price.'",';
|
|
|
|
$yzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '二等座'){
|
|
|
|
$SeaType .= '"O":"¥'.$Seats->Price.'",';
|
|
|
|
$edzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '一等座'){
|
|
|
|
$SeaType .= '"M":"¥'.$Seats->Price.'",';
|
|
|
|
$ydzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '商务座'){
|
|
|
|
$swzPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"9":"'.$swzPrice.'","A9":"¥'.$Seats->Price.'",';
|
|
|
|
$swzNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '硬卧上'){
|
|
|
|
$ywPrice = $Seats->Price * 10;
|
|
|
|
$SeaType .= '"3":"'.$ywPrice.'","A3":"¥'.$Seats->Price.'",';
|
|
|
|
$ywNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '二等双软上'){
|
|
|
|
$SeaType .= '"EDW":"¥'.$Seats->Price.'",';
|
|
|
|
$erwNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($Seats->SeatName == '动卧上'){
|
|
|
|
$SeaType .= '"F":"¥'.$Seats->Price.'",';
|
|
|
|
$dwNum = $Seats->TicketLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
$PriceStr = $SeaType.'"train_no":'.'"'.$TrainInfo->TrainNo.'"';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//对返回的数据进行容错处理
|
|
|
|
$gjrwNum = isset($gjrwNum) ? ticket_exchange($Seats->Price,$gjrwNum,$iseven) : '';
|
|
|
|
$rwNum = isset($rwNum) ? ticket_exchange($Seats->Price,$rwNum,$iseven) : '';
|
|
|
|
$rzNum = isset($rzNum) ? ticket_exchange($Seats->Price,$rzNum,$iseven) : '';
|
|
|
|
$tdzNum = isset($tdzNum) ? ticket_exchange($Seats->Price,$tdzNum,$iseven) : '';
|
|
|
|
$wzNum = isset($wzNum) ? ticket_exchange($Seats->Price,$wzNum,$iseven) : '';
|
|
|
|
$ywNum = isset($ywNum) ? ticket_exchange($Seats->Price,$ywNum,$iseven) : '';
|
|
|
|
$yzNum = isset($yzNum) ? ticket_exchange($Seats->Price,$yzNum,$iseven) : '';
|
|
|
|
$edzNum = isset($edzNum) ? ticket_exchange($Seats->Price,$edzNum,$iseven) : '';
|
|
|
|
$ydzNum = isset($ydzNum) ? ticket_exchange($Seats->Price,$ydzNum,$iseven) : '';
|
|
|
|
$swzNum = isset($swzNum) ? ticket_exchange($Seats->Price,$swzNum,$iseven) : '';
|
|
|
|
$dwNum = isset($dwNum) ? ticket_exchange($Seats->Price,$dwNum,$iseven) : '';
|
|
|
|
$ydwNum = isset($ydwNum) ? ticket_exchange($Seats->Price,$ydwNum,$iseven) : '';
|
|
|
|
$erwNum = isset($erwNum) ? ticket_exchange($Seats->Price,$erwNum,$iseven) : '';
|
|
|
|
|
|
|
|
$runMin = $TrainInfo->DurationMinutes % 60;
|
|
|
|
$runHour = ($TrainInfo->DurationMinutes - $runMin) / 60;
|
|
|
|
|
|
|
|
$ReturnData->data->result[$i] = '|预定|'.$TrainInfo->Train12306No.'|'.$TrainInfo->TrainNo.'|'.$TrainInfo->FromStationName.'|'.$TrainInfo->ToStationName.'|'.$TrainInfo->FromTelcode.'|'.$TrainInfo->ToTelcode.'|'.$TrainInfo->StartTime.'|'.$TrainInfo->ArriveTime.'|'.$runHour.':'.$runMin.'|'.$TrainInfo->CanWebBuy.'||'.date('Ymd',strtotime($date)).'||||||||'.$gjrwNum.'||'.$rwNum.'|'.$rzNum.'|'.$tdzNum.'|'.$wzNum.'||'.$ywNum.'|'.$yzNum.'|'.$edzNum.'|'.$ydzNum.'|'.$swzNum.'|'.$dwNum.'|||'.$ydwNum.'|'.$erwNum;
|
|
|
|
|
|
|
|
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$PriceStr.'},"messages":[],"validateMessages":{}}';
|
|
|
|
$ReturnData->data->price[$i] = $data;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//print_r($ResponseData);die();
|
|
|
|
$ReturnData->data->map = (object)$obj;
|
|
|
|
if($return){
|
|
|
|
return json_encode($ReturnData);
|
|
|
|
}else{
|
|
|
|
echo json_encode($ReturnData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//查询经停站(基于携程api)
|
|
|
|
public function getstopstation(){
|
|
|
|
//接收参数
|
|
|
|
$DepartDate = $this->input->get_post('DepartDate');
|
|
|
|
$TrainNo = $this->input->get_post('TrainNo');
|
|
|
|
|
|
|
|
if(!$DepartDate || !$TrainNo){
|
|
|
|
exit('传参错误!');
|
|
|
|
}else{
|
|
|
|
//生成请求链接
|
|
|
|
$TimeStamp = time();
|
|
|
|
$Sign = md5($TimeStamp.DATAKEY);
|
|
|
|
|
|
|
|
$url = JSONRETURN.'GetStopStations/?DepartDate='.$DepartDate.'&TrainNo='.$TrainNo.'&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
|
|
|
|
|
|
|
$ResponseJson = GetPost_http($url,'','GET');
|
|
|
|
$ResponseData = json_decode($ResponseJson);
|
|
|
|
|
|
|
|
//构造12306格式
|
|
|
|
$ReturnData = array();
|
|
|
|
$ReturnData['validateMessagesShowId'] = '_validatorMessage';
|
|
|
|
$ReturnData['status'] = true;
|
|
|
|
$ReturnData['httpstatus'] = 200;
|
|
|
|
$ReturnData['data'] = array();
|
|
|
|
$i = 0;
|
|
|
|
$Last_num = count($ResponseData->StopStations);
|
|
|
|
foreach($ResponseData->StopStations as $items){
|
|
|
|
if($i == 0){
|
|
|
|
$ReturnData['data']['data'][$i]['start_station_name'] = $items->StationName;
|
|
|
|
$ReturnData['data']['data'][$i]['station_train_code'] = $TrainNo;
|
|
|
|
$ReturnData['data']['data'][$i]['end_station_name'] = $ResponseData->StopStations[$Last_num-1]->StationName;
|
|
|
|
}
|
|
|
|
$ReturnData['data']['data'][$i]['arrive_time'] = $items->ArrivalTime;
|
|
|
|
$ReturnData['data']['data'][$i]['station_name'] = $items->StationName;
|
|
|
|
$ReturnData['data']['data'][$i]['start_time'] = $items->StartTime;
|
|
|
|
$ReturnData['data']['data'][$i]['stopover_time'] = $items->StopMinutes;
|
|
|
|
$ReturnData['data']['data'][$i]['station_no'] = $items->StationNo;
|
|
|
|
$ReturnData['data']['data'][$i]['isEnabled'] = true;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
$ReturnData['messages'] = array();
|
|
|
|
$ReturnData['validateMessages'] = new stdClass();
|
|
|
|
print_r(json_encode($ReturnData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取所有站点信息(基于携程api)
|
|
|
|
public function getallstation(){
|
|
|
|
//生成请求参数
|
|
|
|
$TimeStamp = time();
|
|
|
|
$Sign = md5($TimeStamp.DATAKEY);
|
|
|
|
|
|
|
|
$url = JSONRETURN.'/GetAllStations/?&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
|
|
|
|
|
|
|
$ResponseJson = GetPost_http($url,'','GET');
|
|
|
|
|
|
|
|
$ResponseData = json_decode($ResponseJson);
|
|
|
|
|
|
|
|
$data = array();
|
|
|
|
foreach ($ResponseData->Stations as $items){
|
|
|
|
$data['StationName'] = isset($items->StationName) ? checkNull($items->StationName) : '';
|
|
|
|
$data['PinYin'] = isset($items->PinYin) ? checkNull($items->PinYin) : '';
|
|
|
|
$data['Telecode'] = isset($items->Telecode) ? checkNull($items->Telecode) : '';
|
|
|
|
$data['Address'] = isset($items->Address) ? checkNull($items->Address) : '';
|
|
|
|
$data['Geography'] = isset($items->Geography) ? checkNull($items->Geography) : '';
|
|
|
|
$this->load->model("ctrip_model");
|
|
|
|
$this->ctrip_model->AddOrUpdate($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//查询中转方案(基于携程api)
|
|
|
|
public function gettraintrainsfer(){
|
|
|
|
$FromCode = $this->input->get_post('FromCode');
|
|
|
|
$ToCode = $this->input->get_post('ToCode');
|
|
|
|
$DepartDate = $this->input->get_post('DepartDate');
|
|
|
|
|
|
|
|
if(!$FromCode || !$ToCode || !$DepartDate){
|
|
|
|
exit('传参错误!');
|
|
|
|
}else{
|
|
|
|
$TimeStamp = time();
|
|
|
|
$Sign = md5($TimeStamp.DATAKEY);
|
|
|
|
$this->load->model("ctrip_model");
|
|
|
|
$FromName = $this->ctrip_model->ReplaceCodeToName($FromCode);
|
|
|
|
$ToName = $this->ctrip_model->ReplaceCodeToName($ToCode);
|
|
|
|
|
|
|
|
$From = $FromName->station_name;
|
|
|
|
$To = $ToName->station_name;
|
|
|
|
|
|
|
|
$url = JSONRETURN.'GetTrainTransfer?User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign.'&From='.urlencode($From).'&To='.urlencode($To).'&DepartDate='.$DepartDate;
|
|
|
|
|
|
|
|
|
|
|
|
$ResponseJson = GetPost_http($url,'','GET');
|
|
|
|
$ResponseData = json_decode($ResponseJson);
|
|
|
|
|
|
|
|
$priceAddSeats = ['软卧','硬卧'];
|
|
|
|
foreach ($ResponseData->TransferLines as $methodsItems){
|
|
|
|
foreach($methodsItems->Trains as $trainsItems){
|
|
|
|
foreach ($trainsItems->Seats as $seatsItems){
|
|
|
|
if(in_array($seatsItems->SeatName,$priceAddSeats)){
|
|
|
|
$seatsItems->Price = ceil($seatsItems->Price * 1.2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
print_r(json_encode($ResponseData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//火车移动端数据接口
|
|
|
|
public function get_train(){
|
|
|
|
$train_date = $this->input->get('date');
|
|
|
|
$fromStation = $this->input->get('from');
|
|
|
|
$toStation = $this->input->get('to');
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
exit('传参错误!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$back_json = $this->juheApi($train_date,$fromStation,$toStation,true);
|
|
|
|
|
|
|
|
$train_info = new stdClass();
|
|
|
|
$train_info = json_decode($back_json);
|
|
|
|
|
|
|
|
$return_data = new stdClass();
|
|
|
|
$return_data->status = 200;
|
|
|
|
$return_data->search = new stdClass();
|
|
|
|
$return_data->search->FromStationCode = $fromStation;
|
|
|
|
$return_data->search->ToStationCode = $toStation;
|
|
|
|
$return_data->search->StartDate = $train_date;
|
|
|
|
|
|
|
|
$return_data->CardFee = 3;
|
|
|
|
//MainlandChina:大陆内地寄送费用
|
|
|
|
//HMT:港澳台寄送费用
|
|
|
|
//寄送费按订单收,无论多少张票,没有取票费
|
|
|
|
//$return_data->MainlandChina = 6;
|
|
|
|
//$return_data->HMT = 15;
|
|
|
|
$this->load->library('Currency');
|
|
|
|
define("CONST_SITE_CURRENCY","USD");
|
|
|
|
$return_data->ExRate = $this->currency->get_site_currencyrate();
|
|
|
|
$return_data->result = array();
|
|
|
|
$i = 0;
|
|
|
|
|
|
|
|
foreach ($train_info->data->result as $value){
|
|
|
|
$return_data->result[$i] = new StdClass();
|
|
|
|
$data = explode('|', $value);
|
|
|
|
$return_data->result[$i]->TrainNo = $data[2];
|
|
|
|
$return_data->result[$i]->TrainCode = $data[3];
|
|
|
|
$return_data->result[$i]->TrainType = substr(ucwords($data[3]), 0, 1);
|
|
|
|
$return_data->result[$i]->StartStationCode = $data[4];
|
|
|
|
$return_data->result[$i]->EndStationCode = $data[5];
|
|
|
|
$return_data->result[$i]->DepartStation = '';
|
|
|
|
$return_data->result[$i]->DepartStationCode = $data[6];
|
|
|
|
$return_data->result[$i]->DepartStationNo = '';
|
|
|
|
$return_data->result[$i]->ArriveStation = '';
|
|
|
|
$return_data->result[$i]->ArriveStationCode = $data[7];
|
|
|
|
$return_data->result[$i]->ArriveStationNo = '';
|
|
|
|
$return_data->result[$i]->DepartTime = $data[8];
|
|
|
|
$return_data->result[$i]->ArriveTime = $data[9];
|
|
|
|
$return_data->result[$i]->RunTime = $data[10];
|
|
|
|
$return_data->result[$i]->IsBookable = true;
|
|
|
|
//$return_data->result[$i]->SeatType = '123456789OMPA';
|
|
|
|
$return_data->result[$i]->cached = 1;
|
|
|
|
//$return_data->result[$i]->CheapSeat = new stdClass();
|
|
|
|
$price = json_decode($train_info->data->price[$i]);
|
|
|
|
|
|
|
|
$return_data->result[$i]->CheapSeat = null;
|
|
|
|
$return_data->result[$i]->SeatList = array();
|
|
|
|
//做一个数据存储所有的座位类型的余票
|
|
|
|
$seat_yp_map = array(
|
|
|
|
'A' => $data[21], //高级软卧
|
|
|
|
'A6' => $data[21], //高级软卧
|
|
|
|
'H' => $data[22], //其他
|
|
|
|
'A4' => $data[23], //软卧
|
|
|
|
'A2' => $data[24], //软座
|
|
|
|
'P' => $data[25], //特等座
|
|
|
|
'WZ' => $data[26],//无座
|
|
|
|
'X' => $data[26], //无座
|
|
|
|
'A3' => $data[28], //硬卧
|
|
|
|
'A1' => $data[29], //硬座
|
|
|
|
'O' => $data[30], //二等座
|
|
|
|
'A8' => $data[30], //二等座
|
|
|
|
'A7' => $data[31], //一等座
|
|
|
|
'M' => $data[31], //一等座
|
|
|
|
'A9' => $data[32], //商务座
|
|
|
|
'F' => $data[33], //动卧
|
|
|
|
// 'YDW' => $data[36], //一等卧
|
|
|
|
// 'EDW' => $data[37], //二等卧
|
|
|
|
);
|
|
|
|
$j=0;
|
|
|
|
$soldoutnums = 0;
|
|
|
|
foreach($price->data as $key=>$value){
|
|
|
|
if($key != 'train_no'){
|
|
|
|
if(!is_numeric($key)){
|
|
|
|
$return_data->result[$i]->SeatList[$j] = new StdClass();
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatCode = $key;
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatName = get_name($key);
|
|
|
|
$value = str_replace('¥','',$value);
|
|
|
|
|
|
|
|
if(in_array($key, array('A3', 'A4', 'A5', 'A6', '3', '4', '5', '6', 'A', 'F', 'S','YDW','EDW'))){
|
|
|
|
if (stripos($return_data->result[$i]->TrainNo, "D") !== false || stripos($return_data->result[$i]->TrainNo, "G") !== false) {
|
|
|
|
$value = $value * 1.2;
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 1;
|
|
|
|
}else{
|
|
|
|
$value = $value * 1.15;
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.75;
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.5;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (stripos($value, ".")) {//判断是否是整数,避免类似ecil(9.9*10)=100
|
|
|
|
$value = ceil($value);
|
|
|
|
}*/
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatPrice = $this->currency->GetSiteMoney($value);
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatPriceRMB = $value;
|
|
|
|
if($fromStation == 'LSO' || $toStation == 'LSO'){
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 33;
|
|
|
|
}else{
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 6;
|
|
|
|
}
|
|
|
|
if($fromStation == 'XJA' && stripos($return_data->result[$i]->TrainNo, "G") && $value > 500){
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 10;
|
|
|
|
}
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ServiceChargeRMB = $return_data->result[$i]->SeatList[$j]->ServiceCharge * $return_data->ExRate;
|
|
|
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatInventory = $seat_yp_map[$key];
|
|
|
|
if($return_data->result[$i]->SeatList[$j]->SeatInventory == '有'){
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatInventory = 99;
|
|
|
|
}elseif($return_data->result[$i]->SeatList[$j]->SeatInventory == '无'){
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatInventory = 0;
|
|
|
|
$soldoutnums++;
|
|
|
|
}
|
|
|
|
|
|
|
|
$j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($soldoutnums >= $j){
|
|
|
|
$return_data->result[$i]->soldout = true;
|
|
|
|
}else{
|
|
|
|
$return_data->result[$i]->soldout = false;
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
print_r(json_encode($return_data));
|
|
|
|
}
|
|
|
|
}
|