From 010158833034792f4a49343e91cb2550ee86e06a Mon Sep 17 00:00:00 2001 From: "lmr@hainatravel.com" <59361885@qq.com> Date: Sun, 25 Feb 2018 21:22:48 -0600 Subject: [PATCH 1/7] fix dropbox --- .../views/bootstrap3/information_edit.php | 2550 ++++++++--------- 1 file changed, 1275 insertions(+), 1275 deletions(-) diff --git a/application/views/bootstrap3/information_edit.php b/application/views/bootstrap3/information_edit.php index 893cb8b0..0262fa26 100644 --- a/application/views/bootstrap3/information_edit.php +++ b/application/views/bootstrap3/information_edit.php @@ -1,1276 +1,1276 @@ - - - -
-
- - -
- -
- -
- - - -
-
-
-
- -
-
- | - ic_id, 'AMP_STATUS') === '1') {?> - - - - -
-
- -
-
-
-
-
-
链接标题
- -
-
-
-
链接地址 - - - ic_sitecode == 'cht') {?> - - -
- -
-
- - - - - -
-
- - - - - - -
- - -
- -
- - -
- -
- - -
- -
-
- - - - -
-
- - -
-
- - -
-
- - -
- -
- - -
-
- - - - - - - - - - - - - - - - - -

- - - - - - -
- - -
- - - - - - -
- - - -
- - - - ic_ht_area_type == 'pd') {?> -
-
-
- - 绑定 - -
-
- - - - - - - - - - - - - - -
- - -
- -
- config->item('site_code') == 'ah') || ($this->config->item('site_code') == 'gm')) {?> - - - - - -
-

- - - -

- - - -
-

-
-
    -
    - - - - -
    - - -
    - - - -
    - -
    + + + +
    +
    + + +
    + +
    + +
    + + + +
    +
    +
    +
    + +
    +
    + | + ic_id, 'AMP_STATUS') === '1') {?> + + + + +
    +
    + +
    +
    +
    +
    +
    +
    链接标题
    + +
    +
    +
    +
    链接地址 + + + ic_sitecode == 'cht') {?> + + +
    + +
    +
    + + + + - +
    +
    + + + + + + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    +
    + + + + +
    +
    + + +
    +
    + + +
    +
    + + +
    + +
    + + +
    +
    + + + + + + + + + + + + + + + + + +

    + + + + + + +
    + + +
    + + + + + + +
    + + + +
    + + + + ic_ht_area_type == 'pd') {?> +
    +
    +
    + + 绑定 + +
    +
    + + + + + + + + + + + + + + +
    + + +
    + +
    + config->item('site_code') == 'ah') || ($this->config->item('site_code') == 'gm')) {?> + + + + + +
    +

    + + + +

    + + + +
    +

    +
    +
      +
      + + + + +
      + + +
      + + + +
      + +
      \ No newline at end of file From 9ad62b0380398bfe79651ab899800cce2939df4b Mon Sep 17 00:00:00 2001 From: "lmr@hainatravel.com" <59361885@qq.com> Date: Sun, 25 Feb 2018 21:23:06 -0600 Subject: [PATCH 2/7] fix dropbox v1 --- .../train/controllers/searchnew.php | 292 ++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 application/third_party/train/controllers/searchnew.php diff --git a/application/third_party/train/controllers/searchnew.php b/application/third_party/train/controllers/searchnew.php new file mode 100644 index 00000000..a01a677d --- /dev/null +++ b/application/third_party/train/controllers/searchnew.php @@ -0,0 +1,292 @@ +load->model("BIZ_train_model");//加载模型 + } + + //查询聚合余票接口,对返回的数据进行处理 + public function index($train_date=null,$fromStation=null,$toStation=null){ + //定义一些变量 + $cache = 'no'; + $flag = true; + $juheTrainInfo = ''; + set_time_limit(0); + + //判断数据是否合法 + if(!$train_date || !$fromStation || !$toStation){ + exit('传参不能为空!'); + }else{ + if(strlen($fromStation) != 3){ + exit('fromStation:参数错误!'); + } + if(strlen($toStation) != 3){ + exit('toStation:参数错误!'); + } + $this->train_date = $train_date; + $now_time = time(); + $differ_time = (strtotime($train_date) - $now_time) / 86400; + if($differ_time <= 29){ + //调用聚合搜索模块 + $juheTrainInfo = $this->juheSearch($train_date,$fromStation,$toStation); + if(empty($juheTrainInfo)){ + $flag = 'error'; + } + }else{ + $flag = 'cache'; + } + + //调用数据处理模块。 + $returnJson = $this->dataOperate($juheTrainInfo,$flag,$fromStation,$toStation); + + //调用拼接处理模块 + $trainjson = $this->createTrainJson($returnJson); + + print_r($trainjson); + die(); + } + } + + //搜索模块 + function juheSearch($train_date,$fromStation,$toStation){ + $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; + $this->url = $url; + $juheTrainInfo = $this->get_http($url); + if($this->validateJuhe($juheTrainInfo)){ + return $juheTrainInfo; + }else{ + return null; + } + } + + + //缓存处理模块(包含缓存处理) + function dataOperate($trainInfo,$flag,$fromStation,$toStation){ + if($flag == 'error'){ + $research = $this->juheSearch($this->train_date,$fromStation,$toStation); + if($this->validateJuhe($research)){ + $trainInfo = $research; + }else{ + $flag = 'cache'; + } + } + + if($flag == 'cache'){ + $cacheTrainInfo = $this->BIZ_train_model->get_train_info($fromStation,$toStation); + if(empty($cacheTrainInfo)){ + return null; + }else{ + $cache_time = $cacheTrainInfo->tpc_datetime; + $now_time = time(); + $differ_time = ($now_time - strtotime($cache_time)) / 86400; + if($differ_time >= 7){ + $this->delete_traincache($fromStation,$toStation); + $research = $this->juheSearch(strtotime('+7day'),$fromStation,$toStation); + if($this->validateJuhe($research)){ + $trainInfo = $research; + }else{ + return null; + } + } + } + } + $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$trainInfo); + return $trainInfo; + } + + //字符串拼接模块 + function createTrainJson($returnJson){ + + if(empty($returnJson)){ + + }else{ + $return_data = new stdClass(); + $return_data->data = new stdClass(); + $return_data->httpstatus = 200; + //$return_data->reason = $reason; + //$return_data->cache = $cache; + $return_data->data->result = array(); + $return_data->data->map = new stdClass(); + $obj = array(); + $i = 0; + $pricestr = ''; + //print_r(json_decode($returnJson)); + //die(); + if(!empty(json_decode($returnJson)->result->list)){ + foreach (json_decode($returnJson)->result->list as $value){ + $obj[$value->from_station_code] = $value->from_station_name; + $obj[$value->to_station_code] = $value->to_station_name; + $seat_type = ''; + if(isset($value->gjrw_price)){ + if($value->gjrw_price > 0){ + $gjrwPrice = $value->gjrw_price * 10; + $seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",'; + } + } + if(isset($value->qtxb_price)){ + if($value->qtxb_price > 0){ + $seat_type .= '"H":"¥'.$value->qtxb_price.'",'; + } + } + if(isset($value->rw_price)){ + if($value->rw_price > 0){ + $rwPrice = $value->rw_price * 10; + $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",'; + } + } + if(isset($value->rz_price)){ + if($value->rz_price > 0){ + $rzPrice = $value->rz_price * 10; + $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",'; + } + } + if(isset($value->tdz_price)){ + if($value->tdz_price > 0){ + $seat_type .= '"P":"¥'.$value->tdz_price.'",'; + } + } + if(isset($value->wz_price)){ + if($value->wz_price > 0){ + $wzPrice = $value->wz_price * 10; + $seat_type .= '"WZ":"¥'.$value->wz_price.'",'; + } + } + if(isset($value->yw_price)){ + if($value->yw_price > 0){ + $ywPrice = $value->yw_price * 10; + $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",'; + } + } + if(isset($value->yz_price)){ + if($value->yz_price > 0){ + $yzPrice = $value->yz_price * 10; + $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",'; + } + } + if(isset($value->edz_price)){ + if($value->edz_price > 0){ + $seat_type .= '"O":"¥'.$value->edz_price.'",'; + } + } + if(isset($value->ydz_price)){ + if($value->ydz_price > 0){ + $seat_type .= '"M":"¥'.$value->ydz_price.'",'; + } + } + if(isset($value->swz_price)){ + if($value->swz_price > 0){ + $swzPrice = $value->swz_price * 10; + $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",'; + } + } + if(isset($value->dw_price)){ + if($value->dw_price > 0){ + $seat_type .= '"F":"¥'.$value->dw_price.'",'; + } + } + $pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"'; + //余票字符串 + $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; + $i++; + } + } + $return_data->data->map = (object)$obj; + print_r($return_data); + } + } + + + //获取价格(废弃) + /* + fromStationCode:出发站三字码 + toStationCode:终点站三字码 + trainCode:车次号 + */ + public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ + if(!$fromStationCode || !$toStationCode || !$trainCode){ + exit('传参错误!'); + }else{ + $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); + if(!empty($return_data)){ + print_r(json_decode($return_data->TPL_Price)); + }else{ + print_r('没有数据返回'); + } + } + } + + //验证聚合返回的信息是否正确 + function validateJuhe($trainInfo){ + if(!empty($trainInfo) && !empty(json_decode($trainInfo)->result)){ + return true; + }else{ + return false; + } + } + + + //余票转换 + function ticket_exchange($num){ + if(isset($this->cache)){ + $time = strtotime($this->train_date) - time(); + $day = $time / 86400; + if($day > 15){ + return '有'; + }else{ + return $num; + } + }else{ + if(is_numeric($num)){ + if($num == 0){ + return '无'; + }elseif($num >= 99){ + return '有'; + }else{ + return $num; + } + }else{ + if($num == '--'){ + return ''; + } + } + } + } + + //发送请求 + function get_http($url, $data = '', $method = 'GET') { + $curl = curl_init(); // 启动一个CURL会话 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 + curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer + if ($method == 'POST' && !empty($data)) { + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 + } + curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 + $tmpInfo = curl_exec($curl); // 执行操作 + $errno = curl_errno($curl); + if ($errno !== 0) { + return false; + $error_message = $errno . ' ' . curl_error($curl); //记录错误日志 + log_message('error', "third_party/train_app/index/get_http curl {$error_message}"); + } + curl_close($curl); //关闭CURL会话 + return $tmpInfo; //返回数据 + } +} + + + + +?> \ No newline at end of file From 433608aca3d03cf1b3e91f2e74df58d82e35d532 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Mon, 26 Feb 2018 11:58:13 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=88=A0=E9=99=A4JS=E4=B8=AD=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=9B=B4=E6=96=B0=E7=BC=93=E5=AD=98=E7=9A=84=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/information-system3.min.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/js/information-system3.min.js b/js/information-system3.min.js index 1eb41629..039515b9 100644 --- a/js/information-system3.min.js +++ b/js/information-system3.min.js @@ -300,12 +300,7 @@ function errorfun(responseText, statusText, xhr, form) { function successfun(responseText, statusText, xhr, form) { for (var key in responseText) { if (responseText[key].name == "ok") { - if ($("#rule_check_flag").val() == 1 && $("#auto_update_cache_checkbox").attr("checked")) { - $.modaldialog.success(responseText[key].value + "n" + "\u9759\u6001\u9875\u9762\u66f4\u65b0\u4e2d..."); - updateCache($("#auto_update_cache_checkbox").val(), "") - } else { - $.modaldialog.success(responseText[key].value) - } + $.modaldialog.success(responseText[key].value) } else { if (responseText[key].name == "ok_go") { $.modaldialog.success('提交成功,正在跳转到下个页面...'); @@ -518,12 +513,12 @@ function mobile_friendly(refresh){ var ic_url = $("#ic_url").val(); var sitecode = $("#is_sitecode").val(); if(refresh){ - var url = '/info.php/apps/pagespeed/index/run'; + var url = '/info.php/apps/pagespeed/index/run'; }else{ var url = '/info.php/apps/pagespeed/index/show_score'; } $.post(url, {'psd_URL':ic_url, 'psd_SiteCode':sitecode}, function(data){ - var json = eval('(' + data + ')'); + var json = eval('(' + data + ')'); if (json.result == 'ok'){ $("#mobile_friendly_status").html(json.data); } else{ @@ -535,16 +530,16 @@ if (json.result == 'ok'){ $(document).ready(function() { - + $('.ShowMeTheDatePicker_cn').datepicker({ dateFormat: 'yy-mm-dd', showButtonPanel: false }); - + $('.ShowMeTheDatePicker').datepicker({ showButtonPanel: true }); - - - -}); \ No newline at end of file + + + +}); From 084098d50d3961e5144c56a6fc8bc28d1cda7c5d Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Mon, 26 Feb 2018 13:43:18 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0JS=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/views/bootstrap3/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/bootstrap3/header.php b/application/views/bootstrap3/header.php index 02a83824..a594ea09 100644 --- a/application/views/bootstrap3/header.php +++ b/application/views/bootstrap3/header.php @@ -5,7 +5,7 @@ 信息平台 - + From 9d8d052dfeba3e1f2ce605c180b4ee38edaa43a5 Mon Sep 17 00:00:00 2001 From: lyt Date: Mon, 26 Feb 2018 14:23:46 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0JS=E5=BC=95=E7=94=A8?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/views/bootstrap3/header.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/bootstrap3/header.php b/application/views/bootstrap3/header.php index a594ea09..65a5bcbf 100644 --- a/application/views/bootstrap3/header.php +++ b/application/views/bootstrap3/header.php @@ -5,7 +5,7 @@ 信息平台 - + From 92e683d5f269e5809cd77f520cbad0b3f1670feb Mon Sep 17 00:00:00 2001 From: cyc Date: Tue, 27 Feb 2018 10:59:35 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E7=81=AB=E8=BD=A6=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/train/controllers/search.php | 125 +++++--- .../train/controllers/searchnew.php | 292 ------------------ 2 files changed, 83 insertions(+), 334 deletions(-) delete mode 100644 application/third_party/train/controllers/searchnew.php diff --git a/application/third_party/train/controllers/search.php b/application/third_party/train/controllers/search.php index ed61c05e..80c0582b 100644 --- a/application/third_party/train/controllers/search.php +++ b/application/third_party/train/controllers/search.php @@ -11,7 +11,12 @@ class search extends CI_Controller{ //查询聚合余票接口,对返回的数据进行处理 public function index($train_date=null,$fromStation=null,$toStation=null){ - set_time_limit(0); + //定义一些变量 + $flag = true; + $juheTrainInfo = ''; + set_time_limit(0); + + //判断数据是否合法 if(!$train_date || !$fromStation || !$toStation){ exit('传参不能为空!'); }else{ @@ -21,48 +26,82 @@ class search extends CI_Controller{ if(strlen($toStation) != 3){ exit('toStation:参数错误!'); } - $this->train_date = $train_date; - //$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; - $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; - $back_data = $this->get_http($url); - //特殊车次处理(贵阳 -- 重庆) - /*if(($fromStation == 'GIW') && ($toStation == 'CQW') && (strtotime($train_date) - strtotime('2018-01-16') >= 0)){ - exit('{"httpstatus":200,"reason":"特殊车次不开车","data":{"result":""}}'); - }*/ + //调用查询模块 + $search_return = $this->Searchtrain($train_date,$fromStation,$toStation); - $firstdata = $back_data; - $return_data = new stdClass(); - $cache = 'no'; + //调用数据处理模块 + $returnJson = $this->dataOperate($search_return,$fromStation,$toStation); - if(empty($back_data) || empty(json_decode($back_data)->result)){ - $obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation); - if($obj){ - $back_data = $obj->tpc_content; - $cache = 'yes'; - $this->cache = true; - $reason = '接口数据为空,调用缓存'; - log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|调用缓存号:'.$obj->tpc_sn.'|缓存生成的时间:'.$obj->tpc_datetime); + //调用拼接处理模块 + $trainjson = $this->createTrainJson($returnJson); + + print_r($trainjson); + } + } + + //搜索模块 + function Searchtrain($train_date,$fromStation,$toStation){ + $this->train_date = $train_date; + $now_time = time(); + $differ_time = (strtotime($train_date) - $now_time) / 86400; + //屏蔽掉超过预售期的搜索,提高速度 + if($differ_time > 29){ + $train_date = date('Y-m-d',strtotime('+7day')); + $this->seventh = true; + } + $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; + $this->url = $url; + $train_info = $this->get_http($url); + //如果为网络错误就再执行一次 + if(json_decode($train_info)->reason == '网络故障,请重试(0)'){ + $train_info = $this->get_http($url); + } + return $train_info; + } + + //缓存处理模块(包含缓存处理) + function dataOperate($search_return,$fromStation,$toStation){ + $this->reason = json_decode($search_return)->reason; + $this->cache = 'no'; + if(!empty($search_return) && !empty(json_decode($search_return)->result)){ + $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$search_return); + $operate_data = $search_return; + }else{ + $cache_train_info = $this->BIZ_train_model->get_train_info($fromStation,$toStation); + if(empty($cache_train_info)){ + $operate_data = null; + }else{ + $cache_time = $cache_train_info->tpc_datetime; + $now_time = time(); + $differ_time = ($now_time - strtotime($cache_time)) / 86400; + if($differ_time >= 3){ + $this->delete_traincache($fromStation,$toStation); }else{ - $reason = '接口数据为空,缓存也为空'; - log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|缓存为空'); + $this->cache = 'yes'; + $operate_data = $cache_train_info->tpc_content; + log_message('error','查询为空的链接:'.$this->url.'|出错的原因:'.$this->reason.'|调用缓存号:'.$cache_train_info->tpc_sn.'|缓存生成的时间:'.$cache_train_info->tpc_datetime); } - }else{ - $reason = json_decode($back_data)->reason; - $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data); } - - $return_data->httpstatus = 200; - $return_data->reason = $reason; - $return_data->cache = $cache; - $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)->result->list)){ - foreach (json_decode($back_data)->result->list as $value){ + } + return $operate_data; + } + + //字符串拼接模块 + function createTrainJson($returnjson){ + $return_data = new stdClass(); + $return_data->data = new stdClass(); + $return_data->httpstatus = 200; + $return_data->reason = $this->reason; + $return_data->cache = $this->cache; + $return_data->data->result = array(); + $return_data->data->map = new stdClass(); + $obj = array(); + $i = 0; + $pricestr = ''; + if(!empty($returnjson)){ + if(!empty(json_decode($returnjson)->result->list)){ + foreach (json_decode($returnjson)->result->list as $value){ $obj[$value->from_station_code] = $value->from_station_name; $obj[$value->to_station_code] = $value->to_station_name; $seat_type = ''; @@ -141,12 +180,14 @@ class search extends CI_Controller{ $i++; } } - $return_data->data->map = (object)$obj; - print_r(json_encode($return_data)); - } + + } + $return_data->data->map = (object)$obj; + return json_encode($return_data); } - //获取价格 + + //获取价格(废弃) /* fromStationCode:出发站三字码 toStationCode:终点站三字码 @@ -167,7 +208,7 @@ class search extends CI_Controller{ //余票转换 function ticket_exchange($num){ - if(isset($this->cache)){ + if($this->cache == 'yes'){ $time = strtotime($this->train_date) - time(); $day = $time / 86400; if($day > 15){ diff --git a/application/third_party/train/controllers/searchnew.php b/application/third_party/train/controllers/searchnew.php deleted file mode 100644 index c02fa71a..00000000 --- a/application/third_party/train/controllers/searchnew.php +++ /dev/null @@ -1,292 +0,0 @@ -load->model("BIZ_train_model");//加载模型 - } - - //查询聚合余票接口,对返回的数据进行处理 - public function index($train_date=null,$fromStation=null,$toStation=null){ - //定义一些变量 - $cache = 'no'; - $flag = true; - $juheTrainInfo = ''; - set_time_limit(0); - - //判断数据是否合法 - if(!$train_date || !$fromStation || !$toStation){ - exit('传参不能为空!'); - }else{ - if(strlen($fromStation) != 3){ - exit('fromStation:参数错误!'); - } - if(strlen($toStation) != 3){ - exit('toStation:参数错误!'); - } - $this->train_date = $train_date; - $now_time = time(); - $differ_time = (strtotime($train_date) - $now_time) / 86400; - if($differ_time <= 29){ - //调用聚合搜索模块 - $juheTrainInfo = $this->juheSearch($train_date,$fromStation,$toStation); - if(empty($juheTrainInfo)){ - $flag = 'error'; - } - }else{ - $flag = 'cache'; - } - - //调用数据处理模块。 - $returnJson = $this->dataOperate($juheTrainInfo,$flag,$fromStation,$toStation); - - //调用拼接处理模块 - $trainjson = $this->createTrainJson($returnJson); - - print_r($trainjson); - die(); - } - } - - //搜索模块 - function juheSearch($train_date,$fromStation,$toStation){ - $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; - $this->url = $url; - $juheTrainInfo = $this->get_http($url); - if($this->validateJuhe($juheTrainInfo)){ - return $juheTrainInfo; - }else{ - return null; - } - } - - - //缓存处理模块(包含缓存处理) - function dataOperate($trainInfo,$flag,$fromStation,$toStation){ - if($flag == 'error'){ - $research = $this->juheSearch($this->train_date,$fromStation,$toStation); - if($this->validateJuhe($research)){ - $trainInfo = $research; - }else{ - $flag = 'cache'; - } - } - - if($flag == 'cache'){ - $cacheTrainInfo = $this->BIZ_train_model->get_train_info($fromStation,$toStation); - if(empty($cacheTrainInfo)){ - return null; - }else{ - $cache_time = $cacheTrainInfo->tpc_datetime; - $now_time = time(); - $differ_time = ($now_time - strtotime($cache_time)) / 86400; - if($differ_time >= 7){ - $this->delete_traincache($fromStation,$toStation); - $research = $this->juheSearch(strtotime('+7day'),$fromStation,$toStation); - if($this->validateJuhe($research)){ - $trainInfo = $research; - }else{ - return null; - } - } - } - } - $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$trainInfo); - return $trainInfo; - } - - //字符串拼接模块 - function createTrainJson($returnJson){ - - if(empty($returnJson)){ - - }else{ - $return_data = new stdClass(); - $return_data->data = new stdClass(); - $return_data->httpstatus = 200; - //$return_data->reason = $reason; - //$return_data->cache = $cache; - $return_data->data->result = array(); - $return_data->data->map = new stdClass(); - $obj = array(); - $i = 0; - $pricestr = ''; - //print_r(json_decode($returnJson)); - //die(); - if(!empty(json_decode($returnJson)->result->list)){ - foreach (json_decode($returnJson)->result->list as $value){ - $obj[$value->from_station_code] = $value->from_station_name; - $obj[$value->to_station_code] = $value->to_station_name; - $seat_type = ''; - if(isset($value->gjrw_price)){ - if($value->gjrw_price > 0){ - $gjrwPrice = $value->gjrw_price * 10; - $seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",'; - } - } - if(isset($value->qtxb_price)){ - if($value->qtxb_price > 0){ - $seat_type .= '"H":"¥'.$value->qtxb_price.'",'; - } - } - if(isset($value->rw_price)){ - if($value->rw_price > 0){ - $rwPrice = $value->rw_price * 10; - $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",'; - } - } - if(isset($value->rz_price)){ - if($value->rz_price > 0){ - $rzPrice = $value->rz_price * 10; - $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",'; - } - } - if(isset($value->tdz_price)){ - if($value->tdz_price > 0){ - $seat_type .= '"P":"¥'.$value->tdz_price.'",'; - } - } - if(isset($value->wz_price)){ - if($value->wz_price > 0){ - $wzPrice = $value->wz_price * 10; - $seat_type .= '"WZ":"¥'.$value->wz_price.'",'; - } - } - if(isset($value->yw_price)){ - if($value->yw_price > 0){ - $ywPrice = $value->yw_price * 10; - $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",'; - } - } - if(isset($value->yz_price)){ - if($value->yz_price > 0){ - $yzPrice = $value->yz_price * 10; - $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",'; - } - } - if(isset($value->edz_price)){ - if($value->edz_price > 0){ - $seat_type .= '"O":"¥'.$value->edz_price.'",'; - } - } - if(isset($value->ydz_price)){ - if($value->ydz_price > 0){ - $seat_type .= '"M":"¥'.$value->ydz_price.'",'; - } - } - if(isset($value->swz_price)){ - if($value->swz_price > 0){ - $swzPrice = $value->swz_price * 10; - $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",'; - } - } - if(isset($value->dw_price)){ - if($value->dw_price > 0){ - $seat_type .= '"F":"¥'.$value->dw_price.'",'; - } - } - $pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"'; - //余票字符串 - $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; - $i++; - } - } - $return_data->data->map = (object)$obj; - print_r($return_data); - } - } - - - //获取价格(废弃) - /* - fromStationCode:出发站三字码 - toStationCode:终点站三字码 - trainCode:车次号 - */ - public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ - if(!$fromStationCode || !$toStationCode || !$trainCode){ - exit('传参错误!'); - }else{ - $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); - if(!empty($return_data)){ - print_r(json_decode($return_data->TPL_Price)); - }else{ - print_r('没有数据返回'); - } - } - } - - //验证聚合返回的信息是否正确 - function validateJuhe($trainInfo){ - if(!empty($trainInfo) && !empty(json_decode($trainInfo)->result)){ - return true; - }else{ - return false; - } - } - - - //余票转换 - function ticket_exchange($num){ - if(isset($this->cache)){ - $time = strtotime($this->train_date) - time(); - $day = $time / 86400; - if($day > 15){ - return '有'; - }else{ - return $num; - } - }else{ - if(is_numeric($num)){ - if($num == 0){ - return '无'; - }elseif($num >= 99){ - return '有'; - }else{ - return $num; - } - }else{ - if($num == '--'){ - return ''; - } - } - } - } - - //发送请求 - function get_http($url, $data = '', $method = 'GET') { - $curl = curl_init(); // 启动一个CURL会话 - curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 - curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 - curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer - if ($method == 'POST' && !empty($data)) { - curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 - } - curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环 - curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 - $tmpInfo = curl_exec($curl); // 执行操作 - $errno = curl_errno($curl); - if ($errno !== 0) { - return false; - $error_message = $errno . ' ' . curl_error($curl); //记录错误日志 - log_message('error', "third_party/train_app/index/get_http curl {$error_message}"); - } - curl_close($curl); //关闭CURL会话 - return $tmpInfo; //返回数据 - } -} - - - - -?> \ No newline at end of file From 6741fafe3cac00ebc2acbfcc17a5414a4756b4a5 Mon Sep 17 00:00:00 2001 From: cyc Date: Tue, 27 Feb 2018 10:59:59 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E7=81=AB=E8=BD=A6=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../train/controllers/searchold.php | 226 ++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 application/third_party/train/controllers/searchold.php diff --git a/application/third_party/train/controllers/searchold.php b/application/third_party/train/controllers/searchold.php new file mode 100644 index 00000000..ed61c05e --- /dev/null +++ b/application/third_party/train/controllers/searchold.php @@ -0,0 +1,226 @@ +load->model("BIZ_train_model");//加载模型 + } + + //查询聚合余票接口,对返回的数据进行处理 + public function index($train_date=null,$fromStation=null,$toStation=null){ + set_time_limit(0); + if(!$train_date || !$fromStation || !$toStation){ + exit('传参不能为空!'); + }else{ + if(strlen($fromStation) != 3){ + exit('fromStation:参数错误!'); + } + if(strlen($toStation) != 3){ + exit('toStation:参数错误!'); + } + $this->train_date = $train_date; + //$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; + $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; + $back_data = $this->get_http($url); + + //特殊车次处理(贵阳 -- 重庆) + /*if(($fromStation == 'GIW') && ($toStation == 'CQW') && (strtotime($train_date) - strtotime('2018-01-16') >= 0)){ + exit('{"httpstatus":200,"reason":"特殊车次不开车","data":{"result":""}}'); + }*/ + + $firstdata = $back_data; + $return_data = new stdClass(); + $cache = 'no'; + + if(empty($back_data) || empty(json_decode($back_data)->result)){ + $obj = $this->BIZ_train_model->get_train_info($fromStation,$toStation); + if($obj){ + $back_data = $obj->tpc_content; + $cache = 'yes'; + $this->cache = true; + $reason = '接口数据为空,调用缓存'; + log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|调用缓存号:'.$obj->tpc_sn.'|缓存生成的时间:'.$obj->tpc_datetime); + }else{ + $reason = '接口数据为空,缓存也为空'; + log_message('error','查询为空的链接:'.$url.'|出错的原因:'.$firstdata.'|缓存为空'); + } + }else{ + $reason = json_decode($back_data)->reason; + $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$back_data); + } + + $return_data->httpstatus = 200; + $return_data->reason = $reason; + $return_data->cache = $cache; + $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)->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; + $seat_type = ''; + if(isset($value->gjrw_price)){ + if($value->gjrw_price > 0){ + $gjrwPrice = $value->gjrw_price * 10; + $seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",'; + } + } + if(isset($value->qtxb_price)){ + if($value->qtxb_price > 0){ + $seat_type .= '"H":"¥'.$value->qtxb_price.'",'; + } + } + if(isset($value->rw_price)){ + if($value->rw_price > 0){ + $rwPrice = $value->rw_price * 10; + $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",'; + } + } + if(isset($value->rz_price)){ + if($value->rz_price > 0){ + $rzPrice = $value->rz_price * 10; + $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",'; + } + } + if(isset($value->tdz_price)){ + if($value->tdz_price > 0){ + $seat_type .= '"P":"¥'.$value->tdz_price.'",'; + } + } + if(isset($value->wz_price)){ + if($value->wz_price > 0){ + $wzPrice = $value->wz_price * 10; + $seat_type .= '"WZ":"¥'.$value->wz_price.'",'; + } + } + if(isset($value->yw_price)){ + if($value->yw_price > 0){ + $ywPrice = $value->yw_price * 10; + $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",'; + } + } + if(isset($value->yz_price)){ + if($value->yz_price > 0){ + $yzPrice = $value->yz_price * 10; + $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",'; + } + } + if(isset($value->edz_price)){ + if($value->edz_price > 0){ + $seat_type .= '"O":"¥'.$value->edz_price.'",'; + } + } + if(isset($value->ydz_price)){ + if($value->ydz_price > 0){ + $seat_type .= '"M":"¥'.$value->ydz_price.'",'; + } + } + if(isset($value->swz_price)){ + if($value->swz_price > 0){ + $swzPrice = $value->swz_price * 10; + $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",'; + } + } + if(isset($value->dw_price)){ + if($value->dw_price > 0){ + $seat_type .= '"F":"¥'.$value->dw_price.'",'; + } + } + $pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"'; + //余票字符串 + $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; + $i++; + } + } + $return_data->data->map = (object)$obj; + print_r(json_encode($return_data)); + } + } + + //获取价格 + /* + fromStationCode:出发站三字码 + toStationCode:终点站三字码 + trainCode:车次号 + */ + public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ + if(!$fromStationCode || !$toStationCode || !$trainCode){ + exit('传参错误!'); + }else{ + $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); + if(!empty($return_data)){ + print_r(json_decode($return_data->TPL_Price)); + }else{ + print_r('没有数据返回'); + } + } + } + + //余票转换 + function ticket_exchange($num){ + if(isset($this->cache)){ + $time = strtotime($this->train_date) - time(); + $day = $time / 86400; + if($day > 15){ + return '有'; + }else{ + return $num; + } + }else{ + if(is_numeric($num)){ + if($num == 0){ + return '无'; + }elseif($num >= 99){ + return '有'; + }else{ + return $num; + } + }else{ + if($num == '--'){ + return ''; + } + } + } + } + + //发送请求 + function get_http($url, $data = '', $method = 'GET') { + $curl = curl_init(); // 启动一个CURL会话 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 + curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer + if ($method == 'POST' && !empty($data)) { + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 + } + curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 + $tmpInfo = curl_exec($curl); // 执行操作 + $errno = curl_errno($curl); + if ($errno !== 0) { + return false; + $error_message = $errno . ' ' . curl_error($curl); //记录错误日志 + log_message('error', "third_party/train_app/index/get_http curl {$error_message}"); + } + curl_close($curl); //关闭CURL会话 + return $tmpInfo; //返回数据 + } +} + + + + +?> \ No newline at end of file