将查询到的原始信息存储到数据库中

hotfix/远程访问多媒体中心
cyc 9 years ago
parent 456aa722b8
commit 295dab2bbe

@ -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++;
}
}

@ -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);

Loading…
Cancel
Save