From 295dab2bbeb5141a79b3966cab4181318b1351a7 Mon Sep 17 00:00:00 2001 From: cyc Date: Thu, 30 Nov 2017 13:51:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E6=9F=A5=E8=AF=A2=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E4=BF=A1=E6=81=AF=E5=AD=98=E5=82=A8=E5=88=B0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/train/controllers/search.php | 6 ++- .../train/models/BIZ_train_model.php | 40 +++++++++---------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/application/third_party/train/controllers/search.php b/application/third_party/train/controllers/search.php index 2248c237..7f332410 100644 --- a/application/third_party/train/controllers/search.php +++ b/application/third_party/train/controllers/search.php @@ -6,7 +6,7 @@ class search extends CI_Controller{ public function __construct(){ parent::__construct(); - //$this->load->model("BIZ_train_model");//加载模型 + $this->load->model("BIZ_train_model");//加载模型 } //查询聚合余票接口,对返回的数据进行处理 @@ -20,6 +20,8 @@ class search extends CI_Controller{ $back_data = $this->get_http($url); if(empty(json_decode($back_data)->result)){ log_message('error','juhetrain:'.$url.' '.$back_data); + }else{ + $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data); } //print_r(json_decode($back_data)); $return_data = new stdClass(); @@ -31,6 +33,7 @@ class search extends CI_Controller{ $i = 0; $pricestr = ''; if(!empty(json_decode($back_data)->result->list)){ + foreach (json_decode($back_data)->result->list as $value){ $obj[$value->from_station_code] = $value->from_station_name; $obj[$value->to_station_code] = $value->to_station_name; @@ -107,7 +110,6 @@ class search extends CI_Controller{ $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_num).'|'.$this->ticket_exchange($value->qtxb_num).'|'.$this->ticket_exchange($value->rw_num).'|'.$this->ticket_exchange($value->rz_num).'|'.$this->ticket_exchange($value->tdz_num).'|'.$this->ticket_exchange($value->wz_num).'||'.$this->ticket_exchange($value->yw_num).'|'.$this->ticket_exchange($value->yz_num).'|'.$this->ticket_exchange($value->edz_num).'|'.$this->ticket_exchange($value->ydz_num).'|'.$this->ticket_exchange($value->swz_num).'|'.$this->ticket_exchange($value->dw_num).'||'; $data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}'; $return_data->data->price[$i] = $data; - //$this->BIZ_train_model->addOrUpdate($value->train_no,$value->train_code,$value->from_station_code,$value->to_station_code,json_encode($data)); $i++; } } diff --git a/application/third_party/train/models/BIZ_train_model.php b/application/third_party/train/models/BIZ_train_model.php index 0bd387da..13b3ecb3 100644 --- a/application/third_party/train/models/BIZ_train_model.php +++ b/application/third_party/train/models/BIZ_train_model.php @@ -9,39 +9,37 @@ class BIZ_train_model extends CI_Model { } //新增或更新价格 - 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(),'juhe' + '$tpc_from_station','$tpc_to_station','$tpc_content',GETDATE(),'juhe' ) END ELSE BEGIN - UPDATE TrainPriceList - SET TPL_Train_No = '$TPL_Train_No', - TPL_Price = '$TPL_Price', - TPL_Datetime = GETDATE(), + UPDATE TrainPriceCache + SET tpc_from_station = '$tpc_from_station', + tpc_to_station = '$tpc_to_station', + tpc_datetime = GETDATE(), TPL_Source = 'juhe' - 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' + WHERE + tpc_from_station = '$tpc_from_station' + AND tpc_to_station = '$tpc_to_station' END "; $query = $this->INFO->query($sql);