|
|
@ -2,7 +2,7 @@
|
|
|
|
if (!defined('BASEPATH'))
|
|
|
|
if (!defined('BASEPATH'))
|
|
|
|
exit('No direct script access allowed');
|
|
|
|
exit('No direct script access allowed');
|
|
|
|
|
|
|
|
|
|
|
|
class searchnew extends CI_Controller{
|
|
|
|
class search extends CI_Controller{
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct(){
|
|
|
|
public function __construct(){
|
|
|
|
parent::__construct();
|
|
|
|
parent::__construct();
|
|
|
@ -11,13 +11,7 @@ class searchnew extends CI_Controller{
|
|
|
|
|
|
|
|
|
|
|
|
//查询聚合余票接口,对返回的数据进行处理
|
|
|
|
//查询聚合余票接口,对返回的数据进行处理
|
|
|
|
public function index($train_date=null,$fromStation=null,$toStation=null){
|
|
|
|
public function index($train_date=null,$fromStation=null,$toStation=null){
|
|
|
|
//定义一些变量
|
|
|
|
|
|
|
|
$cache = 'no';
|
|
|
|
|
|
|
|
$flag = true;
|
|
|
|
|
|
|
|
$juheTrainInfo = '';
|
|
|
|
|
|
|
|
set_time_limit(0);
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
|
|
|
|
//判断数据是否合法
|
|
|
|
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
if(!$train_date || !$fromStation || !$toStation){
|
|
|
|
exit('传参不能为空!');
|
|
|
|
exit('传参不能为空!');
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
@ -28,96 +22,47 @@ class searchnew extends CI_Controller{
|
|
|
|
exit('toStation:参数错误!');
|
|
|
|
exit('toStation:参数错误!');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->train_date = $train_date;
|
|
|
|
$this->train_date = $train_date;
|
|
|
|
$now_time = time();
|
|
|
|
//$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
|
|
|
|
$differ_time = (strtotime($train_date) - $now_time) / 86400;
|
|
|
|
$url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
|
|
|
|
if($differ_time <= 29){
|
|
|
|
$back_data = $this->get_http($url);
|
|
|
|
//调用聚合搜索模块
|
|
|
|
|
|
|
|
$juheTrainInfo = $this->juheSearch($train_date,$fromStation,$toStation);
|
|
|
|
|
|
|
|
if(empty($juheTrainInfo)){
|
|
|
|
|
|
|
|
$flag = 'error';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$flag = 'cache';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调用数据处理模块。
|
|
|
|
|
|
|
|
$returnJson = $this->dataOperate($juheTrainInfo,$flag,$fromStation,$toStation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//调用拼接处理模块
|
|
|
|
//特殊车次处理(贵阳 -- 重庆)
|
|
|
|
$trainjson = $this->createTrainJson($returnJson);
|
|
|
|
/*if(($fromStation == 'GIW') && ($toStation == 'CQW') && (strtotime($train_date) - strtotime('2018-01-16') >= 0)){
|
|
|
|
|
|
|
|
exit('{"httpstatus":200,"reason":"特殊车次不开车","data":{"result":""}}');
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
print_r($trainjson);
|
|
|
|
$firstdata = $back_data;
|
|
|
|
die();
|
|
|
|
$return_data = new stdClass();
|
|
|
|
}
|
|
|
|
$cache = 'no';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(empty($back_data) || empty(json_decode($back_data)->result)){
|
|
|
|
//搜索模块
|
|
|
|
$obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
|
|
|
|
function juheSearch($train_date,$fromStation,$toStation){
|
|
|
|
if($obj){
|
|
|
|
$url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
|
|
|
|
$back_data = $obj->tpc_content;
|
|
|
|
$this->url = $url;
|
|
|
|
$cache = 'yes';
|
|
|
|
$juheTrainInfo = $this->get_http($url);
|
|
|
|
$this->cache = true;
|
|
|
|
if($this->validateJuhe($juheTrainInfo)){
|
|
|
|
$reason = '接口数据为空,调用缓存';
|
|
|
|
return $juheTrainInfo;
|
|
|
|
log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|调用缓存号:'.$obj->tpc_sn.'|缓存生成的时间:'.$obj->tpc_datetime);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
return null;
|
|
|
|
$reason = '接口数据为空,缓存也为空';
|
|
|
|
}
|
|
|
|
log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|缓存为空');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//缓存处理模块(包含缓存处理)
|
|
|
|
|
|
|
|
function dataOperate($trainInfo,$flag,$fromStation,$toStation){
|
|
|
|
|
|
|
|
if($flag == 'error'){
|
|
|
|
|
|
|
|
$research = $this->juheSearch($this->train_date,$fromStation,$toStation);
|
|
|
|
|
|
|
|
if($this->validateJuhe($research)){
|
|
|
|
|
|
|
|
$trainInfo = $research;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$flag = 'cache';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($flag == 'cache'){
|
|
|
|
|
|
|
|
$cacheTrainInfo = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
|
|
|
|
|
|
|
|
if(empty($cacheTrainInfo)){
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$cache_time = $cacheTrainInfo->tpc_datetime;
|
|
|
|
|
|
|
|
$now_time = time();
|
|
|
|
|
|
|
|
$differ_time = ($now_time - strtotime($cache_time)) / 86400;
|
|
|
|
|
|
|
|
if($differ_time >= 7){
|
|
|
|
|
|
|
|
$this->delete_traincache($fromStation,$toStation);
|
|
|
|
|
|
|
|
$research = $this->juheSearch(strtotime('+7day'),$fromStation,$toStation);
|
|
|
|
|
|
|
|
if($this->validateJuhe($research)){
|
|
|
|
|
|
|
|
$trainInfo = $research;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$reason = json_decode($back_data)->reason;
|
|
|
|
|
|
|
|
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$trainInfo);
|
|
|
|
|
|
|
|
return $trainInfo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//字符串拼接模块
|
|
|
|
|
|
|
|
function createTrainJson($returnJson){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(empty($returnJson)){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$return_data = new stdClass();
|
|
|
|
|
|
|
|
$return_data->data = new stdClass();
|
|
|
|
|
|
|
|
$return_data->httpstatus = 200;
|
|
|
|
$return_data->httpstatus = 200;
|
|
|
|
//$return_data->reason = $reason;
|
|
|
|
$return_data->reason = $reason;
|
|
|
|
//$return_data->cache = $cache;
|
|
|
|
$return_data->cache = $cache;
|
|
|
|
|
|
|
|
$return_data->data = new stdClass();
|
|
|
|
$return_data->data->result = array();
|
|
|
|
$return_data->data->result = array();
|
|
|
|
$return_data->data->map = new stdClass();
|
|
|
|
$return_data->data->map = new stdClass();
|
|
|
|
$obj = array();
|
|
|
|
$obj = array();
|
|
|
|
$i = 0;
|
|
|
|
$i = 0;
|
|
|
|
$pricestr = '';
|
|
|
|
$pricestr = '';
|
|
|
|
//print_r(json_decode($returnJson));
|
|
|
|
if(!empty(json_decode($back_data)->result->list)){
|
|
|
|
//die();
|
|
|
|
foreach (json_decode($back_data)->result->list as $value){
|
|
|
|
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->from_station_code] = $value->from_station_name;
|
|
|
|
$obj[$value->to_station_code] = $value->to_station_name;
|
|
|
|
$obj[$value->to_station_code] = $value->to_station_name;
|
|
|
|
$seat_type = '';
|
|
|
|
$seat_type = '';
|
|
|
@ -196,13 +141,12 @@ class searchnew extends CI_Controller{
|
|
|
|
$i++;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$return_data->data->map = (object)$obj;
|
|
|
|
$return_data->data->map = (object)$obj;
|
|
|
|
print_r($return_data);
|
|
|
|
print_r(json_encode($return_data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取价格
|
|
|
|
//获取价格(废弃)
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
fromStationCode:出发站三字码
|
|
|
|
fromStationCode:出发站三字码
|
|
|
|
toStationCode:终点站三字码
|
|
|
|
toStationCode:终点站三字码
|
|
|
@ -221,16 +165,6 @@ class searchnew extends CI_Controller{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//验证聚合返回的信息是否正确
|
|
|
|
|
|
|
|
function validateJuhe($trainInfo){
|
|
|
|
|
|
|
|
if(!empty($trainInfo) && !empty(json_decode($trainInfo)->result)){
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//余票转换
|
|
|
|
//余票转换
|
|
|
|
function ticket_exchange($num){
|
|
|
|
function ticket_exchange($num){
|
|
|
|
if(isset($this->cache)){
|
|
|
|
if(isset($this->cache)){
|