|
|
@ -61,39 +61,47 @@ class Tuniu_train extends CI_Controller{
|
|
|
|
"data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" }
|
|
|
|
"data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" }
|
|
|
|
}';
|
|
|
|
}';
|
|
|
|
$back_data = post_tuniu($url,$post_data,$method = 'POST');
|
|
|
|
$back_data = post_tuniu($url,$post_data,$method = 'POST');
|
|
|
|
|
|
|
|
|
|
|
|
//如果数据为空则调用缓存,有数据则进行数据存储
|
|
|
|
//print_r(json_decode($back_data));die();
|
|
|
|
if(empty($back_data)){
|
|
|
|
$log_info = '';
|
|
|
|
log_message('error','tuniutrain 接口未响应|数据源:'.$fromStation.'|'.$toStation.'|'.$date);
|
|
|
|
|
|
|
|
$trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation);
|
|
|
|
if(isset(json_decode($back_data)->data)){
|
|
|
|
$back_data = $trainCache->tpc_content;
|
|
|
|
$tn_info = json_decode($back_data);
|
|
|
|
$isCache = true;
|
|
|
|
$retrun_code = $tn_info->returnCode;
|
|
|
|
}else{
|
|
|
|
$return_msg = $tn_info->errorMsg;
|
|
|
|
if(empty(json_decode($back_data)->data)){
|
|
|
|
if(empty(json_decode($back_data)->data)){
|
|
|
|
$error = json_decode($back_data);
|
|
|
|
$isCache = true;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$log_info = 'tuniutrain 查询数据:'.$fromStation.'|'.$toStation.'|'.$date.'|retrun_code:'.$retrun_code.'|return_msg:'.$return_msg;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$isCache = true;
|
|
|
|
|
|
|
|
$log_info = 'tuniutrain 接口未响应|数据源:'.$fromStation.'|'.$toStation.'|'.$date;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($isCache){
|
|
|
|
|
|
|
|
if($differ <= 5){
|
|
|
|
|
|
|
|
$back_data = null;
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
echo '123';
|
|
|
|
$trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation);
|
|
|
|
$trainCache = $this->tuniuprice_model->get_train_cache($fromStation,$toStation);
|
|
|
|
if(!empty($trainCache)){
|
|
|
|
if(!empty($trainCache)){
|
|
|
|
$back_data = $trainCache->tpc_content;
|
|
|
|
$back_data = $trainCache->tpc_content;
|
|
|
|
$isCache = true;
|
|
|
|
$isCache = true;
|
|
|
|
log_message('error','tuniutrain 查询出错|'.$error->errorMsg);
|
|
|
|
$log_info .= '|调用缓存';
|
|
|
|
|
|
|
|
log_message('error',$log_info);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
$back_data = null;
|
|
|
|
$back_data = null;
|
|
|
|
log_message('error','tuniutrain 缓存为空|'.$fromStation.'|'.$toStation.'|'.$date);
|
|
|
|
$log_info .= '|缓存为空';
|
|
|
|
|
|
|
|
log_message('error',$log_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//途牛数据格式转换
|
|
|
|
//途牛数据格式转换
|
|
|
|
$return_data = new stdClass();
|
|
|
|
$return_data = new stdClass();
|
|
|
|
if(empty($back_data)){
|
|
|
|
|
|
|
|
$return_data->returnCode = '404';
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
$return_data->returnCode = json_decode($back_data)->returnCode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$return_data->httpstatus = 200;
|
|
|
|
$return_data->httpstatus = 200;
|
|
|
|
$return_data->data = new stdClass();
|
|
|
|
$return_data->data = new stdClass();
|
|
|
|
$return_data->data->seven = $iseven;
|
|
|
|
$return_data->data->seven = $iseven;
|
|
|
|