添加机票搜索接口

hotfix/paypal-note
赵鹏 4 years ago
parent 3adf6d249a
commit 4b4309bcfe

@ -2,18 +2,23 @@
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class api extends CI_Controller{
public function __construct(){
class api extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('tuniu');
$this->load->model('flight_model');
}
public function index(){
public function index()
{
exit('前方高能!!');
}
//帐号绑定
public function bindAccount(){
public function bindAccount()
{
$timestamp = time();
$data = '{"account":"phoebe@hainatravel.com","defaultPay":0}';
$sign = md5(TUNIU_FLIGHT_KEY . $data . $timestamp);
@ -27,11 +32,11 @@ class api extends CI_Controller{
$returnJson = post_tuniu(TUNIU_FLIGHT_API, $accountJson, 'POST');
//print_r($returnData);
echo $returnJson;
}
//查询钱包接口
public function checkWallet(){
public function checkWallet()
{
$timestamp = time();
$data = '{}';
$sign = md5(TUNIU_FLIGHT_KEY . $data . $timestamp);
@ -48,7 +53,8 @@ class api extends CI_Controller{
}
//保险查询
public function getinsurance(){
public function getinsurance()
{
$timestamp = time();
$data = '{}';
$sign = md5(TUNIU_FLIGHT_KEY . $data . $timestamp);
@ -65,7 +71,8 @@ class api extends CI_Controller{
}
//查询接口
public function searchForHt(){
public function searchForHt()
{
$departDate = $this->input->get_post('departDate');
$departCode = $this->input->get_post('departCode');
$arriveCode = $this->input->get_post('arriveCode');
@ -82,7 +89,8 @@ class api extends CI_Controller{
}
//下单接口
public function addorders(){
public function addorders()
{
//接收参数
$departime = $this->input->get_post('departime');
$fromcode = $this->input->get_post('fromcode');
@ -125,7 +133,8 @@ class api extends CI_Controller{
}
//请求支付接口
public function payorders(){
public function payorders()
{
$order = $this->input->get_post('order');
$order = '1226443588';
@ -149,7 +158,8 @@ class api extends CI_Controller{
}
//单个订单详情查询接口
public function getorderinfos(){
public function getorderinfos()
{
$order = $this->input->get_post('order');
if (empty($order)) {
@ -172,7 +182,8 @@ class api extends CI_Controller{
}
//机票退票费查询接口
public function refundfee(){
public function refundfee()
{
$order = $this->input->get_post('order');
$ticketcode = $this->input->get_post('ticketcode');
$order = '1226443588';
@ -199,7 +210,8 @@ class api extends CI_Controller{
}
//机票退票接口
public function refundapply(){
public function refundapply()
{
$order = $this->input->get_post('order');
$ticketcode = $this->input->get_post('ticketcode');
$order = '1226443588';
@ -219,11 +231,139 @@ class api extends CI_Controller{
"function": "refundApply",
"data":' . $data . '
}';
echo $returnorderjson;die();
echo $returnorderjson;
die();
$returnJson = post_tuniu(TUNIU_FLIGHT_API, $returnorderjson, 'POST');
echo $returnJson;
}
}
//返回三字码接口
public function ajaxGetCodeAndName($flag = false)
{
//http://202.103.68.104:61/info.php/apps/flightsystem/api/ajaxGetCodeAndName/ //测试地址
$returnData = new stdClass();
$allCityNameAndCode = $this->flight_model->getAllCityCodeAndName();
$returnJson = json_encode($allCityNameAndCode);
//return $returnJson;
if ($flag) {
return $returnJson;
} else {
echo $returnJson;
}
}
//获取所有机场信息
public function ajaxGetAirPort()
{
$returnData = new stdClass();
$airPortCodeAndName = $this->flight_model->getAllAirPort();
$returnData = array();
foreach ($airPortCodeAndName as $items) {
$returnData[$items->air_threeChar] = $items->air_english_name;
}
$returnJson = json_encode($returnData);
print_r($returnJson);
}
//查询接口
public function search()
{
//http://202.103.68.104:61/info.php/apps/flightsystem/api/search/?departDate=2021-09-04&departCode=BJS&arriveCode=KWL //测试地址
$departDate = $this->input->get_post('departDate');
$departCode = $this->input->get_post('departCode');
$arriveCode = $this->input->get_post('arriveCode');
$flightnumber = $this->input->get_post('flightnumber');
if (empty($departDate) || empty($departCode) || empty($arriveCode)) {
exit('error');
}
$postJson = get_serach_json($departDate, $departCode, $arriveCode, $flightnumber);
//echo $postJson;die();
$returnJson = post_tuniu(TUNIU_FLIGHT_API, $postJson, 'POST');
$returnData = json_decode($returnJson);
//print_r($returnJson);die();
$cacheData = new stdClass();
if (!empty($returnData)) {
$cacheData->success = $returnData->success;
$cacheData->msg = $returnData->msg;
$cacheData->errorCode = $returnData->errorCode;
$cacheData->queryResultList = array();
$i = 0;
//$airPortCodeAndName = json_decode($redis->get('airPortCodeAndName'));
$airPortCodeAndName = $this->ajaxGetCodeAndName(true);
//print_r($airPortCodeAndName);die();
foreach ($returnData->data->queryResultList as $items) {
$cacheData->queryResultList[$i] = new stdClass();
$cacheData->queryResultList[$i]->flight = new stdClass();
//航班信息
$cacheData->queryResultList[$i]->flight->flightNo = $items->flight->flightNo;
$cacheData->queryResultList[$i]->flight->craftType = $items->flight->craftType;
$cacheData->queryResultList[$i]->flight->airlineCompany = $items->flight->airlineCompany;
$cacheData->queryResultList[$i]->flight->airlineIataCode = $items->flight->airlineIataCode;
$cacheData->queryResultList[$i]->flight->arriveAirportCode = $items->flight->arriveAirportCode;
$cacheData->queryResultList[$i]->flight->arriveAirportName = $items->flight->arriveAirportName;
$arriveAirportCode = $items->flight->arriveAirportCode;
$cacheData->queryResultList[$i]->flight->arriveAirportNameEn = $this->flight_model->getAirPortNameEn($items->flight->arriveAirportCode); //$airPortCodeAndName->$arriveAirportCode;
$cacheData->queryResultList[$i]->flight->arriveAirportTerminal = $items->flight->arriveAirportTerminal;
$cacheData->queryResultList[$i]->flight->arriveCityIataCode = $items->flight->arriveCityIataCode;
$cacheData->queryResultList[$i]->flight->arriveCityName = $items->flight->arriveCityName;
$cacheData->queryResultList[$i]->flight->arriveDate = $items->flight->arriveDate;
$cacheData->queryResultList[$i]->flight->arriveTime = $items->flight->arriveTime;
$cacheData->queryResultList[$i]->flight->departAirportCode = $items->flight->departAirportCode;
$cacheData->queryResultList[$i]->flight->departAirportName = $items->flight->departAirportName;
$departAirportCode = $items->flight->departAirportCode;
$cacheData->queryResultList[$i]->flight->departAirportNameEn = $this->flight_model->getAirPortNameEn($items->flight->departAirportCode); //$airPortCodeAndName->$departAirportCode;
$cacheData->queryResultList[$i]->flight->departAirportTerminal = $items->flight->departAirportTerminal;
$cacheData->queryResultList[$i]->flight->departCityIataCode = $items->flight->departCityIataCode;
$cacheData->queryResultList[$i]->flight->departCityName = $items->flight->departCityName;
$cacheData->queryResultList[$i]->flight->departDate = $items->flight->departDate;
$cacheData->queryResultList[$i]->flight->departTime = $items->flight->departTime;
$cacheData->queryResultList[$i]->flight->duration = $items->flight->duration;
$cacheData->queryResultList[$i]->flight->meal = $items->flight->meal;
$cacheData->queryResultList[$i]->flight->stopInformation = $items->flight->stopInformation;
$cacheData->queryResultList[$i]->flight->stopNum = $items->flight->stopNum;
$cacheData->queryResultList[$i]->flight->stopPointList = $items->flight->stopPointList;
//航班对应可用的资源列表
$cacheData->queryResultList[$i]->resourceList = array();
$j = 0;
foreach ($items->resourceList as $resourceItems) {
$cacheData->queryResultList[$i]->resourceList[$j] = new stdClass();
$cacheData->queryResultList[$i]->resourceList[$j]->price = new stdClass();
$cacheData->queryResultList[$i]->resourceList[$j]->price->adultPrice = $resourceItems->price->adultPrice;
$cacheData->queryResultList[$i]->resourceList[$j]->price->childPrice = $resourceItems->price->childPrice;
$cacheData->queryResultList[$i]->resourceList[$j]->price->adultFacePrice = $resourceItems->price->adultFacePrice;
$cacheData->queryResultList[$i]->resourceList[$j]->price->childFacePrice = $resourceItems->price->childFacePrice;
$cacheData->queryResultList[$i]->resourceList[$j]->price->cabinClassFullPrice = $resourceItems->price->cabinClassFullPrice;
$cacheData->queryResultList[$i]->resourceList[$j]->price->adultTax = $resourceItems->price->adultTax;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList = array();
$k = 0;
foreach ($resourceItems->cabinList as $cabinListItems) {
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k] = new stdClass();
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->cabinClass = $cabinListItems->cabinClass;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->cabinClassName = $cabinListItems->cabinClassName;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->freeLuggage = $cabinListItems->freeLuggage;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->freeLuggageUnit = $cabinListItems->freeLuggageUnit;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->billType = $cabinListItems->billType;
$cacheData->queryResultList[$i]->resourceList[$j]->cabinList[$k]->seatStatus = $cabinListItems->seatStatus;
$k++;
}
$j++;
}
$i++;
}
print_r(json_encode($cacheData));
}
}
}

@ -0,0 +1,77 @@
<?php
class flight_model extends CI_Model{
function __construct(){
parent::__construct();
$this->INFO = $this->load->database('INFO', TRUE);
$this->HT=$this->load->database('HT',TRUE);
}
//public $FlightAPI_Code = "http://202.103.68.156:9032"; //本地
public $FlightAPI_Code = "https://www.trainspread.com"; //网前
public function getAllCityCodeAndName(){
$sql = "select city_chinese_name,city_english_name,city_threeChar from city_threeChar";
$query = $this->INFO->query($sql);
return $query->result();
}
public function getAllAirPort(){
$sql = "select air_threeChar,air_english_name from air_threeChar";
$query = $this->INFO->query($sql);
return $query->result();
}
/**
* 根据机场code获取对于的机场英文名 20201229 zp 接口数据突然无法获取机场英文名,估计是删除缓存获取以后的错误
*/
public function getAirPortNameEn($code){
$sql = "select top 1 air_english_name from air_threeChar where air_threeChar ='".$code."'";
$query = $this->INFO->query($sql);
$row = $query->row();
if (isset($row)){
return $row->air_english_name;
}else{
return "";
}
}
/*
* 根据三字码获取对应城市的英文名称
*/
public function getCityNameFromCode($code){
$result = "";
$Url_FlightCode = $this->FlightAPI_Code."/flight/ajaxGetCodeAndName/";
$FlightCodeList = get_http($Url_FlightCode); //获取接口机场列表Json
$Json_FlightCode = json_decode($FlightCodeList);
if (!empty($code)){
foreach($Json_FlightCode as $Item){
if ($Item->city_threeChar==$code){
$result=$Item->city_english_name;
break;
}
}
}
return $result;
}
/*
* 根据航线二字码获取对应的航空公司英文名
*/
public function getAirlineNameEn($code){
$sql = "select top 1 NameEN,NameCN from AirCompany where Code='".$code."'";
$query = $this->HT->query($sql);
$row = $query->row();
if (isset($row)){
return $row->NameEN;
}else{
return "";
}
}
}
?>
Loading…
Cancel
Save