diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index 7a254903..6c8c79d7 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -61,26 +61,35 @@ class Tuniu_train extends CI_Controller{ "data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" } }'; $back_data = post_tuniu($url,$post_data,$method = 'POST'); - + + //print_r(json_decode($back_data));die(); + //如果数据为空则调用缓存,有数据则进行数据存储 if(empty($back_data)){ log_message('error','tuniutrain 接口未响应|数据源:'.$fromStation.'|'.$toStation.'|'.$date); - $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); - $back_data = $trainCache->tpc_content; - $isCache = true; + if($differ <= 5){ + $back_data = null; + }else{ + $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); + $back_data = $trainCache->tpc_content; + $isCache = true; + } }else{ if(empty(json_decode($back_data)->data)){ $error = json_decode($back_data); - $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); - if(!empty($trainCache)){ - $back_data = $trainCache->tpc_content; - $isCache = true; - log_message('error','tuniutrain 查询出错|'.$error->errorMsg); - }else{ + if($error->returnCode == '201'){ $back_data = null; - log_message('error','tuniutrain 缓存为空|'.$fromStation.'|'.$toStation.'|'.$date); + }else{ + $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); + if(!empty($trainCache)){ + $back_data = $trainCache->tpc_content; + $isCache = true; + log_message('error','tuniutrain 查询出错|'.$error->errorMsg); + }else{ + $back_data = null; + log_message('error','tuniutrain 缓存为空|'.$fromStation.'|'.$toStation.'|'.$date); + } } - }else{ $this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data); }