整理火车搜索接口到一个目录下
parent
16bf3af463
commit
6f515d6f8a
@ -0,0 +1,478 @@
|
||||
<?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 juheApi($train_date=null,$fromStation=null,$toStation=null){
|
||||
//定义一些变量
|
||||
$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);
|
||||
print_r($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->httpstatus = 200;
|
||||
$return_data->seveth = $this->seveth;
|
||||
$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){
|
||||
//接收参数
|
||||
if(!$date && !$from && !$to){
|
||||
$date = $this->input->get_post('date');
|
||||
$from = $this->input->get_post('from');
|
||||
$to = $this->input->get_post('to');
|
||||
}
|
||||
|
||||
$TrainNo = $this->input->get_post('TrainNo');
|
||||
|
||||
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->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;
|
||||
print_r(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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
class BIZ_intel_train_model extends CI_Model {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
//查询火车列表信息
|
||||
public function get_train_info($trainFromCode,$trainToCode){
|
||||
if($trainFromCode == 'CHBJ'){
|
||||
$add = "OR tl.trainFromCode = 'CHPW'";
|
||||
}else{
|
||||
$add = "";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
tl.trainNo,
|
||||
tl.trainFrom,
|
||||
tl.trainFromCode,
|
||||
(select s_country from TrainStation_intel where s_code = tl.trainFromCode) as from_country,
|
||||
tl.trainTo,
|
||||
tl.trainToCode,
|
||||
(select s_country from TrainStation_intel where s_code = tl.trainToCode) as to_country,
|
||||
tl.trainType,
|
||||
tl.train_no,
|
||||
tl.trainUse,
|
||||
tl.RunTime,
|
||||
tl.departTime,
|
||||
(select top 1 trainArrive from trainlistDetail where train_no = tl.train_no order by trainOrder desc) as arriveTime,
|
||||
tl.UseDay,
|
||||
tl.DateRule,
|
||||
tl.TrainMessage,
|
||||
tp.seatPriceInfo2
|
||||
FROM
|
||||
trainlist tl
|
||||
left join
|
||||
trainPrice tp
|
||||
on
|
||||
tl.train_no = tp.train_no
|
||||
WHERE
|
||||
tl.isGlobal = 1
|
||||
AND
|
||||
(tl.trainFromCode = '{$trainFromCode}' {$add})
|
||||
AND
|
||||
tl.trainToCode = '{$trainToCode}'
|
||||
AND
|
||||
tl.DateRule != ''
|
||||
AND
|
||||
tp.seatPriceInfo2 IS NOT NULL
|
||||
order by departTime asc
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_code_by_name($name){
|
||||
$sql = "select s_code from TrainStation_intel where s_ename = '{$name}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_seatname($seat_code){
|
||||
$sql = "select Seat_EName1,Seat_Pic from TrainSeat_Intel where Seat_code = '{$seat_code}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
//获取一列指定火车数据
|
||||
public function get_one_train($train_no){
|
||||
$sql = "
|
||||
SELECT
|
||||
*,
|
||||
(select s_country from TrainStation_intel where trainFromCode = s_code ) as From_country,
|
||||
(select s_country from TrainStation_intel where trainToCode = s_code ) as To_country,
|
||||
(select top 1 trainArrive from trainlistDetail where train_no = tl.train_no order by trainOrder desc) as localarriveTime
|
||||
FROM
|
||||
trainlist tl
|
||||
LEFT JOIN
|
||||
trainPrice tp
|
||||
ON
|
||||
tl.train_no = tp.train_no
|
||||
WHERE
|
||||
tl.train_no = '{$train_no}'
|
||||
AND
|
||||
isGlobal = 1
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_allinteltrain(){
|
||||
$sql = "
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
TrainStation_intel
|
||||
LEFT JOIN
|
||||
trainlist
|
||||
ON
|
||||
s_code = trainFromCode
|
||||
WHERE
|
||||
trainFrom != 'NULL'
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_seat_info($seat_code){
|
||||
$sql = "SELECT Seat_CName,Seat_EName1 FROM TrainSeat_Intel WHERE Seat_Code = '{$seat_code}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_train_station($train_no){
|
||||
$sql = "SELECT * FROM trainlistDetail WHERE train_no = '{$train_no}' order by trainOrder asc";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_allstations(){
|
||||
$sql = "SELECT * FROM TrainStation_intel where station_id != 1";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function ch_allstations(){
|
||||
$sql = "select
|
||||
tsi1.s_ename as fromStationName,
|
||||
tsi1.s_country as fromStationCountry,
|
||||
tsi2.s_ename as toStationName,
|
||||
tsi2.s_country as toStationCountry,
|
||||
tsi_Message
|
||||
from TrainSearch_intel
|
||||
left join
|
||||
TrainStation_intel tsi1
|
||||
ON
|
||||
tsi1.station_id = tsi_FromStation
|
||||
left join
|
||||
TrainStation_intel tsi2
|
||||
ON
|
||||
tsi2.station_id = tsi_ToStation
|
||||
where tsi1.s_country = 'china' or tsi2.s_country = 'china'
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_train_rules($station_id){
|
||||
if($station_id == 11){
|
||||
$station = "or tsi_FromStation = 10";
|
||||
}elseif($station_id == 2){
|
||||
$station = "or tsi_FromStation = 9";
|
||||
}else{
|
||||
$station = "";
|
||||
}
|
||||
$sql = "SELECT
|
||||
S_ename,s_country,tsi_Message
|
||||
FROM
|
||||
TrainSearch_intel
|
||||
LEFT JOIN
|
||||
TrainStation_intel
|
||||
ON
|
||||
tsi_ToStation = station_id
|
||||
where
|
||||
tsi_FromStation = '{$station_id}'";
|
||||
$sql .= $station;
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function ch_train_rules($station_id){
|
||||
if($station_id == 11){
|
||||
$station = "or tsi_FromStation = 10";
|
||||
}elseif($station_id == 2){
|
||||
$station = "or tsi_FromStation = 9";
|
||||
}else{
|
||||
$station = "";
|
||||
}
|
||||
$sql = "SELECT
|
||||
S_ename,s_country,tsi_Message
|
||||
FROM
|
||||
TrainSearch_intel
|
||||
LEFT JOIN
|
||||
TrainStation_intel
|
||||
ON
|
||||
tsi_ToStation = station_id
|
||||
where
|
||||
(tsi_FromStation = ?)
|
||||
";
|
||||
$sql .= $station;
|
||||
$query = $this->HT->query($sql,array($station_id));
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue