Merge branch 'master' of github.com:hainatravel/information-system
commit
83af1fc97d
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/*
|
||||
* @Author: zp
|
||||
* @Date: 2020-04-29 11:36:41
|
||||
* @LastEditTime: 2020-05-26 15:33:10
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: 雷延廷的抓取bokun接口文件
|
||||
* @FilePath: \trippest.com\TP\libraries\bokun_lib.php
|
||||
*/
|
||||
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Bokun_lib
|
||||
{
|
||||
protected $ci;
|
||||
|
||||
private $bokun_url = 'https://api.bokun.is'; // https://api.bokun.io
|
||||
private $access_key = '2f6284e43ee84f6a85fbb0c5660c7404';
|
||||
private $secret_key = 'ef3353fe28dc402b9045c2a766b68efe';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->ci =& get_instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @param string $activityid :产品的ID
|
||||
* @return: json :产品的详细json数据
|
||||
* @Date Changed:
|
||||
*/
|
||||
public function get_activity_detail($activityid){
|
||||
$path = "/activity.json/$activityid?currency=USD&lang=EN";
|
||||
$activity = $this->call_bokun($path,'get');
|
||||
return ($activity);
|
||||
}
|
||||
|
||||
public function get_all_product_list()
|
||||
{
|
||||
$path = "/product-list.json/list?lang=EN";
|
||||
$product_list = $this->call_bokun($path,'get');
|
||||
return ($product_list);
|
||||
}
|
||||
|
||||
public function get_product_list_detail($list_id)
|
||||
{
|
||||
$path = "/product-list.json/$list_id?currency=USD&lang=EN";
|
||||
$product_list = $this->call_bokun($path,'get');
|
||||
return ($product_list);
|
||||
}
|
||||
|
||||
public function get_activity_price($bokun_id)
|
||||
{
|
||||
$path = "/activity.json/$bokun_id/price-list?currency=USD";
|
||||
$price_list = $this->call_bokun($path,'get');
|
||||
return ($price_list);
|
||||
}
|
||||
|
||||
private function make_bokun_signature($date, $method, $path)
|
||||
{
|
||||
$raw_str = $date . $this->access_key . strtoupper($method) . $path;
|
||||
return base64_encode(hash_hmac("sha1", $raw_str, $this->secret_key, TRUE));
|
||||
}
|
||||
|
||||
private function call_bokun($path, $method, $body=null)
|
||||
{
|
||||
$url = $this->bokun_url . $path;
|
||||
$create_date = gmdate("Y-m-d H:i:s");
|
||||
$bokun_signature = $this->make_bokun_signature($create_date, $method, $path);
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER,
|
||||
array(
|
||||
"X-Bokun-Date:" . $create_date,
|
||||
"X-Bokun-AccessKey :" . $this->access_key,
|
||||
"X-Bokun-Signature :" . $bokun_signature
|
||||
)
|
||||
);
|
||||
$set_post = strtoupper($method) === 'GET' ? false : true;
|
||||
curl_setopt($curl, CURLOPT_POST, $set_post);
|
||||
// curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
|
||||
log_message('debug','call_bokun ' . $method . PHP_EOL . var_export($url, 1));
|
||||
$output = curl_exec($curl);
|
||||
if (curl_errno($curl)) {
|
||||
log_message('error', "curl error code: ".curl_error($curl)."; curl call: ".$path);
|
||||
} else {
|
||||
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if (200 !== $httpStatusCode) {
|
||||
log_message('error', "Request html Status Code: ".$httpStatusCode."; curl call: ".$path);
|
||||
}
|
||||
}
|
||||
curl_close($curl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* End of file Bokun_lib.php */
|
@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
class IContent_model extends CI_Model
|
||||
{
|
||||
|
||||
var $insert_id = -1;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
function Add($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords,
|
||||
$ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages,
|
||||
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author)
|
||||
{
|
||||
$ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url3'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_org2'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace('#textarea#', 'textarea',$ic_content);
|
||||
$sql = "INSERT INTO infoContents \n"
|
||||
. " ( \n"
|
||||
. " ic_url, ic_url_title, ic_type, ic_title, ic_content, ic_summary, ic_seo_title, \n"
|
||||
. " ic_seo_description, ic_seo_keywords, ic_show_bread_crumbs, ic_status, \n"
|
||||
. " ic_template, ic_photo,ic_photo_width,ic_photo_height, ic_sitecode, ic_recommend_tours, ic_recommend_packages, \n"
|
||||
. " ic_ht_area_id, ic_ht_area_type,ic_ht_product_id,ic_ht_product_type,ic_author, ic_datetime \n"
|
||||
. " ) \n"
|
||||
. "VALUES \n"
|
||||
. " ( N?,N?,?,N?,N?,N?,N?,N?,N?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,getdate() )";
|
||||
$query = $this->HT->query($sql,
|
||||
array($ic_url, $ic_url_title, $ic_type, $ic_title, str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),
|
||||
$ic_content),
|
||||
$ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status,
|
||||
$ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, "trippest", $ic_recommend_tours, $ic_recommend_packages,
|
||||
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author));
|
||||
$this->insert_id = $this->HT->last_id('infoContents');
|
||||
return $query;
|
||||
}
|
||||
|
||||
function Update($ic_id, $ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords,
|
||||
$ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages,
|
||||
$ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author)
|
||||
{
|
||||
$ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content);
|
||||
$ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content);
|
||||
$sql = "UPDATE infoContents \n"
|
||||
. "SET ic_url = N?, \n"
|
||||
. " ic_url_title = N?, \n"
|
||||
. " ic_type = ?, \n"
|
||||
. " ic_title = N?, \n"
|
||||
. " ic_content = N?, \n"
|
||||
. " ic_summary = N?, \n"
|
||||
. " ic_seo_title = N?, \n"
|
||||
. " ic_seo_description = N?, \n"
|
||||
. " ic_seo_keywords = N?, \n"
|
||||
. " ic_show_bread_crumbs = ?, \n"
|
||||
. " ic_status = ?, \n"
|
||||
. " ic_template = ?, \n"
|
||||
. " ic_photo = ?, \n"
|
||||
. " ic_photo_width = ?, \n"
|
||||
. " ic_photo_height = ?, \n"
|
||||
. " ic_recommend_tours = ?, \n"
|
||||
. " ic_recommend_packages = ?, \n"
|
||||
. " ic_datetime = GETDATE() , \n"
|
||||
. " ic_ht_area_id = ?, \n"
|
||||
. " ic_ht_area_type = ?, \n"
|
||||
. " ic_ht_product_id = ?, \n"
|
||||
. " ic_ht_product_type = ?, \n"
|
||||
. " ic_author = ? \n"
|
||||
. "WHERE ic_id = ? \n"
|
||||
. "AND ic_sitecode = ? ";
|
||||
$query = $this->HT->query($sql,
|
||||
array($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary,
|
||||
$ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height,
|
||||
$ic_recommend_tours, $ic_recommend_packages, $ic_ht_area_id,
|
||||
$ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author, $ic_id,"trippest"));
|
||||
return $query;
|
||||
}
|
||||
|
||||
//删除信息
|
||||
function force_update($ic_id, $ic_content)
|
||||
{
|
||||
$sql = "UPDATE infoContents SET ic_content = N? WHERE ic_id = ?";
|
||||
$query = $this->HT->query($sql, array($ic_content, $ic_id));
|
||||
return $query;
|
||||
}
|
||||
|
||||
//删除信息
|
||||
function Delete($ic_id)
|
||||
{
|
||||
$sql = "DELETE \n"
|
||||
. "FROM infoContents \n"
|
||||
. "WHERE ic_id = ?";
|
||||
$query = $this->HT->query($sql, array($ic_id));
|
||||
return $query;
|
||||
}
|
||||
|
||||
//递增浏览量
|
||||
function inc_views($sitecode,$page_url)
|
||||
{
|
||||
//查询信息需要过滤url上的域名
|
||||
if($page_url && $sitecode)
|
||||
{
|
||||
$page_url=substr($page_url,strpos($page_url,'/',8));//过滤掉url前面的http://
|
||||
$sql = "UPDATE infoContents \n"
|
||||
. "SET ic_view = ISNULL(ic_view,0) + 1 \n"
|
||||
. "WHERE ic_sitecode = ? AND ic_url = N?";
|
||||
return $this->HT->query($sql,array($sitecode,$page_url));
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ic_contents($ic_id)
|
||||
{
|
||||
$sql="SELECT top 1 ic_id from infoContents where ic_id=?";
|
||||
$query=$this->HT->query($sql,array($ic_id));
|
||||
if ($query->result())
|
||||
{
|
||||
$row = $query->row();
|
||||
return $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ic_contents2($ic_id)
|
||||
{
|
||||
$sql="SELECT top 1 ic_id, ic_content, ic_title, ic_url, ic_photo, ic_sitecode, ic_seo_description from infoContents where ic_id=?";
|
||||
$query=$this->HT->query($sql,array($ic_id));
|
||||
if ($query->result())
|
||||
{
|
||||
$row = $query->row();
|
||||
return $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_ic_contents_by_list($ic_id_list)
|
||||
{
|
||||
$ic_id_list=trim($ic_id_list);
|
||||
$ic_id_list.=0;
|
||||
$sql="SELECT * from infoContents where ic_id in ($ic_id_list) order by charindex(','+ltrim(ic_id)+',', ',$ic_id_list,')";
|
||||
$query=$this->HT->query($sql);
|
||||
if ($query->result())
|
||||
{
|
||||
$row = $query->result();
|
||||
return $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
class IStructures_model extends CI_Model
|
||||
{
|
||||
|
||||
var $insert_id = -1;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
function Detail($is_id)
|
||||
{
|
||||
$sql = "SELECT TOP 1 is1.is_id, \n"
|
||||
. " is1.is_parent_id, \n"
|
||||
. " is1.is_path, \n"
|
||||
. " is1.is_level, \n"
|
||||
. " is1.is_sort, \n"
|
||||
. " is1.is_sitecode, \n"
|
||||
. " is1.is_datetime, \n"
|
||||
. " is1.is_ic_id \n"
|
||||
. "FROM infoStructures is1 \n"
|
||||
. "WHERE is1.is_id = ?";
|
||||
$query = $this->HT->query($sql, array($is_id));
|
||||
//print_r($this->HT->queries);
|
||||
if ($query->result())
|
||||
{
|
||||
$row = $query->row();
|
||||
return $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function Add($is_parent_id, $is_ic_id=-1)
|
||||
{
|
||||
if ($is_parent_id == 0)
|
||||
{
|
||||
$is_path = '';
|
||||
$is_level = 1;
|
||||
$is_sort = 999;
|
||||
}
|
||||
else
|
||||
{
|
||||
$infoStructure = $this->Detail($is_parent_id);
|
||||
if ($infoStructure)
|
||||
{
|
||||
$is_path = $infoStructure->is_path;
|
||||
$is_level = $infoStructure->is_level + 1;
|
||||
$is_sort = 999;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$sql = "INSERT INTO infoStructures \n"
|
||||
. " ( \n"
|
||||
. " is_parent_id, is_path, is_level, is_sort, is_sitecode, is_datetime, is_ic_id \n"
|
||||
. " ) \n"
|
||||
. "VALUES \n"
|
||||
. " ( \n"
|
||||
. " ?, ?, ?, ?, ?, getdate(), ? \n"
|
||||
. " )";
|
||||
$query = $this->HT->query($sql, array($is_parent_id, $is_path, $is_level, $is_sort, "trippest", $is_ic_id));
|
||||
$this->insert_id = $this->HT->last_id('infoStructures');
|
||||
//把自己的ID加到path上
|
||||
$set_sql = "UPDATE infoStructures \n"
|
||||
. "SET is_path = is_path + CONVERT(VARCHAR(200), is_id) + ',' \n"
|
||||
. "WHERE is_id = ?";
|
||||
$query = $this->HT->query($set_sql, array($this->insert_id));
|
||||
|
||||
return $this->insert_id;
|
||||
}
|
||||
|
||||
function GetParent($is_path, $level=1)
|
||||
{
|
||||
if ($is_path == '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$sql = "SELECT TOP 1 is1.is_id, \n"
|
||||
. " is1.is_parent_id, \n"
|
||||
. " is1.is_path, \n"
|
||||
. " is1.is_level, \n"
|
||||
. " is1.is_sort, \n"
|
||||
. " is1.is_sitecode, \n"
|
||||
. " is1.is_datetime, \n"
|
||||
. " is1.is_ic_id \n"
|
||||
. "FROM infoStructures is1 \n"
|
||||
. "WHERE is1.is_level = ? \n"
|
||||
. " AND is1.is_id IN ($is_path 0) \n"
|
||||
. "ORDER BY \n"
|
||||
. " is1.is_id ASC";
|
||||
$query = $this->HT->query($sql, array($level));
|
||||
// print_r($this->HT->queries);
|
||||
if ($query->result())
|
||||
{
|
||||
$row = $query->row();
|
||||
return $row;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//查询节点的根节点
|
||||
function get_root($is_id)
|
||||
{
|
||||
$detail = $this->Detail($is_id);
|
||||
$root = $this->GetParent($detail->is_path, 1);
|
||||
if ($root)
|
||||
{
|
||||
return $root;
|
||||
}
|
||||
else
|
||||
{ //没有根节点则返回本节点
|
||||
return $detail;
|
||||
}
|
||||
}
|
||||
|
||||
//判断是否有子节点
|
||||
function HasChild($is_id)
|
||||
{
|
||||
$sql = "SELECT TOP 1 is1.is_id \n"
|
||||
. "FROM infoStructures is1 \n"
|
||||
. "WHERE is1.is_parent_id = ?";
|
||||
$query = $this->HT->query($sql, array($is_id));
|
||||
if ($query->result())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
//删除节点
|
||||
function Delete($is_id)
|
||||
{
|
||||
$sql = "DELETE \n"
|
||||
. "FROM infoStructures \n"
|
||||
. "WHERE is_id = ?";
|
||||
$query = $this->HT->query($sql, array($is_id));
|
||||
return $query;
|
||||
}
|
||||
|
||||
//设置排序
|
||||
function set_sort($is_id, $sort)
|
||||
{
|
||||
$sql = "UPDATE infoStructures \n"
|
||||
. "SET is_datetime = GETDATE(), \n"
|
||||
. " is_sort = ? \n"
|
||||
. "WHERE is_id = ?";
|
||||
$query = $this->HT->query($sql, array($sort, $is_id));
|
||||
//print_r($this->HT->queries);
|
||||
return $query;
|
||||
}
|
||||
|
||||
//设置路径
|
||||
function set_path($parent_id, $is_id)
|
||||
{
|
||||
$structure = $this->Detail($is_id);
|
||||
//如果父级相同则不需要重新设置path
|
||||
if ($parent_id == $structure->is_parent_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
$parent = $this->Detail($parent_id);
|
||||
//设置当前节点
|
||||
$set_parent_id = $parent->is_id;
|
||||
$set_level = $parent->is_level + 1;
|
||||
$set_path = $parent->is_path . $is_id . ',';
|
||||
|
||||
$set_sql = "UPDATE infoStructures \n"
|
||||
. "SET is_parent_id = ?, \n"
|
||||
. " is_level = ?, \n"
|
||||
. " is_path = ? \n"
|
||||
. "WHERE is_id = ?";
|
||||
$this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $is_id));
|
||||
|
||||
$structure = $this->Detail($is_id);
|
||||
|
||||
//查询当前节点的所有子节点
|
||||
$sql = "SELECT is1.is_id, \n"
|
||||
. " is1.is_parent_id, \n"
|
||||
. " is1.is_path, \n"
|
||||
. " is1.is_level, \n"
|
||||
. " is1.is_sort \n"
|
||||
. "FROM infoStructures is1 \n"
|
||||
. "WHERE ',' + is1.is_path LIKE '%,$structure->is_id,%' \n"
|
||||
. "ORDER BY \n"
|
||||
. " is1.is_level ASC ";
|
||||
$query = $this->HT->query($sql);
|
||||
foreach ($query->result() as $item)
|
||||
{
|
||||
if ($item->is_parent_id != $structure->is_id)
|
||||
{
|
||||
$structure = $this->Detail($item->is_parent_id);
|
||||
}
|
||||
$set_parent_id = $structure->is_id;
|
||||
$set_level = $structure->is_level + 1;
|
||||
$set_path = $structure->is_path . $item->is_id . ',';
|
||||
$set_sql = "UPDATE infoStructures \n"
|
||||
. "SET is_parent_id = ?, \n"
|
||||
. " is_level = ?, \n"
|
||||
. " is_path = ? \n"
|
||||
. "WHERE is_id = ?";
|
||||
$this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $item->is_id));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,644 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class innerTrainSearch extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
header('Access-Control-Allow-Origin:*');
|
||||
header('Access-Control-Allow-Methods:POST, GET');
|
||||
header('Access-Control-Max-Age:0');
|
||||
header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
|
||||
header('Access-Control-Allow-Credentials:true');
|
||||
$this->load->helper('train');
|
||||
$this->start_time = microtime(true);
|
||||
//$this->load->model("BIZ_intel_train_model");//国际火车模型
|
||||
}
|
||||
|
||||
public function index(){
|
||||
exit('你走错了!');
|
||||
}
|
||||
|
||||
//查询选择
|
||||
public function search(){
|
||||
//接收参数
|
||||
$date = $this->input->get_post('date');
|
||||
$from = $this->input->get_post('from');
|
||||
$to = $this->input->get_post('to');
|
||||
|
||||
if(!$date || !$from || !$to){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
||||
}else{
|
||||
//根据选择的接口供应商调用对应的接口,默认使用携程的接口
|
||||
$supplier = $this->input->get_post('supplier');
|
||||
|
||||
switch ($supplier){
|
||||
case 'juhe':
|
||||
$this->juheApi($date,$from,$to);
|
||||
break;
|
||||
case 'ctrip':
|
||||
$this->ctripApi($date,$from,$to);
|
||||
break;
|
||||
default :
|
||||
$this->ctripApi($date,$from,$to);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//聚合数据接口
|
||||
public function juheApi($train_date=null,$fromStation=null,$toStation=null){
|
||||
//定义一些变量
|
||||
$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:参数错误!');
|
||||
}
|
||||
|
||||
$api_start_time = microtime(true);
|
||||
|
||||
//调用查询模块
|
||||
$search_return = $this->Searchtrain($train_date,$fromStation,$toStation);
|
||||
$api_end_time = microtime(true);
|
||||
|
||||
//调用拼接处理模块
|
||||
$trainjson = $this->createTrainJson($search_return);
|
||||
$end_time = microtime(true);
|
||||
|
||||
//聚合接口相应时间
|
||||
$api_responsive_time = $api_end_time - $api_start_time;
|
||||
|
||||
//我们的接口相应时间
|
||||
$responsive_time = $end_time - $this->start_time;
|
||||
log_message('error','TRAINSPEED|请求url:'.$this->url.'|聚合相应时间:'.$api_responsive_time.'s|接口运行时间:'.$responsive_time.'s|+7天:'.$this->seveth);
|
||||
print_r($trainjson);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//搜索模块
|
||||
function Searchtrain($train_date,$fromStation,$toStation){
|
||||
$this->train_date = $train_date;
|
||||
$now_time = time();
|
||||
$this->differ_time = (strtotime($train_date) - $now_time) / 86400;
|
||||
$this->seveth = false;
|
||||
//屏蔽掉超过预售期的搜索,提高速度
|
||||
if($this->differ_time > 29){
|
||||
$train_date = date('Y-m-d',strtotime('+7day'));
|
||||
$this->seveth = true;
|
||||
}
|
||||
$this->url = JUHE_TRAIN_CX_API.'?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
|
||||
$train_info = GetPost_http($this->url);
|
||||
return $train_info;
|
||||
}
|
||||
|
||||
//字符串拼接模块
|
||||
function createTrainJson($returnjson){
|
||||
$return_data = new stdClass();
|
||||
$return_data->data = new stdClass();
|
||||
$return_data->data->httpstatus = 200;
|
||||
$return_data->data->seveth = $this->seveth;
|
||||
$return_data->data->supplier = 'juhe';
|
||||
$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 = '';
|
||||
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.'"';
|
||||
//余票字符串
|
||||
$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.'||'.$this->train_date.'||||||||'.ticket_exchange($value->gjrw_price,$value->gjrw_num,$this->seveth).'|'.ticket_exchange($value->qtxb_price,$value->qtxb_num,$this->seveth).'|'.ticket_exchange($value->rw_price,$value->rw_num,$this->seveth).'|'.ticket_exchange($value->rz_price,$value->rz_num,$this->seveth).'|'.ticket_exchange($value->tdz_price,$value->tdz_num,$this->seveth).'|'.ticket_exchange($value->wz_price,$value->wz_num,$this->seveth).'||'.ticket_exchange($value->yw_price,$value->yw_num,$this->seveth).'|'.ticket_exchange($value->yz_price,$value->yz_num,$this->seveth).'|'.ticket_exchange($value->edz_price,$value->edz_num,$this->seveth).'|'.ticket_exchange($value->ydz_price,$value->ydz_num,$this->seveth).'|'.ticket_exchange($value->swz_price,$value->swz_num,$this->seveth).'|'.ticket_exchange($value->dw_price,$value->dw_num,$this->seveth).'||';
|
||||
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
|
||||
$return_data->data->price[$i] = $data;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$return_data->data->map = (object)$obj;
|
||||
return json_encode($return_data);
|
||||
}
|
||||
|
||||
//携程数据接口
|
||||
public function ctripApi($date=null,$from=null,$to=null,$return=false){
|
||||
if(!$date || !$from || !$to){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
||||
}else{
|
||||
$isCache = false;
|
||||
$iseven = false;
|
||||
$cachedata = false;
|
||||
$now_time = time();
|
||||
$differ = (strtotime($date) - $now_time) / 86400;
|
||||
if($differ > 29){
|
||||
$date = date('Y-m-d',strtotime('+7day'));
|
||||
$iseven = true;
|
||||
}
|
||||
|
||||
//转换三字码为中文
|
||||
$this->load->model("ctrip_model");
|
||||
$FromName = $this->ctrip_model->ReplaceCodeToName($from);
|
||||
$ToName = $this->ctrip_model->ReplaceCodeToName($to);
|
||||
|
||||
|
||||
if(!$FromName || !$ToName){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"httpstatus":404,"data":{"seven":false,"cache":false,"result":[],"map":{}}}');
|
||||
}else{
|
||||
$FromName = $FromName->station_name;
|
||||
$ToName = $ToName->station_name;
|
||||
}
|
||||
|
||||
//生成请求链接
|
||||
$TimeStamp = time();
|
||||
$Sign = md5($TimeStamp.DATAKEY);
|
||||
|
||||
$url = JSONRETURN.'SearchS2S/?From='.urlencode($FromName).'&To='.urlencode($ToName).'&DepartDate='.$date.'&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
||||
|
||||
$api_start_time = microtime(true);
|
||||
|
||||
//获取数据
|
||||
$ResponseJson = GetPost_http($url,'','GET');
|
||||
|
||||
$api_end_time = microtime(true);
|
||||
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
$api_responsive_time = $api_end_time - $api_start_time;
|
||||
|
||||
if(empty($ResponseData->Trains)){
|
||||
log_message('error','ctrip_trian|status:trains is empty |相应时间:'.$api_responsive_time);
|
||||
}else{
|
||||
log_message('error','ctrip_trian|status:'.$ResponseData->ResponseStatus->Ack.'|相应时间:'.$api_responsive_time);
|
||||
}
|
||||
|
||||
//定义返回的json
|
||||
$ReturnData = new stdClass();
|
||||
$ReturnData->httpstatus = 200;
|
||||
$ReturnData->data = new stdClass();
|
||||
$ReturnData->data->seven = $iseven;
|
||||
$ReturnData->data->cache = $isCache;
|
||||
$ReturnData->data->supplier = 'ctrip';
|
||||
$ReturnData->data->result = array();
|
||||
$ReturnData->data->map = new stdClass();
|
||||
$obj = array();
|
||||
$i = 0;
|
||||
$PriceStr = '';
|
||||
|
||||
//数据解析
|
||||
if(!empty($ResponseData->Trains)){
|
||||
foreach ($ResponseData->Trains as $TrainInfo){
|
||||
$obj[$TrainInfo->FromTelcode] = $TrainInfo->FromStationName;
|
||||
$obj[$TrainInfo->ToTelcode] = $TrainInfo->ToStationName;
|
||||
$SeaType = '';
|
||||
//余数初始化为空
|
||||
$gjrwNum = $rwNum = $rzNum = $tdzNum = $wzNum = $yzNum = $edzNum = $ydzNum = $swzNum = $ywNum = $dwNum = $ydwNum = $edzNum = null;
|
||||
foreach($TrainInfo->Seats as $Seats){
|
||||
//从香港出发的 D/G 火车加价3%
|
||||
if($from == 'XJA'){
|
||||
if(stripos($TrainInfo->TrainNo, "G") !== false || stripos($TrainInfo->TrainNo, "D") !== false){
|
||||
$Seats->Price = $Seats->Price * 1.03;
|
||||
}
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '高级软卧上'){
|
||||
$gjrwXiaPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"6":"'.$gjrwXiaPrice.'","A6":"¥'.$Seats->Price.'",';
|
||||
$gjrwNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '软卧上'){
|
||||
$rwPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"4":"'.$rwPrice.'","A4":"¥'.$Seats->Price.'",';
|
||||
$rwNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '一等双软上'){
|
||||
$SeaType .= '"YDW":"¥'.$Seats->Price.'",';
|
||||
$ydwNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '软座'){
|
||||
$rzPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"2":"'.$rzPrice.'","A2":"¥'.$Seats->Price.'",';
|
||||
$rzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '特等座'){
|
||||
$SeaType .= '"P":"¥'.$Seats->Price.'",';
|
||||
$tdzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '无座'){
|
||||
$SeaType .= '"WZ":"¥'.$Seats->Price.'",';
|
||||
$wzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '硬座'){
|
||||
$yzPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"1":"'.$yzPrice.'","A1":"¥'.$Seats->Price.'",';
|
||||
$yzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '二等座'){
|
||||
$SeaType .= '"O":"¥'.$Seats->Price.'",';
|
||||
$edzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '一等座'){
|
||||
$SeaType .= '"M":"¥'.$Seats->Price.'",';
|
||||
$ydzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '商务座'){
|
||||
$swzPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"9":"'.$swzPrice.'","A9":"¥'.$Seats->Price.'",';
|
||||
$swzNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '硬卧上'){
|
||||
$ywPrice = $Seats->Price * 10;
|
||||
$SeaType .= '"3":"'.$ywPrice.'","A3":"¥'.$Seats->Price.'",';
|
||||
$ywNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '二等双软上'){
|
||||
$SeaType .= '"EDW":"¥'.$Seats->Price.'",';
|
||||
$erwNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
if($Seats->SeatName == '动卧上'){
|
||||
$SeaType .= '"F":"¥'.$Seats->Price.'",';
|
||||
$dwNum = $Seats->TicketLeft;
|
||||
}
|
||||
|
||||
$PriceStr = $SeaType.'"train_no":'.'"'.$TrainInfo->TrainNo.'"';
|
||||
|
||||
}
|
||||
|
||||
//对返回的数据进行容错处理
|
||||
$gjrwNum = isset($gjrwNum) ? ticket_exchange($Seats->Price,$gjrwNum,$iseven) : '';
|
||||
$rwNum = isset($rwNum) ? ticket_exchange($Seats->Price,$rwNum,$iseven) : '';
|
||||
$rzNum = isset($rzNum) ? ticket_exchange($Seats->Price,$rzNum,$iseven) : '';
|
||||
$tdzNum = isset($tdzNum) ? ticket_exchange($Seats->Price,$tdzNum,$iseven) : '';
|
||||
$wzNum = isset($wzNum) ? ticket_exchange($Seats->Price,$wzNum,$iseven) : '';
|
||||
$ywNum = isset($ywNum) ? ticket_exchange($Seats->Price,$ywNum,$iseven) : '';
|
||||
$yzNum = isset($yzNum) ? ticket_exchange($Seats->Price,$yzNum,$iseven) : '';
|
||||
$edzNum = isset($edzNum) ? ticket_exchange($Seats->Price,$edzNum,$iseven) : '';
|
||||
$ydzNum = isset($ydzNum) ? ticket_exchange($Seats->Price,$ydzNum,$iseven) : '';
|
||||
$swzNum = isset($swzNum) ? ticket_exchange($Seats->Price,$swzNum,$iseven) : '';
|
||||
$dwNum = isset($dwNum) ? ticket_exchange($Seats->Price,$dwNum,$iseven) : '';
|
||||
$ydwNum = isset($ydwNum) ? ticket_exchange($Seats->Price,$ydwNum,$iseven) : '';
|
||||
$erwNum = isset($erwNum) ? ticket_exchange($Seats->Price,$erwNum,$iseven) : '';
|
||||
|
||||
$runMin = $TrainInfo->DurationMinutes % 60;
|
||||
$runHour = ($TrainInfo->DurationMinutes - $runMin) / 60;
|
||||
|
||||
$ReturnData->data->result[$i] = '|预定|'.$TrainInfo->Train12306No.'|'.$TrainInfo->TrainNo.'|'.$TrainInfo->FromStationName.'|'.$TrainInfo->ToStationName.'|'.$TrainInfo->FromTelcode.'|'.$TrainInfo->ToTelcode.'|'.$TrainInfo->StartTime.'|'.$TrainInfo->ArriveTime.'|'.$runHour.':'.$runMin.'|'.$TrainInfo->CanWebBuy.'||'.date('Ymd',strtotime($date)).'||||||||'.$gjrwNum.'||'.$rwNum.'|'.$rzNum.'|'.$tdzNum.'|'.$wzNum.'||'.$ywNum.'|'.$yzNum.'|'.$edzNum.'|'.$ydzNum.'|'.$swzNum.'|'.$dwNum.'|||'.$ydwNum.'|'.$erwNum;
|
||||
|
||||
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$PriceStr.'},"messages":[],"validateMessages":{}}';
|
||||
$ReturnData->data->price[$i] = $data;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
//print_r($ResponseData);die();
|
||||
$ReturnData->data->map = (object)$obj;
|
||||
if($return){
|
||||
return json_encode($ReturnData);
|
||||
}else{
|
||||
echo json_encode($ReturnData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//查询经停站(基于携程api)
|
||||
public function getstopstation(){
|
||||
//接收参数
|
||||
$DepartDate = $this->input->get_post('DepartDate');
|
||||
$TrainNo = $this->input->get_post('TrainNo');
|
||||
|
||||
if(!$DepartDate || !$TrainNo){
|
||||
exit('传参错误!');
|
||||
}else{
|
||||
//生成请求链接
|
||||
$TimeStamp = time();
|
||||
$Sign = md5($TimeStamp.DATAKEY);
|
||||
|
||||
$url = JSONRETURN.'GetStopStations/?DepartDate='.$DepartDate.'&TrainNo='.$TrainNo.'&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
||||
|
||||
$ResponseJson = GetPost_http($url,'','GET');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
//构造12306格式
|
||||
$ReturnData = array();
|
||||
$ReturnData['validateMessagesShowId'] = '_validatorMessage';
|
||||
$ReturnData['status'] = true;
|
||||
$ReturnData['httpstatus'] = 200;
|
||||
$ReturnData['data'] = array();
|
||||
$i = 0;
|
||||
$Last_num = count($ResponseData->StopStations);
|
||||
foreach($ResponseData->StopStations as $items){
|
||||
if($i == 0){
|
||||
$ReturnData['data']['data'][$i]['start_station_name'] = $items->StationName;
|
||||
$ReturnData['data']['data'][$i]['station_train_code'] = $TrainNo;
|
||||
$ReturnData['data']['data'][$i]['end_station_name'] = $ResponseData->StopStations[$Last_num-1]->StationName;
|
||||
}
|
||||
$ReturnData['data']['data'][$i]['arrive_time'] = $items->ArrivalTime;
|
||||
$ReturnData['data']['data'][$i]['station_name'] = $items->StationName;
|
||||
$ReturnData['data']['data'][$i]['start_time'] = $items->StartTime;
|
||||
$ReturnData['data']['data'][$i]['stopover_time'] = $items->StopMinutes;
|
||||
$ReturnData['data']['data'][$i]['station_no'] = $items->StationNo;
|
||||
$ReturnData['data']['data'][$i]['isEnabled'] = true;
|
||||
$i++;
|
||||
}
|
||||
$ReturnData['messages'] = array();
|
||||
$ReturnData['validateMessages'] = new stdClass();
|
||||
print_r(json_encode($ReturnData));
|
||||
}
|
||||
}
|
||||
|
||||
//获取所有站点信息(基于携程api)
|
||||
public function getallstation(){
|
||||
//生成请求参数
|
||||
$TimeStamp = time();
|
||||
$Sign = md5($TimeStamp.DATAKEY);
|
||||
|
||||
$url = JSONRETURN.'/GetAllStations/?&User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign;
|
||||
|
||||
$ResponseJson = GetPost_http($url,'','GET');
|
||||
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
$data = array();
|
||||
foreach ($ResponseData->Stations as $items){
|
||||
$data['StationName'] = isset($items->StationName) ? checkNull($items->StationName) : '';
|
||||
$data['PinYin'] = isset($items->PinYin) ? checkNull($items->PinYin) : '';
|
||||
$data['Telecode'] = isset($items->Telecode) ? checkNull($items->Telecode) : '';
|
||||
$data['Address'] = isset($items->Address) ? checkNull($items->Address) : '';
|
||||
$data['Geography'] = isset($items->Geography) ? checkNull($items->Geography) : '';
|
||||
$this->load->model("ctrip_model");
|
||||
$this->ctrip_model->AddOrUpdate($data);
|
||||
}
|
||||
}
|
||||
|
||||
//查询中转方案(基于携程api)
|
||||
public function gettraintrainsfer(){
|
||||
$FromCode = $this->input->get_post('FromCode');
|
||||
$ToCode = $this->input->get_post('ToCode');
|
||||
$DepartDate = $this->input->get_post('DepartDate');
|
||||
|
||||
if(!$FromCode || !$ToCode || !$DepartDate){
|
||||
exit('传参错误!');
|
||||
}else{
|
||||
$TimeStamp = time();
|
||||
$Sign = md5($TimeStamp.DATAKEY);
|
||||
$this->load->model("ctrip_model");
|
||||
$FromName = $this->ctrip_model->ReplaceCodeToName($FromCode);
|
||||
$ToName = $this->ctrip_model->ReplaceCodeToName($ToCode);
|
||||
|
||||
$From = $FromName->station_name;
|
||||
$To = $ToName->station_name;
|
||||
|
||||
$url = JSONRETURN.'GetTrainTransfer?User='.DATAUSER.'&TimeStamp='.$TimeStamp.'&Sign='.$Sign.'&From='.urlencode($From).'&To='.urlencode($To).'&DepartDate='.$DepartDate;
|
||||
|
||||
|
||||
$ResponseJson = GetPost_http($url,'','GET');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
$priceAddSeats = ['软卧','硬卧'];
|
||||
foreach ($ResponseData->TransferLines as $methodsItems){
|
||||
foreach($methodsItems->Trains as $trainsItems){
|
||||
foreach ($trainsItems->Seats as $seatsItems){
|
||||
if(in_array($seatsItems->SeatName,$priceAddSeats)){
|
||||
$seatsItems->Price = ceil($seatsItems->Price * 1.2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
print_r(json_encode($ResponseData));
|
||||
}
|
||||
}
|
||||
|
||||
//火车移动端数据接口
|
||||
public function get_train(){
|
||||
$train_date = $this->input->get('date');
|
||||
$fromStation = $this->input->get('from');
|
||||
$toStation = $this->input->get('to');
|
||||
if(!$train_date || !$fromStation || !$toStation){
|
||||
exit('传参错误!');
|
||||
}
|
||||
|
||||
$back_json = $this->ctripApi($train_date,$fromStation,$toStation,true);
|
||||
|
||||
$train_info = new stdClass();
|
||||
$train_info = json_decode($back_json);
|
||||
|
||||
$return_data = new stdClass();
|
||||
$return_data->status = 200;
|
||||
$return_data->search = new stdClass();
|
||||
$return_data->search->FromStationCode = $fromStation;
|
||||
$return_data->search->ToStationCode = $toStation;
|
||||
$return_data->search->StartDate = $train_date;
|
||||
|
||||
$return_data->CardFee = 3;
|
||||
//MainlandChina:大陆内地寄送费用
|
||||
//HMT:港澳台寄送费用
|
||||
//寄送费按订单收,无论多少张票,没有取票费
|
||||
//$return_data->MainlandChina = 6;
|
||||
//$return_data->HMT = 15;
|
||||
$this->load->library('Currency');
|
||||
define("CONST_SITE_CURRENCY","USD");
|
||||
$return_data->ExRate = $this->currency->get_site_currencyrate();
|
||||
$return_data->result = array();
|
||||
$i = 0;
|
||||
|
||||
foreach ($train_info->data->result as $value){
|
||||
$return_data->result[$i] = new StdClass();
|
||||
$data = explode('|', $value);
|
||||
$return_data->result[$i]->TrainNo = $data[2];
|
||||
$return_data->result[$i]->TrainCode = $data[3];
|
||||
$return_data->result[$i]->TrainType = substr(ucwords($data[3]), 0, 1);
|
||||
$return_data->result[$i]->StartStationCode = $data[4];
|
||||
$return_data->result[$i]->EndStationCode = $data[5];
|
||||
$return_data->result[$i]->DepartStation = '';
|
||||
$return_data->result[$i]->DepartStationCode = $data[6];
|
||||
$return_data->result[$i]->DepartStationNo = '';
|
||||
$return_data->result[$i]->ArriveStation = '';
|
||||
$return_data->result[$i]->ArriveStationCode = $data[7];
|
||||
$return_data->result[$i]->ArriveStationNo = '';
|
||||
$return_data->result[$i]->DepartTime = $data[8];
|
||||
$return_data->result[$i]->ArriveTime = $data[9];
|
||||
$return_data->result[$i]->RunTime = $data[10];
|
||||
$return_data->result[$i]->IsBookable = true;
|
||||
//$return_data->result[$i]->SeatType = '123456789OMPA';
|
||||
$return_data->result[$i]->cached = 1;
|
||||
//$return_data->result[$i]->CheapSeat = new stdClass();
|
||||
$price = json_decode($train_info->data->price[$i]);
|
||||
|
||||
$return_data->result[$i]->CheapSeat = null;
|
||||
$return_data->result[$i]->SeatList = array();
|
||||
//做一个数据存储所有的座位类型的余票
|
||||
$seat_yp_map = array(
|
||||
'A' => $data[21], //高级软卧
|
||||
'A6' => $data[21], //高级软卧
|
||||
'H' => $data[22], //其他
|
||||
'A4' => $data[23], //软卧
|
||||
'A2' => $data[24], //软座
|
||||
'P' => $data[25], //特等座
|
||||
'WZ' => $data[26],//无座
|
||||
'X' => $data[26], //无座
|
||||
'A3' => $data[28], //硬卧
|
||||
'A1' => $data[29], //硬座
|
||||
'O' => $data[30], //二等座
|
||||
'A8' => $data[30], //二等座
|
||||
'A7' => $data[31], //一等座
|
||||
'M' => $data[31], //一等座
|
||||
'A9' => $data[32], //商务座
|
||||
'F' => $data[33], //动卧
|
||||
'YDW' => $data[36], //一等卧
|
||||
'EDW' => $data[37], //二等卧
|
||||
);
|
||||
$j=0;
|
||||
$soldoutnums = 0;
|
||||
foreach($price->data as $key=>$value){
|
||||
if($key != 'train_no'){
|
||||
if(!is_numeric($key)){
|
||||
$return_data->result[$i]->SeatList[$j] = new StdClass();
|
||||
$return_data->result[$i]->SeatList[$j]->SeatCode = $key;
|
||||
$return_data->result[$i]->SeatList[$j]->SeatName = get_name($key);
|
||||
$value = str_replace('¥','',$value);
|
||||
|
||||
if(in_array($key, array('A3', 'A4', 'A5', 'A6', '3', '4', '5', '6', 'A', 'F', 'S','YDW','EDW'))){
|
||||
if (stripos($return_data->result[$i]->TrainNo, "D") !== false || stripos($return_data->result[$i]->TrainNo, "G") !== false) {
|
||||
$value = $value * 1.2;
|
||||
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 1;
|
||||
}else{
|
||||
$value = $value * 1.15;
|
||||
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.75;
|
||||
}
|
||||
}else{
|
||||
$return_data->result[$i]->SeatList[$j]->ChildDiscut = 0.5;
|
||||
}
|
||||
/*
|
||||
if (stripos($value, ".")) {//判断是否是整数,避免类似ecil(9.9*10)=100
|
||||
$value = ceil($value);
|
||||
}*/
|
||||
$return_data->result[$i]->SeatList[$j]->SeatPrice = $this->currency->GetSiteMoney($value);
|
||||
$return_data->result[$i]->SeatList[$j]->SeatPriceRMB = $value;
|
||||
if($fromStation == 'LSO' || $toStation == 'LSO'){
|
||||
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 33;
|
||||
}else{
|
||||
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 6;
|
||||
}
|
||||
if($fromStation == 'XJA' && stripos($return_data->result[$i]->TrainNo, "G") && $value > 500){
|
||||
$return_data->result[$i]->SeatList[$j]->ServiceCharge = 10;
|
||||
}
|
||||
$return_data->result[$i]->SeatList[$j]->ServiceChargeRMB = $return_data->result[$i]->SeatList[$j]->ServiceCharge * $return_data->ExRate;
|
||||
|
||||
$return_data->result[$i]->SeatList[$j]->SeatInventory = $seat_yp_map[$key];
|
||||
if($return_data->result[$i]->SeatList[$j]->SeatInventory == '有'){
|
||||
$return_data->result[$i]->SeatList[$j]->SeatInventory = 99;
|
||||
}elseif($return_data->result[$i]->SeatList[$j]->SeatInventory == '无'){
|
||||
$return_data->result[$i]->SeatList[$j]->SeatInventory = 0;
|
||||
$soldoutnums++;
|
||||
}
|
||||
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($soldoutnums >= $j){
|
||||
$return_data->result[$i]->soldout = true;
|
||||
}else{
|
||||
$return_data->result[$i]->soldout = false;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
print_r(json_encode($return_data));
|
||||
}
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
class BIZ_intel_train_model extends CI_Model {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
//查询火车列表信息
|
||||
public function get_train_info($trainFromCode,$trainToCode){
|
||||
if($trainFromCode == 'CHBJ'){
|
||||
$add = "OR tl.trainFromCode = 'CHPW'";
|
||||
}else{
|
||||
$add = "";
|
||||
}
|
||||
$sql = "
|
||||
SELECT
|
||||
tl.trainNo,
|
||||
tl.trainFrom,
|
||||
tl.trainFromCode,
|
||||
(select s_country from TrainStation_intel where s_code = tl.trainFromCode) as from_country,
|
||||
tl.trainTo,
|
||||
tl.trainToCode,
|
||||
(select s_country from TrainStation_intel where s_code = tl.trainToCode) as to_country,
|
||||
tl.trainType,
|
||||
tl.train_no,
|
||||
tl.trainUse,
|
||||
tl.RunTime,
|
||||
tl.departTime,
|
||||
(select top 1 trainArrive from trainlistDetail where train_no = tl.train_no order by trainOrder desc) as arriveTime,
|
||||
tl.UseDay,
|
||||
tl.DateRule,
|
||||
tl.TrainMessage,
|
||||
tp.seatPriceInfo2
|
||||
FROM
|
||||
trainlist tl
|
||||
left join
|
||||
trainPrice tp
|
||||
on
|
||||
tl.train_no = tp.train_no
|
||||
WHERE
|
||||
tl.isGlobal = 1
|
||||
AND
|
||||
(tl.trainFromCode = '{$trainFromCode}' {$add})
|
||||
AND
|
||||
tl.trainToCode = '{$trainToCode}'
|
||||
AND
|
||||
tl.DateRule != ''
|
||||
AND
|
||||
tp.seatPriceInfo2 IS NOT NULL
|
||||
order by departTime asc
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_code_by_name($name){
|
||||
$sql = "select s_code from TrainStation_intel where s_ename = '{$name}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_seatname($seat_code){
|
||||
$sql = "select Seat_EName1,Seat_Pic from TrainSeat_Intel where Seat_code = '{$seat_code}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
//获取一列指定火车数据
|
||||
public function get_one_train($train_no){
|
||||
$sql = "
|
||||
SELECT
|
||||
*,
|
||||
(select s_country from TrainStation_intel where trainFromCode = s_code ) as From_country,
|
||||
(select s_country from TrainStation_intel where trainToCode = s_code ) as To_country,
|
||||
(select top 1 trainArrive from trainlistDetail where train_no = tl.train_no order by trainOrder desc) as localarriveTime
|
||||
FROM
|
||||
trainlist tl
|
||||
LEFT JOIN
|
||||
trainPrice tp
|
||||
ON
|
||||
tl.train_no = tp.train_no
|
||||
WHERE
|
||||
tl.train_no = '{$train_no}'
|
||||
AND
|
||||
isGlobal = 1
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_allinteltrain(){
|
||||
$sql = "
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
TrainStation_intel
|
||||
LEFT JOIN
|
||||
trainlist
|
||||
ON
|
||||
s_code = trainFromCode
|
||||
WHERE
|
||||
trainFrom != 'NULL'
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_seat_info($seat_code){
|
||||
$sql = "SELECT Seat_CName,Seat_EName1 FROM TrainSeat_Intel WHERE Seat_Code = '{$seat_code}'";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_train_station($train_no){
|
||||
$sql = "SELECT * FROM trainlistDetail WHERE train_no = '{$train_no}' order by trainOrder asc";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_allstations(){
|
||||
$sql = "SELECT * FROM TrainStation_intel where station_id != 1";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function ch_allstations(){
|
||||
$sql = "select
|
||||
tsi1.s_ename as fromStationName,
|
||||
tsi1.s_country as fromStationCountry,
|
||||
tsi2.s_ename as toStationName,
|
||||
tsi2.s_country as toStationCountry,
|
||||
tsi_Message
|
||||
from TrainSearch_intel
|
||||
left join
|
||||
TrainStation_intel tsi1
|
||||
ON
|
||||
tsi1.station_id = tsi_FromStation
|
||||
left join
|
||||
TrainStation_intel tsi2
|
||||
ON
|
||||
tsi2.station_id = tsi_ToStation
|
||||
where tsi1.s_country = 'china' or tsi2.s_country = 'china'
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function get_train_rules($station_id){
|
||||
if($station_id == 11){
|
||||
$station = "or tsi_FromStation = 10";
|
||||
}elseif($station_id == 2){
|
||||
$station = "or tsi_FromStation = 9";
|
||||
}else{
|
||||
$station = "";
|
||||
}
|
||||
$sql = "SELECT
|
||||
S_ename,s_country,tsi_Message
|
||||
FROM
|
||||
TrainSearch_intel
|
||||
LEFT JOIN
|
||||
TrainStation_intel
|
||||
ON
|
||||
tsi_ToStation = station_id
|
||||
where
|
||||
tsi_FromStation = '{$station_id}'";
|
||||
$sql .= $station;
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function ch_train_rules($station_id){
|
||||
if($station_id == 11){
|
||||
$station = "or tsi_FromStation = 10";
|
||||
}elseif($station_id == 2){
|
||||
$station = "or tsi_FromStation = 9";
|
||||
}else{
|
||||
$station = "";
|
||||
}
|
||||
$sql = "SELECT
|
||||
S_ename,s_country,tsi_Message
|
||||
FROM
|
||||
TrainSearch_intel
|
||||
LEFT JOIN
|
||||
TrainStation_intel
|
||||
ON
|
||||
tsi_ToStation = station_id
|
||||
where
|
||||
(tsi_FromStation = ?)
|
||||
";
|
||||
$sql .= $station;
|
||||
$query = $this->HT->query($sql,array($station_id));
|
||||
return $query->result();
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
function tpmeta(meta_act, ibd_id, ibd_Itemvalue = "", ibd_ItemType = "", ibd_ItemDescription = "") {
|
||||
if (meta_act == "save") {
|
||||
var url = "/info.php/infobokundata/save_meta"
|
||||
}
|
||||
if (meta_act == "delete") {
|
||||
if (confirm("是否删除该属性?")) {
|
||||
var url = "/info.php/infobokundata/delete_meta"
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: {
|
||||
"ibd_id": ibd_id,
|
||||
"ibd_Itemvalue": ibd_Itemvalue,
|
||||
"ibd_ItemType": ibd_ItemType,
|
||||
"ibd_ItemDescription": ibd_ItemDescription
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
for (var key in data) {
|
||||
if (data[key].name == "ok") {
|
||||
if (meta_act == "delete") {
|
||||
// alert("sss");
|
||||
$("#" + ibd_id).closest("div.box").remove();
|
||||
// alert("end");
|
||||
}
|
||||
$.modaldialog.success(data[key].value);
|
||||
return true
|
||||
} else {
|
||||
$.modaldialog.error(data[key].value)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
error: function () {
|
||||
$.modaldialog.error("更新失败..")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function addmeta(ibd_ic_id,ibd_parentId=0,ibd_ItemName,ibd_Itemvalue="",ibd_ItemType="",ibd_ItemDescription="") {
|
||||
var url = "/info.php/infobokundata/add_meta";
|
||||
if (ibd_ItemName=="" || typeof(ibd_ItemName) == undefined){
|
||||
$.modaldialog.error("更新失败,属性名称必须选择!")
|
||||
return false;
|
||||
}
|
||||
if (ibd_Itemvalue=="" || typeof(ibd_Itemvalue) == undefined){
|
||||
$.modaldialog.error("更新失败,属性值必须填写!")
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$.ajax({
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
url: url,
|
||||
data: {
|
||||
"ibd_ic_id": ibd_ic_id,
|
||||
"ibd_parentId":ibd_parentId,
|
||||
"ibd_ItemName":ibd_ItemName,
|
||||
"ibd_Itemvalue": ibd_Itemvalue,
|
||||
"ibd_ItemType": ibd_ItemType,
|
||||
"ibd_ItemDescription": ibd_ItemDescription
|
||||
},
|
||||
success: function (data, textStatus) {
|
||||
for (var key in data) {
|
||||
if (data[key].name == "ok") {
|
||||
$.modaldialog.success(data[key].value);
|
||||
return true
|
||||
} else {
|
||||
$.modaldialog.error(data[key].value)
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
error: function () {
|
||||
$.modaldialog.error("更新失败..")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function CheckAddBox() {
|
||||
if ($("#js_AddBokunBox").is(":visible")){
|
||||
$("#js_AddBokunBox").hide();
|
||||
}else{
|
||||
$("#js_AddBokunBox").show();
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
<IfModule mod_php5.c>
|
||||
php_value engine off
|
||||
</IfModule>
|
||||
<IfModule mod_php4.c>
|
||||
php_value engine off
|
||||
</IfModule>
|
Loading…
Reference in New Issue