From 288272d0214f7d7da76bddeaf0d392b077b6a590 Mon Sep 17 00:00:00 2001 From: cyc Date: Sun, 16 Sep 2018 12:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=94=E7=89=9B=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tuniu/controllers/tuniu_train.php | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) 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); }