From 97349dba5894dede83fb47b9ed8ab4a8067dd029 Mon Sep 17 00:00:00 2001 From: cyc Date: Wed, 12 Sep 2018 09:37:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E8=81=9A=E5=90=88=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=A0=BC=E5=BC=8F=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/third_party/train/controllers/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/third_party/train/controllers/search.php b/application/third_party/train/controllers/search.php index ee023727..6677baca 100644 --- a/application/third_party/train/controllers/search.php +++ b/application/third_party/train/controllers/search.php @@ -206,7 +206,7 @@ class search extends CI_Controller{ $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.'||'.$value->train_start_date.'||||||||'.$this->ticket_exchange($value->gjrw_price,$value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_price,$value->qtxb_num).'|'.$this->ticket_exchange($value->rw_price,$value->rw_num).'|'.$this->ticket_exchange($value->rz_price,$value->rz_num).'|'.$this->ticket_exchange($value->tdz_price,$value->tdz_num).'|'.$this->ticket_exchange($value->wz_price,$value->wz_num).'||'.$this->ticket_exchange($value->yw_price,$value->yw_num).'|'.$this->ticket_exchange($value->yz_price,$value->yz_num).'|'.$this->ticket_exchange($value->edz_price,$value->edz_num).'|'.$this->ticket_exchange($value->ydz_price,$value->ydz_num).'|'.$this->ticket_exchange($value->swz_price,$value->swz_num).'|'.$this->ticket_exchange($value->dw_price,$value->dw_num).'||'; + $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.'||||||||'.$this->ticket_exchange($value->gjrw_price,$value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_price,$value->qtxb_num).'|'.$this->ticket_exchange($value->rw_price,$value->rw_num).'|'.$this->ticket_exchange($value->rz_price,$value->rz_num).'|'.$this->ticket_exchange($value->tdz_price,$value->tdz_num).'|'.$this->ticket_exchange($value->wz_price,$value->wz_num).'||'.$this->ticket_exchange($value->yw_price,$value->yw_num).'|'.$this->ticket_exchange($value->yz_price,$value->yz_num).'|'.$this->ticket_exchange($value->edz_price,$value->edz_num).'|'.$this->ticket_exchange($value->ydz_price,$value->ydz_num).'|'.$this->ticket_exchange($value->swz_price,$value->swz_num).'|'.$this->ticket_exchange($value->dw_price,$value->dw_num).'||'; $data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}'; $return_data->data->price[$i] = $data; $i++; From 05f48da4237edd0782efd72fda32171edc5d7e27 Mon Sep 17 00:00:00 2001 From: cyc Date: Wed, 12 Sep 2018 11:13:46 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=BB=99=E9=80=94=E7=89=9B=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=B7=BB=E5=8A=A0=E5=AE=B9=E9=94=99=E5=92=8C?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E8=B0=83=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/train/controllers/search.php | 2 +- .../train/models/BIZ_train_model.php | 4 +- .../tuniu/controllers/tuniu_train.php | 224 ++++++++++-------- .../tuniu/helpers/tuniu_helper.php | 24 +- .../tuniu/models/tuniuprice_model.php | 61 +++-- 5 files changed, 176 insertions(+), 139 deletions(-) diff --git a/application/third_party/train/controllers/search.php b/application/third_party/train/controllers/search.php index 6677baca..0e217f82 100644 --- a/application/third_party/train/controllers/search.php +++ b/application/third_party/train/controllers/search.php @@ -93,7 +93,7 @@ class search extends CI_Controller{ if($this->differ_time <= 5){ $cache_train_info = NULL; }else{ - $cache_train_info = $this->BIZ_train_model->get_train_info($fromStation,$toStation); + $cache_train_info = $this->BIZ_train_model->get_train_cache($fromStation,$toStation); } //判断缓存是否为空 diff --git a/application/third_party/train/models/BIZ_train_model.php b/application/third_party/train/models/BIZ_train_model.php index ebad9cd0..3cebc984 100644 --- a/application/third_party/train/models/BIZ_train_model.php +++ b/application/third_party/train/models/BIZ_train_model.php @@ -8,7 +8,7 @@ class BIZ_train_model extends CI_Model { $this->INFO = $this->load->database('INFO', TRUE); } - //新增或更新价格 + //新增或更新缓存 public function addOrUpdate($tpc_from_station,$tpc_to_station,$tpc_content){ $sql = "IF NOT EXISTS( SELECT 1 @@ -49,7 +49,7 @@ class BIZ_train_model extends CI_Model { //获取缓存的火车信息 //如果读取到缓存是7天以前的数据就不返回任何数据,并且将其删除。 - public function get_train_info($tpc_from_station,$tpc_to_station){ + public function get_train_cache($tpc_from_station,$tpc_to_station){ $sql = "SELECT * FROM diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index cf81e430..ce2872ef 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -40,123 +40,143 @@ class Tuniu_train extends CI_Controller{ if(!$date || !$fromStation || !$toStation){ exit('传参错误!'); }else{ + //做超过预售期的处理查询 + $isCache = false; + $iseven = false; + $now_time = time(); + $differ = (strtotime($date) - $now_time) / 86400; + if($differ > 29){ + $date = date('Y-m-d',strtotime('+7day')); + $iseven = true; + } + + //途牛报文拼接 $sign = $this->create_sign(); - $url = TUNIU_URL.'/train/search'; - $time = date('Y-m-d H:i:s',time()); - $post_data = '{ - "apiKey": "'.TUNIU_KEY.'", - "sign": "'.$sign.'", - "timestamp": "'.$time.'", - "data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" } - }'; - $back_data = post_tuniu($url,$post_data,$method = 'POST'); - if(empty(json_decode($back_data)->data)){ - log_message('error','tuniu:'.json_encode($post_data)); - } - //print_r(json_decode($back_data)); + $url = TUNIU_URL.'/train/search'; + $time = date('Y-m-d H:i:s',time()); + $post_data = '{ + "apiKey": "'.TUNIU_KEY.'", + "sign": "'.$sign.'", + "timestamp": "'.$time.'", + "data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" } + }'; + $back_data = post_tuniu($url,$post_data,$method = 'POST'); + + //如果数据为空则调用缓存,有数据则进行数据存储 + if(empty(json_decode($back_data)->data)){ + $error = json_decode($back_data); + $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); + $back_data = $trainCache->tpc_content; + $isCache = true; + log_message('error','tuniutrain 出错的原因:'.json_decode($back_data)); + }else{ + $this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data); + } - $return_data = new stdClass(); - $return_data->returnCode = json_decode($back_data)->returnCode; - //echo $return_data->returnCode; - $return_data->httpstatus = 200; - $return_data->data = new stdClass(); - $return_data->data->result = array(); - $return_data->data->map = new stdClass(); - $obj = array(); - $i = 0; - $pricestr = ''; - if(!empty(json_decode($back_data)->data)){ - foreach (json_decode($back_data)->data as $value){ - $obj[$value->fromStationCode] = $value->fromStationName; - $obj[$value->toStationCode] = $value->toStationName; - $seat_type = ''; - if(isset($value->gjrwXiaPrice)){ - if(is_numeric($value->gjrwXiaPrice)){ - $gjrwXiaPrice = $value->gjrwXiaPrice * 10; - $seat_type .= '"6":"'.$gjrwXiaPrice.'","A6":"¥'.$value->gjrwXiaPrice.'",'; + //途牛数据格式转换 + $return_data = new stdClass(); + $return_data->returnCode = json_decode($back_data)->returnCode; + //echo $return_data->returnCode; + $return_data->httpstatus = 200; + $return_data->data = new stdClass(); + $return_data->data->result = array(); + $return_data->data->map = new stdClass(); + $return_data->data->seven = $iseven; + $return_data->data->cache = $isCache; + $obj = array(); + $i = 0; + $pricestr = ''; + if(!empty(json_decode($back_data)->data)){ + foreach (json_decode($back_data)->data as $value){ + $obj[$value->fromStationCode] = $value->fromStationName; + $obj[$value->toStationCode] = $value->toStationName; + $seat_type = ''; + if(isset($value->gjrwXiaPrice)){ + if(is_numeric($value->gjrwXiaPrice)){ + $gjrwXiaPrice = $value->gjrwXiaPrice * 10; + $seat_type .= '"6":"'.$gjrwXiaPrice.'","A6":"¥'.$value->gjrwXiaPrice.'",'; + } } - } - if(isset($value->qtxbPrice)){ - if(is_numeric($value->qtxbPrice)){ - $seat_type .= '"H":"¥'.$value->qtxbPrice.'",'; + if(isset($value->qtxbPrice)){ + if(is_numeric($value->qtxbPrice)){ + $seat_type .= '"H":"¥'.$value->qtxbPrice.'",'; + } } - } - if(isset($value->rwPrice)){ - if(is_numeric($value->rwPrice)){ - $rwPrice = $value->rwPrice * 10; - $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rwPrice.'",'; + if(isset($value->rwPrice)){ + if(is_numeric($value->rwPrice)){ + $rwPrice = $value->rwPrice * 10; + $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rwPrice.'",'; + } } - } - if(isset($value->rzPrice)){ - if(is_numeric($value->rzPrice)){ - $rzPrice = $value->rzPrice * 10; - $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rzPrice.'",'; + if(isset($value->rzPrice)){ + if(is_numeric($value->rzPrice)){ + $rzPrice = $value->rzPrice * 10; + $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rzPrice.'",'; + } } - } - if(isset($value->tdzPrice)){ - if(is_numeric($value->tdzPrice)){ - $seat_type .= '"P":"¥'.$value->tdzPrice.'",'; + if(isset($value->tdzPrice)){ + if(is_numeric($value->tdzPrice)){ + $seat_type .= '"P":"¥'.$value->tdzPrice.'",'; + } } - } - if(isset($value->wzPrice)){ - if(is_numeric($value->wzPrice)){ - $wzPrice = $value->wzPrice * 10; - $seat_type .= '"WZ":"¥'.$value->wzPrice.'",'; + if(isset($value->wzPrice)){ + if(is_numeric($value->wzPrice)){ + $wzPrice = $value->wzPrice * 10; + $seat_type .= '"WZ":"¥'.$value->wzPrice.'",'; + } } - } - if(isset($value->ywPrice)){ - if(is_numeric($value->ywPrice)){ - $ywPrice = $value->ywPrice * 10; - $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->ywPrice.'",'; + if(isset($value->ywPrice)){ + if(is_numeric($value->ywPrice)){ + $ywPrice = $value->ywPrice * 10; + $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->ywPrice.'",'; + } } - } - if(isset($value->yzPrice)){ - if(is_numeric($value->yzPrice)){ - $yzPrice = $value->yzPrice * 10; - $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yzPrice.'",'; + if(isset($value->yzPrice)){ + if(is_numeric($value->yzPrice)){ + $yzPrice = $value->yzPrice * 10; + $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yzPrice.'",'; + } } - } - if(isset($value->edzPrice)){ - if(is_numeric($value->edzPrice)){ - $seat_type .= '"O":"¥'.$value->edzPrice.'",'; + if(isset($value->edzPrice)){ + if(is_numeric($value->edzPrice)){ + $seat_type .= '"O":"¥'.$value->edzPrice.'",'; + } } - } - if(isset($value->ydzPrice)){ - if(is_numeric($value->ydzPrice)){ - $seat_type .= '"M":"¥'.$value->ydzPrice.'",'; + if(isset($value->ydzPrice)){ + if(is_numeric($value->ydzPrice)){ + $seat_type .= '"M":"¥'.$value->ydzPrice.'",'; + } } - } - if(isset($value->swzPrice)){ - if(is_numeric($value->swzPrice)){ - $swzPrice = $value->swzPrice * 10; - $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swzPrice.'",'; + if(isset($value->swzPrice)){ + if(is_numeric($value->swzPrice)){ + $swzPrice = $value->swzPrice * 10; + $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swzPrice.'",'; + } } + $pricestr = $seat_type.'"train_no":'.'"'.$value->trainNo.'"'; + + //对余票数进行验证 + $value->gjrwNum = isset($value->gjrwNum) ? ticket_exchange($value->gjrwNum,$iseven) : ''; + $value->rwNum = isset($value->rwNum) ? ticket_exchange($value->rwNum,$iseven) : ''; + $value->rzNum = isset($value->rzNum)?ticket_exchange($value->rzNum,$iseven) : ''; + $value->tdzNum = isset($value->tdzNum)?ticket_exchange($value->tdzNum,$iseven) : ''; + $value->wzNum = isset($value->wzNum)?ticket_exchange($value->wzNum,$iseven) : ''; + $value->ywNum = isset($value->ywNum)?ticket_exchange($value->ywNum,$iseven) : ''; + $value->yzNum = isset($value->yzNum)?ticket_exchange($value->yzNum,$iseven) : ''; + $value->edzNum = isset($value->edzNum)?ticket_exchange($value->edzNum,$iseven) : ''; + $value->ydzNum = isset($value->ydzNum)?ticket_exchange($value->ydzNum,$iseven) : ''; + $value->swzNum = isset($value->swzNum)?ticket_exchange($value->swzNum,$iseven) : ''; + $value->dwNum = isset($value->dwNum)?ticket_exchange($value->dwNum,$iseven) : ''; + + //余票字符串 + $return_data->data->result[$i] = '|预定|'.$value->trainNo.'|'.$value->trainCode.'|'.$value->fromStationName.'|'.$value->toStationName.'|'.$value->fromStationCode.'|'.$value->toStationCode.'|'.$value->startTime.'|'.$value->arriveTime.'|'.$value->runTime.'|'.$value->canBuyNow.'||'.date('Ymd',strtotime($value->trainStartDate)).'||||||||'.$value->gjrwNum.'||'.$value->rwNum.'|'.$value->rzNum.'|'.$value->tdzNum.'|'.$value->wzNum.'||'.$value->ywNum.'|'.$value->yzNum.'|'.$value->edzNum.'|'.$value->ydzNum.'|'.$value->swzNum.'|'.$value->dwNum.'||'; + $data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}'; + $return_data->data->price[$i] = $data; + $i++; } - $pricestr = $seat_type.'"train_no":'.'"'.$value->trainNo.'"'; - - //对余票数进行验证 - $value->gjrwNum = isset($value->gjrwNum) ? ticket_exchange($value->gjrwNum) : ''; - $value->rwNum = isset($value->rwNum) ? ticket_exchange($value->rwNum) : ''; - $value->rzNum = isset($value->rzNum)?ticket_exchange($value->rzNum) : ''; - $value->tdzNum = isset($value->tdzNum)?ticket_exchange($value->tdzNum) : ''; - $value->wzNum = isset($value->wzNum)?ticket_exchange($value->wzNum) : ''; - $value->ywNum = isset($value->ywNum)?ticket_exchange($value->ywNum) : ''; - $value->yzNum = isset($value->yzNum)?ticket_exchange($value->yzNum) : ''; - $value->edzNum = isset($value->edzNum)?ticket_exchange($value->edzNum) : ''; - $value->ydzNum = isset($value->ydzNum)?ticket_exchange($value->ydzNum) : ''; - $value->swzNum = isset($value->swzNum)?ticket_exchange($value->swzNum) : ''; - $value->dwNum = isset($value->dwNum)?ticket_exchange($value->dwNum) : ''; - - //余票字符串 - $return_data->data->result[$i] = '|预定|'.$value->trainNo.'|'.$value->trainCode.'|'.$value->fromStationName.'|'.$value->toStationName.'|'.$value->fromStationCode.'|'.$value->toStationCode.'|'.$value->startTime.'|'.$value->arriveTime.'|'.$value->runTime.'|'.$value->canBuyNow.'||'.date('Ymd',strtotime($value->trainStartDate)).'||||||||'.$value->gjrwNum.'||'.$value->rwNum.'|'.$value->rzNum.'|'.$value->tdzNum.'|'.$value->wzNum.'||'.$value->ywNum.'|'.$value->yzNum.'|'.$value->edzNum.'|'.$value->ydzNum.'|'.$value->swzNum.'|'.$value->dwNum.'||'; - $data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}'; - $return_data->data->price[$i] = $data; - $this->tuniuprice_model->addOrUpdate($value->trainNo,$value->trainCode,$value->fromStationCode,$value->toStationCode,json_encode($data)); - $i++; } - } - $return_data->data->map = (object)$obj; - print_r(json_encode($return_data)); + $return_data->data->map = (object)$obj; + print_r(json_encode($return_data)); } } diff --git a/application/third_party/tuniu/helpers/tuniu_helper.php b/application/third_party/tuniu/helpers/tuniu_helper.php index 1b5e1fa9..822429e6 100644 --- a/application/third_party/tuniu/helpers/tuniu_helper.php +++ b/application/third_party/tuniu/helpers/tuniu_helper.php @@ -14,16 +14,20 @@ } //余票转换 - function ticket_exchange($num){ - if(is_numeric($num)){ - if($num == 0){ - return '无'; - }elseif($num == 99){ - return '有'; - }else{ - return $num; - } - } + function ticket_exchange($num,$iseven){ + if($iseven){ + return '有'; + }else{ + if(is_numeric($num)){ + if($num == 0){ + return '无'; + }elseif($num >= 99){ + return '有'; + }else{ + return $num; + } + } + } } //发送请求函数 diff --git a/application/third_party/tuniu/models/tuniuprice_model.php b/application/third_party/tuniu/models/tuniuprice_model.php index c738b903..404ad70e 100644 --- a/application/third_party/tuniu/models/tuniuprice_model.php +++ b/application/third_party/tuniu/models/tuniuprice_model.php @@ -6,47 +6,60 @@ class tuniuprice_model extends CI_Model { $this->INFO = $this->load->database('INFO', TRUE); } - //¼۸ - public function addOrUpdate($TPL_Train_No,$TPL_Train_Code,$TPL_From_Station_Code,$TPL_To_Station_Code,$TPL_Price){ + //» + public function addOrUpdate($tpc_from_station,$tpc_to_station,$tpc_content){ $sql = "IF NOT EXISTS( SELECT 1 - FROM TrainPriceList - WHERE TPL_Train_Code = '$TPL_Train_Code' - AND TPL_From_Station_Code = '$TPL_From_Station_Code' - AND TPL_To_Station_Code = '$TPL_To_Station_Code' + FROM TrainPriceCache + WHERE + tpc_from_station = '$tpc_from_station' + AND tpc_to_station = '$tpc_to_station' ) BEGIN - INSERT INTO TrainPriceList + INSERT INTO TrainPriceCache ( - TPL_Train_No, - TPL_Train_Code, - TPL_From_Station_Code, - TPL_To_Station_Code, - TPL_Price, - TPL_Datetime, - TPL_Source + tpc_from_station, + tpc_to_station, + tpc_content, + tpc_datetime, + tpc_source ) VALUES ( - '$TPL_Train_No','$TPL_Train_Code','$TPL_From_Station_Code','$TPL_To_Station_Code','$TPL_Price',GETDATE(),'tuniu' + '$tpc_from_station','$tpc_to_station','$tpc_content',GETDATE(),'tuniu' ) END ELSE BEGIN - UPDATE TrainPriceList - SET - TPL_Train_No = '$TPL_Train_No', - TPL_Price = '$TPL_Price', - TPL_Datetime = GETDATE(), - TPL_Source = 'tuniu' - WHERE TPL_Train_Code = '$TPL_Train_Code' - AND TPL_From_Station_Code = '$TPL_From_Station_Code' - AND TPL_To_Station_Code = '$TPL_To_Station_Code' + UPDATE TrainPriceCache + SET tpc_from_station = '$tpc_from_station', + tpc_to_station = '$tpc_to_station', + tpc_content = '$tpc_content', + tpc_datetime = GETDATE(), + tpc_source = 'tuniu' + WHERE + tpc_from_station = '$tpc_from_station' + AND tpc_to_station = '$tpc_to_station' END "; $query = $this->INFO->query($sql); return $query; } + //ȡĻϢ + //ȡ7ǰݾͲκݣҽɾ + public function get_train_cache($tpc_from_station,$tpc_to_station){ + $sql = "SELECT + * + FROM + TrainPriceCache + WHERE + tpc_from_station = '$tpc_from_station' + AND + tpc_to_station = '$tpc_to_station'"; + $query = $this->INFO->query($sql); + return $query->row(); + } + //ȡ۸ public function get_price($fromStationCode,$toStationCode,$trainCode){ $sql = "SELECT From 11e38e86e6863ab5ffd48ecdb52f3f31440188b1 Mon Sep 17 00:00:00 2001 From: cyc Date: Wed, 12 Sep 2018 11:39:38 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=94=E7=89=9B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tuniu/controllers/tuniu_train.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index ce2872ef..b53e4fe1 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -63,14 +63,21 @@ class Tuniu_train extends CI_Controller{ $back_data = post_tuniu($url,$post_data,$method = 'POST'); //如果数据为空则调用缓存,有数据则进行数据存储 - if(empty(json_decode($back_data)->data)){ - $error = json_decode($back_data); + 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; - log_message('error','tuniutrain 出错的原因:'.json_decode($back_data)); }else{ - $this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data); + if(empty(json_decode($back_data)->data)){ + $error = json_decode($back_data); + $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); + $back_data = $trainCache->tpc_content; + $isCache = true; + log_message('error','tuniutrain 查询出错'.json_decode($back_data)); + }else{ + $this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data); + } } //途牛数据格式转换 @@ -79,10 +86,11 @@ class Tuniu_train extends CI_Controller{ //echo $return_data->returnCode; $return_data->httpstatus = 200; $return_data->data = new stdClass(); - $return_data->data->result = array(); - $return_data->data->map = new stdClass(); $return_data->data->seven = $iseven; $return_data->data->cache = $isCache; + $return_data->data->result = array(); + $return_data->data->map = new stdClass(); + $obj = array(); $i = 0; $pricestr = ''; @@ -155,7 +163,7 @@ class Tuniu_train extends CI_Controller{ } $pricestr = $seat_type.'"train_no":'.'"'.$value->trainNo.'"'; - //对余票数进行验证 + //对返回的数据进行容错处理 $value->gjrwNum = isset($value->gjrwNum) ? ticket_exchange($value->gjrwNum,$iseven) : ''; $value->rwNum = isset($value->rwNum) ? ticket_exchange($value->rwNum,$iseven) : ''; $value->rzNum = isset($value->rzNum)?ticket_exchange($value->rzNum,$iseven) : ''; @@ -167,6 +175,7 @@ class Tuniu_train extends CI_Controller{ $value->ydzNum = isset($value->ydzNum)?ticket_exchange($value->ydzNum,$iseven) : ''; $value->swzNum = isset($value->swzNum)?ticket_exchange($value->swzNum,$iseven) : ''; $value->dwNum = isset($value->dwNum)?ticket_exchange($value->dwNum,$iseven) : ''; + $value->runTime = isset($value->runTime)?$value->runTime : ''; //余票字符串 $return_data->data->result[$i] = '|预定|'.$value->trainNo.'|'.$value->trainCode.'|'.$value->fromStationName.'|'.$value->toStationName.'|'.$value->fromStationCode.'|'.$value->toStationCode.'|'.$value->startTime.'|'.$value->arriveTime.'|'.$value->runTime.'|'.$value->canBuyNow.'||'.date('Ymd',strtotime($value->trainStartDate)).'||||||||'.$value->gjrwNum.'||'.$value->rwNum.'|'.$value->rzNum.'|'.$value->tdzNum.'|'.$value->wzNum.'||'.$value->ywNum.'|'.$value->yzNum.'|'.$value->edzNum.'|'.$value->ydzNum.'|'.$value->swzNum.'|'.$value->dwNum.'||'; From 2bd56ea6816470c4a2918df4d51ac3eb9d508d98 Mon Sep 17 00:00:00 2001 From: cyc Date: Wed, 12 Sep 2018 12:01:57 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=94=E7=89=9B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tuniu/controllers/tuniu_train.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index b53e4fe1..7a254903 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -61,7 +61,7 @@ class Tuniu_train extends CI_Controller{ "data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" } }'; $back_data = post_tuniu($url,$post_data,$method = 'POST'); - + //如果数据为空则调用缓存,有数据则进行数据存储 if(empty($back_data)){ log_message('error','tuniutrain 接口未响应|数据源:'.$fromStation.'|'.$toStation.'|'.$date); @@ -72,9 +72,15 @@ class Tuniu_train extends CI_Controller{ if(empty(json_decode($back_data)->data)){ $error = json_decode($back_data); $trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation); - $back_data = $trainCache->tpc_content; - $isCache = true; - log_message('error','tuniutrain 查询出错'.json_decode($back_data)); + 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); } @@ -82,8 +88,12 @@ class Tuniu_train extends CI_Controller{ //途牛数据格式转换 $return_data = new stdClass(); - $return_data->returnCode = json_decode($back_data)->returnCode; - //echo $return_data->returnCode; + if(empty($back_data)){ + $return_data->returnCode = '404'; + }else{ + $return_data->returnCode = json_decode($back_data)->returnCode; + } + $return_data->httpstatus = 200; $return_data->data = new stdClass(); $return_data->data->seven = $iseven; From 9311b8ee86ce8a69474aca97db58869d24f3b188 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Wed, 12 Sep 2018 14:26:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=A7=A3=E5=86=B3AMP=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=B2=A1=E6=9C=89=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/controllers/amp.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/controllers/amp.php b/application/controllers/amp.php index 2895f5fa..740f9f9d 100644 --- a/application/controllers/amp.php +++ b/application/controllers/amp.php @@ -108,7 +108,8 @@ class Amp extends CI_Controller $this->InfoMetas_model->update($ic_id, 'AMP_STATUS', $amp_status); } - echo json_encode(array('name' => 'ok', 'value' => $this->lang->line('form_info_success'))); + $data[] = array('name' => 'ok', 'value' => $this->lang->line('form_info_success')); + echo json_encode($data); } }