|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
<?php
|
|
|
|
|
<?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:*');
|
|
|
|
@ -15,47 +15,47 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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");
|
|
|
|
|
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 :
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
$this->juheApi($date,$from,$to);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//聚合数据接口
|
|
|
|
|
public function juheApi($train_date=null,$fromStation=null,$toStation=null){
|
|
|
|
|
//定义一些变量
|
|
|
|
|
$flag = true;
|
|
|
|
|
$juheTrainInfo = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断数据是否合法
|
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
|
exit('传参不能为空!');
|
|
|
|
@ -66,35 +66,35 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
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);
|
|
|
|
|
print_r($trainjson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//搜索模块
|
|
|
|
|
function Searchtrain($train_date,$fromStation,$toStation){
|
|
|
|
|
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;
|
|
|
|
@ -103,7 +103,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$train_info = GetPost_http($this->url);
|
|
|
|
|
return $train_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//字符串拼接模块
|
|
|
|
|
function createTrainJson($returnjson){
|
|
|
|
|
$return_data = new stdClass();
|
|
|
|
@ -125,7 +125,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
if(isset($value->gjrw_price)){
|
|
|
|
|
if($value->gjrw_price > 0){
|
|
|
|
|
$gjrwPrice = $value->gjrw_price * 10;
|
|
|
|
|
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
|
|
|
|
|
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($value->qtxb_price)){
|
|
|
|
@ -136,13 +136,13 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
if(isset($value->rw_price)){
|
|
|
|
|
if($value->rw_price > 0){
|
|
|
|
|
$rwPrice = $value->rw_price * 10;
|
|
|
|
|
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($value->tdz_price)){
|
|
|
|
@ -153,40 +153,40 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
if(isset($value->wz_price)){
|
|
|
|
|
if($value->wz_price > 0){
|
|
|
|
|
$wzPrice = $value->wz_price * 10;
|
|
|
|
|
$seat_type .= '"WZ":"¥'.$value->wz_price.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($value->edz_price)){
|
|
|
|
|
if($value->edz_price > 0){
|
|
|
|
|
$seat_type .= '"O":"¥'.$value->edz_price.'",';
|
|
|
|
|
$seat_type .= '"O":"¥'.$value->edz_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($value->ydz_price)){
|
|
|
|
|
if($value->ydz_price > 0){
|
|
|
|
|
$seat_type .= '"M":"¥'.$value->ydz_price.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(isset($value->dw_price)){
|
|
|
|
|
if($value->dw_price > 0){
|
|
|
|
|
$seat_type .= '"F":"¥'.$value->dw_price.'",';
|
|
|
|
|
$seat_type .= '"F":"¥'.$value->dw_price.'",';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"';
|
|
|
|
@ -198,16 +198,16 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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");
|
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
|
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
|
|
|
|
}else{
|
|
|
|
|
$isCache = false;
|
|
|
|
@ -219,48 +219,48 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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");
|
|
|
|
|
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 = new stdClass();
|
|
|
|
|
$ReturnData->data->seven = $iseven;
|
|
|
|
|
$ReturnData->data->cache = $isCache;
|
|
|
|
|
$ReturnData->data->supplier = 'ctrip';
|
|
|
|
@ -269,7 +269,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$obj = array();
|
|
|
|
|
$i = 0;
|
|
|
|
|
$PriceStr = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//数据解析
|
|
|
|
|
if(!empty($ResponseData->Trains)){
|
|
|
|
|
foreach ($ResponseData->Trains as $TrainInfo){
|
|
|
|
@ -285,82 +285,82 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$SeaType .= '"WZ":"¥'.$Seats->Price.'",';
|
|
|
|
|
$wzNum = $Seats->TicketLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($Seats->SeatName == '硬座'){
|
|
|
|
|
$yzPrice = $Seats->Price * 10;
|
|
|
|
|
$SeaType .= '"1":"'.$yzPrice.'","A1":"¥'.$Seats->Price.'",';
|
|
|
|
|
$SeaType .= '"1":"'.$yzPrice.'","A1":"¥'.$Seats->Price.'",';
|
|
|
|
|
$yzNum = $Seats->TicketLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($Seats->SeatName == '二等座'){
|
|
|
|
|
$SeaType .= '"O":"¥'.$Seats->Price.'",';
|
|
|
|
|
$SeaType .= '"O":"¥'.$Seats->Price.'",';
|
|
|
|
|
$edzNum = $Seats->TicketLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($Seats->SeatName == '一等座'){
|
|
|
|
|
$SeaType .= '"M":"¥'.$Seats->Price.'",';
|
|
|
|
|
$SeaType .= '"M":"¥'.$Seats->Price.'",';
|
|
|
|
|
$ydzNum = $Seats->TicketLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($Seats->SeatName == '商务座'){
|
|
|
|
|
$swzPrice = $Seats->Price * 10;
|
|
|
|
|
$SeaType .= '"9":"'.$swzPrice.'","A9":"¥'.$Seats->Price.'",';
|
|
|
|
|
$SeaType .= '"9":"'.$swzPrice.'","A9":"¥'.$Seats->Price.'",';
|
|
|
|
|
$swzNum = $Seats->TicketLeft;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($Seats->SeatName == '硬卧上'){
|
|
|
|
|
$ywPrice = $Seats->Price * 10;
|
|
|
|
|
$SeaType .= '"3":"'.$ywPrice.'","A3":"¥'.$Seats->Price.'",';
|
|
|
|
|
$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.'",';
|
|
|
|
|
$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) : '';
|
|
|
|
@ -375,12 +375,12 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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++;
|
|
|
|
@ -395,20 +395,20 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询经停站(基于携程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');
|
|
|
|
@ -441,19 +441,19 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
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) : '';
|
|
|
|
@ -465,13 +465,13 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$this->ctrip_model->AddOrUpdate($data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询中转方案(基于携程api)
|
|
|
|
|
public function gettraintrainsfer(){
|
|
|
|
|
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{
|
|
|
|
@ -480,16 +480,16 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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){
|
|
|
|
@ -503,7 +503,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
print_r(json_encode($ResponseData));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//火车移动端数据接口
|
|
|
|
|
public function get_train(){
|
|
|
|
|
$train_date = $this->input->get('date');
|
|
|
|
@ -512,19 +512,19 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
|
exit('传参错误!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$back_json = $this->ctripApi($train_date,$fromStation,$toStation,true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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:港澳台寄送费用
|
|
|
|
@ -536,7 +536,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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);
|
|
|
|
@ -592,24 +592,24 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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;
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.75;
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.5;
|
|
|
|
|
$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;
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatPriceRMB = $value;
|
|
|
|
|
if($fromStation == 'LSO' || $toStation == 'LSO'){
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 33;
|
|
|
|
|
}else{
|
|
|
|
@ -619,7 +619,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$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;
|
|
|
|
@ -627,7 +627,7 @@ class innerTrainSearch extends CI_Controller{
|
|
|
|
|
$return_data->result[$i]->SeatList[$j]->SeatInventory = 0;
|
|
|
|
|
$soldoutnums++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|