添加火车数据缓存调用条件

hotfix/远程访问多媒体中心
cyc 8 years ago
parent 1fd5c07562
commit 84929b7328

@ -57,16 +57,15 @@ class search extends CI_Controller{
function Searchtrain($train_date,$fromStation,$toStation){
$this->train_date = $train_date;
$now_time = time();
$differ_time = (strtotime($train_date) - $now_time) / 86400;
$this->differ_time = (strtotime($train_date) - $now_time) / 86400;
$this->seveth = 'no';
//屏蔽掉超过预售期的搜索,提高速度
if($differ_time > 29){
if($this->differ_time > 29){
$train_date = date('Y-m-d',strtotime('+7day'));
$this->seveth = 'yes';
}
$url = JUHE_TRAIN_CX_API.'?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$this->url = $url;
$train_info = $this->get_http($url);
$this->url = JUHE_TRAIN_CX_API.'?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$train_info = $this->get_http($this->url);
return $train_info;
}
@ -85,15 +84,22 @@ class search extends CI_Controller{
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$search_return);
$operate_data = $search_return;
}else{
$cache_train_info = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
//添加缓存调用时间判断
if($this->differ_time <= 5){
$cache_train_info = NULL;
}else{
$cache_train_info = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
}
//判断缓存是否为空
if(empty($cache_train_info)){
log_message('error','TRAIN 查询为空的链接:'.$this->url.'|出错的原因:'.$this->reason.'|缓存为空');
$operate_data = NULL;
}else{
$cache_time = $cache_train_info->tpc_datetime;
$now_time = time();
$differ_time = ($now_time - strtotime($cache_time)) / 86400;
if($differ_time >= 3){
$cache_differ_time = ($now_time - strtotime($cache_time)) / 86400;
if($cache_differ_time >= 3){
$this->BIZ_train_model->delete_traincache($fromStation,$toStation);
log_message('error','TRAIN 查询为空的链接:'.$this->url.'|出错的原因:'.$this->reason.'|缓存超时,已经删除');
$operate_data = NULL;

Loading…
Cancel
Save