Merge branch 'master' of https://gitee.com/hainatravel/information-system
commit
2f9ea4884e
@ -1,158 +0,0 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class Gaapi extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->permission->is_admin();
|
||||
$this->site_code = $this->config->item('site_code');
|
||||
//ga verder
|
||||
$this->load->library('MY_Composer');
|
||||
}
|
||||
|
||||
public function user_track()
|
||||
{
|
||||
$cid = $this->input->get_post('cid');
|
||||
$analytics = $this->initializeAnalytics();
|
||||
$response = $this->getReport($analytics, $cid);
|
||||
$this->printResults($response);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes an Analytics Reporting API V4 service object.
|
||||
*
|
||||
* @return An authorized Analytics Reporting API V4 service object.
|
||||
*/
|
||||
function initializeAnalytics()
|
||||
{
|
||||
|
||||
// Use the developers console and download your service account
|
||||
// credentials in JSON format. Place them in this directory or
|
||||
// change the key file location if necessary.
|
||||
$KEY_FILE_LOCATION = __DIR__ . '/gaapi_json/sylvan-box-234910-357cb59e6bf0.json';
|
||||
|
||||
// Create and configure a new client object.
|
||||
$client = new Google_Client();
|
||||
$client->setApplicationName("User Tracker");
|
||||
$client->setAuthConfig($KEY_FILE_LOCATION);
|
||||
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
|
||||
$analytics = new Google_Service_AnalyticsReporting($client);
|
||||
|
||||
return $analytics;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Queries the Analytics Reporting API V4.
|
||||
*
|
||||
* @param service An authorized Analytics Reporting API V4 service object.
|
||||
* @return The Analytics Reporting API V4 response.
|
||||
*/
|
||||
function getReport($analytics, $cid_no)
|
||||
{
|
||||
//die($cid);
|
||||
|
||||
// Replace with your view ID, for example XXXX.
|
||||
$VIEW_ID = "68484932";
|
||||
|
||||
// Create the DateRange object.
|
||||
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
|
||||
$dateRange->setStartDate("30daysAgo");
|
||||
$dateRange->setEndDate("today");
|
||||
|
||||
// Create the Metrics object.
|
||||
$pv = new Google_Service_AnalyticsReporting_Metric();
|
||||
$pv->setExpression("ga:pageviews");
|
||||
$pv->setAlias("pageviews");
|
||||
|
||||
//Create the dimensions
|
||||
$pageUrl = new Google_Service_AnalyticsReporting_Dimension();
|
||||
$pageUrl->setName("ga:pagePath");
|
||||
$cid = new Google_Service_AnalyticsReporting_Dimension();
|
||||
$cid->setName("ga:dimension1");
|
||||
$hitTime = new Google_Service_AnalyticsReporting_Dimension();
|
||||
$hitTime->setName("ga:dimension3");
|
||||
$ip = new Google_Service_AnalyticsReporting_Dimension();
|
||||
$ip->setName("ga:dimension3");
|
||||
|
||||
// Create Dimension Filter 1
|
||||
$cidFilter = new Google_Service_AnalyticsReporting_DimensionFilter();
|
||||
$cidFilter->setDimensionName("ga:dimension1");
|
||||
$cidFilter->setOperator('EXACT');
|
||||
$cidFilter->setExpressions($cid_no);
|
||||
|
||||
// Create the DimensionFilterClauses
|
||||
$dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
|
||||
$dimensionFilterClause->setFilters(array($cidFilter));
|
||||
|
||||
// OrderBy maybe some bugs
|
||||
$order = new Google_Service_AnalyticsReporting_OrderBy;
|
||||
$order->setFieldName("ga:dimension3");
|
||||
$order->setOrderType("VALUE");
|
||||
$order->setSortOrder("DESCENDING");
|
||||
|
||||
// Create the ReportRequest object.
|
||||
$request = new Google_Service_AnalyticsReporting_ReportRequest();
|
||||
$request->setViewId($VIEW_ID);
|
||||
$request->setDateRanges($dateRange);
|
||||
$request->setMetrics(array($pv));
|
||||
$request->setDimensions(array($pageUrl, $cid, $hitTime));
|
||||
$request->setDimensionFilterClauses(array($dimensionFilterClause));
|
||||
$request->setOrderBys(array($order));
|
||||
|
||||
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
|
||||
$body->setReportRequests(array($request));
|
||||
return $analytics->reports->batchGet($body);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses and prints the Analytics Reporting API V4 response.
|
||||
*
|
||||
* @param An Analytics Reporting API V4 response.
|
||||
*/
|
||||
function printResults($reports)
|
||||
{
|
||||
$alais_array = array(
|
||||
"ga:dimension1" => "cid",
|
||||
"ga:dimension3" => "hitTime",
|
||||
"ga:pagePath" => "path"
|
||||
);
|
||||
$rs_array = array();
|
||||
for ($reportIndex = 0; $reportIndex < count($reports); $reportIndex++) {
|
||||
$report = $reports[$reportIndex];
|
||||
$header = $report->getColumnHeader();
|
||||
$dimensionHeaders = $header->getDimensions();
|
||||
$metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries();
|
||||
$rows = $report->getData()->getRows();
|
||||
$rs_row = array();
|
||||
for ($rowIndex = 0; $rowIndex < count($rows); $rowIndex++) {
|
||||
$row = $rows[$rowIndex];
|
||||
$dimensions = $row->getDimensions();
|
||||
$metrics = $row->getMetrics();
|
||||
for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) {
|
||||
//print($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n");
|
||||
$rs_row[$alais_array[$dimensionHeaders[$i]]] = $dimensions[$i];
|
||||
}
|
||||
|
||||
for ($j = 0; $j < count($metrics); $j++) {
|
||||
$values = $metrics[$j]->getValues();
|
||||
for ($k = 0; $k < count($values); $k++) {
|
||||
$entry = $metricHeaders[$k];
|
||||
//print($entry->getName() . ": " . $values[$k] . "\n");
|
||||
$rs_row[$entry->getName()] = $values[$k];
|
||||
}
|
||||
}
|
||||
array_push($rs_array, $rs_row);
|
||||
}
|
||||
}
|
||||
echo(json_encode($rs_array));
|
||||
}
|
||||
|
||||
}
|
||||
//end of gaapi
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "sylvan-box-234910",
|
||||
"private_key_id": "357cb59e6bf066231fe9d421a1cada76b6af29ef",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDSNl/aj3hQf6bf\naPBHuGTLemiUl2OborE8MNvl5brhJMncTSslS1Q5CQRPk4K6nW1gAq2/gQ5KZ7Sd\nh9gdtWzIDoUS1DBDaZiPB8vVN6YOjIWpRSylIXTewQ6YYuw9kt7vW0orfDSsaWrE\nc2Yb5YN+6GTxVBjFEb19IYg5/8zfmvaUCOinDwO+F8mh6fCS9FyhiN5omKD+ixiQ\nYFIo1CM1SCpT3eH67JIF+hzuGAVWhF7YmdNTBdfrM0/1PBM8HRry0jD1VaDeyv+e\n4lTnPCtvUgc5SJOaLv/UR06X1FpIYikK0RHJ04fTslQxu7hTLqbhg/7d/+aj95K0\nAwaGERvdAgMBAAECggEAAOQZHFdoDVxwlSJEqeNyIDZh+GIfmnYQAUFhMKkOsPCc\nw9rtTxrNRxace0fd2sXtVkF8pp5dWTasmmIMPGNt+dLR7pP/z4Of2o9ZQcJR1vCp\nZc195rz/EL+AmGgLgZXg/5lxGhyDKhJ9vpORNt/FPiFALyOueJ/wslEnkZfwDANv\n0C+uIv2L3g0mrgTqXVwU/dVdYi9UK7hhn0YMgtlbdpxRHV0cIiilb23Cyy0QsFXN\n2MsoHPQWf+72nE+5jNnysXcR8AjAthzOvP/jIcqqBguid1w9F3goH4adLTa1aPIL\ndNGI/z9mwuqGQg5C78ZfmZMb3YIRwV4nmUia7kzrowKBgQDr2h14VyEGAypCjo+r\nXRvDti55PY+jKUnUzbseJca7Z1Z2snvGXWgkoasZc8ozsQjoH7wJJnRoJOGnAJdF\ntyZxtJV5W0pefB6Pfqy6k5MlJJhMy6lGpkQo96iPOBqfowHa1r/S55USHjQAMXG2\nKrX6oq1IWmEmFYMFZnQo7+SPqwKBgQDkK4rnCbirwHC0Z6eXkbk0Fb8KrS0huq3C\nupaoBtwkfkyISBzcXx6Bup/Gg7czSxvY6U/Bg93WtTzzJwVuqKSqcTUrwW4rAmrh\nZNEYjJc5YLKK1xXVOEeisMIsWCEpF8JHvyrCRsoBCOVRbQROFqz9IOSGrplw1Rq6\ntuPp2fsalwKBgQDgbfabG/X9vadKHFSUUY5pBwRkNHNpZJGwIXEMeBALJoN9gcwM\nb7f5G6owFyHzXGRIVmJdJq2gqG/dtc889NJtYtTV3UwAawW9sGH3TRS5RIB0m1xi\nMTcs8LYCSvXysG/EaZOxwtL0oa8D/AjjuvLeJEzWS8KkNdYunlas2dJZ7wKBgEAO\nlWV9jjHxyfJr81oTGDquLD80FSqV/ThhJ/CuVFmOd6//BtM7hRYIrdiOm/0zhfLk\ntXZvrfUcVqsw9k513BzZwYKyQFqkyBrVMfrBZac/JYDjF4cP0NS06R6H829U8z8v\nRTLbqtSVicPNZlsB9Ljv5hiFpiBOQ73NoLjDcMKrAoGAC+mrH9aOBeQuikQllpWJ\naZ7XoDdZcmh3j+o7OZWHAP3mpQ6q6/1iPW4lhG/q6l+syjsYRmQuzYICtSJ6xQlC\nM+AYPjD+O6sW3MWGz469cqrym8o+Bm24emxJNvilo/U/N2Yif2gUGWgw8qXLEGsu\nUedwiH6aWGBFnlVuPz6CZ6s=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "gaapi-904@sylvan-box-234910.iam.gserviceaccount.com",
|
||||
"client_id": "112785767675412711830",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gaapi-904%40sylvan-box-234910.iam.gserviceaccount.com"
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
|
||||
define("JUHE_API_KEY","123");
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,585 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
//帐号密钥
|
||||
define("ORDERUSER","guilintravel");
|
||||
define("ORDERKEY","07f811fe29f04008a8fcc86e81c012b9");
|
||||
|
||||
//数据返回格式地址
|
||||
define("JSONRETURN","http://m.ctrip.com/restapi/soa2/12976/json/");
|
||||
define("XMLRETURN","http://m.ctrip.com/restapi/soa2/12976/xml/");
|
||||
|
||||
class ctrip_train extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->helper("train");//加载模型
|
||||
$this->load->model("ctrip_train_model");//加载模型
|
||||
}
|
||||
|
||||
public function addorders(){
|
||||
//接收参数
|
||||
$cold_sn = $this->input->get("order");
|
||||
$bpe_sn = $this->input->get("people");
|
||||
$SelectSeat = $this->input->get("selectseat");
|
||||
$data = array();
|
||||
$rebakc = array();//返回数据
|
||||
$rebakc["status"] = 0;
|
||||
$rebakc["mes"] = "";
|
||||
|
||||
|
||||
if(!is_numeric($cold_sn)){
|
||||
$rebakc["mes"] = "订单号是数字";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
if(empty($bpe_sn)){
|
||||
$rebakc["mes"] = "请选择乘客";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['train'] = $this->ctrip_train_model->biz_order_detail($cold_sn);
|
||||
$data['people_list'] = $this->ctrip_train_model->in_bpesn_people_info($bpe_sn);
|
||||
|
||||
/*print_r($data['train']);
|
||||
print_r($data['people_list']);*/
|
||||
|
||||
//生成订单号
|
||||
$OrderNumber = ORDERUSER.time();
|
||||
|
||||
if (empty($data['train'])) {
|
||||
//显示错误,找不到车次
|
||||
$rebakc["mes"] = "找不到车次";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
|
||||
}
|
||||
if (empty($data['people_list'])) {
|
||||
//显示错误,找不到用户信息
|
||||
$rebakc["mes"] = "找不到乘客信息";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($data['people_list']) > 5) {
|
||||
//显示错误,用户超过五个
|
||||
$rebakc["mes"] = "乘客不能超过五个";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
$db_train_zw = $this->config->item('db_train_zw');
|
||||
$train_zw = $this->config->item('train_zw');
|
||||
$zwcode = $db_train_zw[$data['train']->Aircraft]; //座位简码
|
||||
$zwname = $train_zw[$db_train_zw[$data['train']->Aircraft]]; //座位名称
|
||||
$black_list = $this->config->item('black_list');
|
||||
|
||||
//拼接发送的报文
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.PartnerAddOrder';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.PartnerAddOrder'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->PartnerName = ORDERUSER;
|
||||
$PostData['TrainOrderService']->Operation = '';
|
||||
$PostData['TrainOrderService']->OrderType = '电子';
|
||||
$PostData['TrainOrderService']->OrderTicketType = '0';
|
||||
$PostData['TrainOrderService']->OrderNumber = $OrderNumber;
|
||||
$PostData['TrainOrderService']->ChannelName = ORDERUSER;
|
||||
|
||||
$PostData['TrainOrderService']->Order->OrderTime = $time;
|
||||
$PostData['TrainOrderService']->Order->OrderMedia = 'pc';
|
||||
$PostData['TrainOrderService']->Order->Insurance = 'N';
|
||||
$PostData['TrainOrderService']->Order->Invoice = 'N';
|
||||
$PostData['TrainOrderService']->Order->PrivateCustomization = '0';
|
||||
|
||||
$PostData['TrainOrderService']->Order->TicketItem->FromStationName = $data['train']->DepartAirport_cn;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->ToStationName = $data['train']->ArrivalAirport_cn;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->TicketTime = date('Y-m-d H:i:s',strtotime($data['train']->DepartureTime));
|
||||
$PostData['TrainOrderService']->Order->TicketItem->TrainNumber = $data['train']->FlightsNo;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->ArrivalDateTime = date('Y-m-d H:i:s',strtotime($data['train']->ArrivalTime));
|
||||
$PostData['TrainOrderService']->Order->TicketItem->TicketPrice = $data['train']->adultcost;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->TicketCount = count($data['people_list']);
|
||||
|
||||
$AdultNum = 0;
|
||||
$ChildNum = 0;
|
||||
$Passport = '';
|
||||
foreach ($data['people_list'] as $PassagerInfo){
|
||||
//乘客类型
|
||||
switch ($PassagerInfo->BPE_GuestType) {
|
||||
case 1:
|
||||
$PiaoType = 1;
|
||||
$PiaoTypeName = "成人票";
|
||||
$AdultNum++;
|
||||
break;
|
||||
case 2:
|
||||
$PiaoType = 2;
|
||||
$PiaoTypeName = "儿童票";
|
||||
$ChildNum++;
|
||||
break;
|
||||
default://外国人应该就两种票吧
|
||||
$PiaoType = 1;
|
||||
$PiaoTypeName = "成人票";
|
||||
break;
|
||||
}
|
||||
|
||||
//证件类型
|
||||
switch ($PassagerInfo->BPE_PassportType){
|
||||
case 'Chinese ID':
|
||||
$PassportTypeseId = "1";
|
||||
$PassportTypeseidName = "二代身份证";
|
||||
break;
|
||||
case 'Travel Permit from Hong Kong / Macau':
|
||||
$PassportTypeseidName = "港澳通行证";
|
||||
break;
|
||||
case 'Travel Permit from Taiwan':
|
||||
$PassportTypeseId = "G";
|
||||
$PassportTypeseidName = "台湾通行证";
|
||||
break;
|
||||
default :
|
||||
$PassportTypeseId = "B";
|
||||
$PassportTypeseidName = "护照";
|
||||
break;
|
||||
}
|
||||
//$Passport .= chk_sp_name($PassagerInfo->BPE_FirstName.$PassagerInfo->BPE_MiddleName.$PassagerInfo->BPE_LastName).','.$PassportTypeseidName.','.$PassagerInfo->BPE_Passport.','.$PiaoTypeName.','.''.',0|';
|
||||
|
||||
if($PiaoType == 1){
|
||||
$RelatioNme = chk_sp_name($PassagerInfo->BPE_FirstName.$PassagerInfo->BPE_MiddleName.$PassagerInfo->BPE_LastName);
|
||||
$Passport .= chk_sp_name($PassagerInfo->BPE_FirstName.$PassagerInfo->BPE_MiddleName.$PassagerInfo->BPE_LastName).','.$PassportTypeseidName.','.$PassagerInfo->BPE_Passport.','.$PiaoTypeName.','.''.',0|';
|
||||
}elseif($PiaoType == 2){
|
||||
$Passport .= $RelatioNme.','.$PassportTypeseidName.','.$PassagerInfo->BPE_Passport.','.$PiaoTypeName.','.''.',0,'.chk_sp_name($PassagerInfo->BPE_FirstName.$PassagerInfo->BPE_MiddleName.$PassagerInfo->BPE_LastName).'|';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$PostData['TrainOrderService']->Order->TicketItem->AuditTicketCount = $AdultNum;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->ChildTicketCount = $ChildNum;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->SeatName = $train_zw[$db_train_zw[$data['train']->Aircraft]];
|
||||
$PostData['TrainOrderService']->Order->TicketItem->SelectedSeat = $SelectSeat;
|
||||
$PostData['TrainOrderService']->Order->TicketItem->AcceptSeat = '';
|
||||
$PostData['TrainOrderService']->Order->TicketItem->passport = substr($Passport,0,strlen($Passport)-1);
|
||||
$PostData['TrainOrderService']->Order->TicketItem->OrderPrice = $data['train']->adultcost * $AdultNum + $data['train']->childcost * $ChildNum;
|
||||
|
||||
$PostData['TrainOrderService']->Order->FrontSeatFlag = '0';
|
||||
|
||||
$PostData['TrainOrderService']->Order->User->UserID = '';
|
||||
$PostData['TrainOrderService']->Order->User->UserName = 'guilintravel';
|
||||
$PostData['TrainOrderService']->Order->User->userLoginName = 'guilintravel';
|
||||
$PostData['TrainOrderService']->Order->User->UserMobile = '18877381547';
|
||||
//print_r($PostData);die();
|
||||
//本地添加记录
|
||||
$add_data = new stdClass();
|
||||
$add_data->cold_sn = $cold_sn;
|
||||
$add_data->ordernumber = $OrderNumber;
|
||||
$add_data->returncode = '';
|
||||
$add_data->status = '2';
|
||||
$add_data->errormsg = '预定中';
|
||||
$add_data->checi = $data['train']->FlightsNo;
|
||||
$add_data->fromstationame = $data['train']->DepartAirport_cn;
|
||||
$add_data->fromstationcode = $data['train']->DepartAirport;
|
||||
$add_data->tostationame = $data['train']->ArrivalAirport_cn;
|
||||
$add_data->tostationcode = $data['train']->ArrivalAirport;
|
||||
$add_data->startdate = date('Y-m-d',strtotime($data['train']->DepartureDate));
|
||||
$add_data->startime = date('H:i',strtotime($data['train']->DepartureTime));
|
||||
$add_data->endtime = date('H:i',strtotime($data['train']->ArrivalTime));
|
||||
$add_data->runtime = (strtotime($data['train']->ArrivalTime) - strtotime($data['train']->DepartureTime)) / 60;
|
||||
$add_data->channel = 'ctrip';
|
||||
$add_data->isauto = 0;
|
||||
|
||||
|
||||
//存储到数据库
|
||||
$this->ctrip_train_model->add_orders($add_data);
|
||||
|
||||
$Url = 'http://m.ctrip.com/restapi/soa2/11009/json/PartnerAddOrder';
|
||||
$ResponseJson = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
//echo '预定';
|
||||
//print_r($ResponseData);
|
||||
|
||||
//预定请求成功后执行支付
|
||||
if($ResponseData->Status == 'SUCCESS'){
|
||||
//计算订单总价,进行支付
|
||||
$total_price = $AdultNum * $data['train']->adultcost + $ChildNum * $data['train']->childcost;
|
||||
$this->payorders($OrderNumber,$total_price);
|
||||
$rebakc["status"] = 1;
|
||||
$rebakc["order"] = $OrderNumber;
|
||||
$rebakc["mes"] = "订单提交成功,等待回调";
|
||||
echo json_encode($rebakc);
|
||||
}
|
||||
}
|
||||
|
||||
//取消订单
|
||||
public function cancelorders(){
|
||||
$CtripOrder = $this->input->post('CtripOrder');
|
||||
|
||||
$CtripOrder = '488110485_1543999756';
|
||||
|
||||
//生成报文
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.PartnerPayOrder';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.PartnerPayOrder'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->PartnerName = ORDERUSER;
|
||||
$PostData['TrainOrderService']->OrderNumber = $CtripOrder;
|
||||
$PostData['TrainOrderService']->CancelTime = date('Y-m-d H:s:i',time());
|
||||
|
||||
$Url = 'http://ws-ordercenter-train.fat.ctripqa.com/orderCore/api/json/PartnerCancelOrder';
|
||||
|
||||
$ResponseData = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
|
||||
print_r($ResponseData);
|
||||
}
|
||||
|
||||
//请求支付
|
||||
public function payorders($CtripOrder,$Price){
|
||||
if(empty($CtripOrder) && !is_numeric($Price)){
|
||||
exit('传参错误!');
|
||||
}
|
||||
|
||||
//生成报文
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.PartnerPayOrder';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.PartnerPayOrder'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->PartnerName = ORDERUSER;
|
||||
$PostData['TrainOrderService']->OrderNumber = $CtripOrder;
|
||||
$PostData['TrainOrderService']->PayedPrice = $Price;
|
||||
//$PostData['TrainOrderService']->PayType = $time;
|
||||
//$PostData['TrainOrderService']->TradeNumber = $time;
|
||||
|
||||
$Url = 'http://m.ctrip.com/restapi/soa2/11009/json/PartnerPayOrder';
|
||||
|
||||
$ResponseJson = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
//echo '支付';
|
||||
//print_r($ResponseData);
|
||||
//支付同步回调信息 {"Status":"SUCCESS","PartnerName":"guilintravel","OrderNumber":"guilintravel1546071576","OperationDateTime":"2018-12-29 16:19:37","RetCode":0,"ResponseStatus":{"Timestamp":"\/Date(1546071577236+0800)\/","Ack":"Success","Errors":[],"Extension":[]}}
|
||||
}
|
||||
|
||||
//退票接口
|
||||
public function returnticket(){
|
||||
//接收数据
|
||||
$CtripOrder = $this->input->get_post('CtripOrder');
|
||||
$PassagerId = $this->input->get_post('PassagerId');
|
||||
|
||||
//根据获取到的订单号获取信息
|
||||
if(empty($CtripOrder)){
|
||||
exit('订单号为空');
|
||||
}
|
||||
|
||||
$ReturnObj = $this->ctrip_train_model->get_passager_info($CtripOrder,$PassagerId);
|
||||
if(empty($ReturnObj)){
|
||||
exit('订单详情为空');
|
||||
}
|
||||
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.ticketReturn';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.ticketReturn'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->contactName = '陈宇超';
|
||||
$PostData['TrainOrderService']->contactMobile = '18877381547';
|
||||
$PostData['TrainOrderService']->OrderNumber = $CtripOrder;
|
||||
$PostData['TrainOrderService']->OperatorType = '0';
|
||||
$PostData['TrainOrderService']->TicketInfo = '';
|
||||
$PostData['TrainOrderService']->TicketInfo = array();
|
||||
|
||||
$i = 0;
|
||||
foreach($ReturnObj as $items){
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderNumber'] = $items->ts_elecnumber;
|
||||
if($items->tst_ticketype == '儿童票'){
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderType'] = '2';
|
||||
}else{
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderType'] = '1';
|
||||
}
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['seatNumber'] = $items->tst_seatdetail;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['passportName'] = $items->tst_realname;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['passport'] = $items->tst_numberid;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['realName'] = $items->tst_realname;
|
||||
$i++;
|
||||
}
|
||||
|
||||
|
||||
//发起退票请求
|
||||
$Url = 'http://m.ctrip.com/restapi/soa2/11009/json/PartnerReturnTicket';
|
||||
$ResponseJson = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
//请求结束后,将乘客状态更改为出票状态
|
||||
/*$ResponseData = new stdClass();
|
||||
$ResponseData->Status = '';
|
||||
$ResponseData->Status = 'SUCCESS';*/
|
||||
|
||||
if($ResponseData->Status == 'SUCCESS'){
|
||||
echo "<script>alert('请求成功,正在处理退票...');location.href='".site_url("/apps/trainsystem/pages/refund?order=$CtripOrder")."';</script>";
|
||||
}
|
||||
//print_r($ResponseJson);
|
||||
}
|
||||
|
||||
//火车票改签
|
||||
public function rescheduleticket(){
|
||||
//订单号
|
||||
$CtripOrder = $this->input->get_post('CtripOrder');
|
||||
//改签车次
|
||||
$RescheduleTrainNumber = $this->input->get_post('RescheduleTrainNumber');
|
||||
//改签出发站
|
||||
$DepartStationName = $this->input->get_post('DepartStationName');
|
||||
//改签到达站
|
||||
$ArriveStationName = $this->input->get_post('ArriveStationName');
|
||||
//改签车次票价
|
||||
$RescheduleTicketPrice = $this->input->get_post('RescheduleTicketPrice');
|
||||
//改签坐席
|
||||
$RescheduleSeatName = $this->input->get_post('RescheduleSeatName');
|
||||
//改签出发时间
|
||||
$RescheduleDepartTime = $this->input->get_post('RescheduleDepartTime');
|
||||
//改签到达时间
|
||||
$RescheduleArriveTime = $this->input->get_post('RescheduleArriveTime');
|
||||
|
||||
//赋值测试
|
||||
$CtripOrder = '488111988_1544754322';
|
||||
$RescheduleTrainNumber = 'D8205';
|
||||
$DepartStationName = '桂林';
|
||||
$ArriveStationName = '南宁东';
|
||||
$RescheduleTicketPrice = '128.5';
|
||||
$RescheduleSeatName = '二等座';
|
||||
$RescheduleDepartTime = '2019/01/01 10:38';
|
||||
$RescheduleArriveTime = '2019/01/01 13:03';
|
||||
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.partnerreschedule';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.partnerreschedule'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->OrderNumber = $CtripOrder;
|
||||
$PostData['TrainOrderService']->Operator = '陈宇超';
|
||||
$PostData['TrainOrderService']->RescheduleTrainNumber = $RescheduleTrainNumber;
|
||||
$PostData['TrainOrderService']->DepartStationName = $DepartStationName;
|
||||
$PostData['TrainOrderService']->ArriveStationName = $ArriveStationName;
|
||||
$PostData['TrainOrderService']->RescheduleDepartTime = $ArriveStationName;
|
||||
$PostData['TrainOrderService']->RescheduleArriveTime = $ArriveStationName;
|
||||
$PostData['TrainOrderService']->RescheduleTicketPrice = $RescheduleTicketPrice;
|
||||
$PostData['TrainOrderService']->RescheduleSeatName = $RescheduleSeatName;
|
||||
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos = array();
|
||||
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['eOrderNumber'] = 'E1317265149';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['eOrderType'] = '1';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['realName'] = 'LISI';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['CarriageNo'] = '12';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['seatNumber'] = '877号';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['passportName'] = 'LISI';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['0']['passport'] = '123456789';
|
||||
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['eOrderNumber'] = 'E1317265149';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['eOrderType'] = '1';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['realName'] = 'WANGWU';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['CarriageNo'] = '13';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['seatNumber'] = '878号';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['passportName'] = 'WANGWU';
|
||||
$PostData['TrainOrderService']->RescheduleTicketPassengerInfos['1']['passport'] = '123456789';
|
||||
|
||||
//print_r(json_encode($PostData));die();
|
||||
$Url = 'http://ws-ordercenter-train.fat.ctripqa.com/orderCore/api/json/PartnerReschedule';
|
||||
$ResponseData = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
print_r($ResponseData);
|
||||
}
|
||||
|
||||
//回调函数
|
||||
public function ctrip_callback(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
log_message('error','携程回调信息:'.$back_json);
|
||||
/*$back_json = '{"Authentication":{"ServiceName":"web.order.returnTicketNotice","PartnerName":"tieyou","TimeStamp":"2019-1-18 11:35:22","MessageIdentity":"93F2BA3253829E8FAD29B5DEB7646A59"},"TrainOrderService":{"contactName":{},"contactMobile":{},"OrderNumber":"guilintravel1547778269","refundTicket":{"childBillId":{},"orderId":"8360041214","eOrderNumber":"EB59937931","eOrderType":"1","seatNumber":"01D\u53f7","passport":"544712454","passportName":"YANGFRANCISCHENG","realName":"YANGFRANCISCHENG","status":"1","reason":"\u9000\u7968\u6210\u529f\uff0c\u9000\u6b3e\u91d1\u989d:218.50\u5143"}}}';*/
|
||||
$ctrip_backdata = json_decode($back_json);
|
||||
//print_r($ctrip_backdata);
|
||||
if(!empty($ctrip_backdata)){
|
||||
$update_data = new stdClass();
|
||||
$update_data->ServiceName = $ctrip_backdata->Authentication->ServiceName;
|
||||
$update_data->ordernumber = '';
|
||||
$update_data->seatsinfo = '';
|
||||
$update_data->TicketCheck = '';
|
||||
$update_data->bookcallback = '';
|
||||
$update_data->confirmcallback = '';
|
||||
$update_data->returncallback = '';
|
||||
$update_data->OrderTotleFee = 0;
|
||||
$update_data->ElectronicOrderNumber = '';
|
||||
$update_data->reschedulecallback = '';
|
||||
|
||||
if($update_data->ServiceName == 'web.order.notifyTicket'){
|
||||
$update_data->OrderStatus = '4';
|
||||
$update_data->ErrorMsg = '出票成功';
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$update_data->OrderTotleFee = $ctrip_backdata->TrainOrderService->OrderInfo->OrderTotleFee;
|
||||
$update_data->ElectronicOrderNumber = $ctrip_backdata->TrainOrderService->OrderInfo->ElectronicOrderNumber;
|
||||
|
||||
//新添加检票口信息
|
||||
if(isset($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck)){
|
||||
if(!is_object($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck)){
|
||||
$update_data->TicketCheck = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck;
|
||||
}
|
||||
}
|
||||
|
||||
//获取总票数,由于携程接口单人和多人返回的数据结构不一致
|
||||
$person_num = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketCount;
|
||||
|
||||
//存储座位信息 转换为英文
|
||||
$coach_arr = array();
|
||||
$seats_arr = array();
|
||||
$data_passager = new stdClass();
|
||||
$string = '';
|
||||
$i = 0;
|
||||
if($person_num > 1){
|
||||
foreach ($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo as $items){
|
||||
if(strpos($items->SeatNo,'车厢')){
|
||||
$coach = mb_substr($items->SeatNo,0,strpos($items->SeatNo,'车厢'));
|
||||
array_push($coach_arr,$coach);
|
||||
$seat = mb_substr($items->SeatNo,strpos($items->SeatNo,'车厢')+2,mb_strlen($items->SeatNo,'UTF8'));
|
||||
$find = array('号');
|
||||
$replace = array('');
|
||||
$seat = str_replace($find,$replace,$seat);
|
||||
array_push($seats_arr,$seat);
|
||||
}
|
||||
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$data_passager->realname = $items->PassengerName;
|
||||
$data_passager->identitytype = $items->IdentityType;
|
||||
$data_passager->numberid = $items->NumberID;
|
||||
$data_passager->ticketype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketType;
|
||||
$data_passager->ticketprice = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketPrice;
|
||||
$data_passager->seatype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketSeat;
|
||||
$data_passager->seatdetail = $items->SeatNo;
|
||||
$this->ctrip_train_model->add_passagers($data_passager);
|
||||
$i++;
|
||||
}
|
||||
|
||||
}else{
|
||||
$seatinfo_html = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->SeatNo;
|
||||
if(strpos($seatinfo_html,'车厢')){
|
||||
$coach = mb_substr($seatinfo_html,0,strpos($seatinfo_html,'车厢'));
|
||||
array_push($coach_arr,$coach);
|
||||
$seat = mb_substr($seatinfo_html,strpos($seatinfo_html,'车厢')+2,mb_strlen($seatinfo_html,'UTF8'));
|
||||
$find = array('号');
|
||||
$replace = array('');
|
||||
$seat = str_replace($find,$replace,$seat);
|
||||
array_push($seats_arr,$seat);
|
||||
}
|
||||
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$data_passager->realname = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->PassengerName;
|
||||
$data_passager->identitytype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->IdentityType;
|
||||
$data_passager->numberid = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->NumberID;
|
||||
$data_passager->ticketype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketType;
|
||||
$data_passager->ticketprice = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketPrice;
|
||||
$data_passager->seatype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketSeat;
|
||||
$data_passager->seatdetail = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->SeatNo;
|
||||
$this->ctrip_train_model->add_passagers($data_passager);
|
||||
}
|
||||
|
||||
if(count(array_unique($coach_arr)) == 1){
|
||||
$onlycoach = array_unique($coach_arr);
|
||||
$update_data->seatsinfo .= 'Coach '.$onlycoach[0].',';
|
||||
}else{
|
||||
foreach (array_unique($coach_arr) as $item_coach){
|
||||
$update_data->seatsinfo .= 'Coach '.$item_coach.',';
|
||||
}
|
||||
}
|
||||
|
||||
$update_data->seatsinfo .= 'Seat ';
|
||||
foreach($seats_arr as $item_seat){
|
||||
$update_data->seatsinfo .= $item_seat.',';
|
||||
}
|
||||
|
||||
$update_data->seatsinfo = substr($update_data->seatsinfo,0,strlen($update_data->seatsinfo)-1);
|
||||
|
||||
$update_data->bookcallback = $back_json;
|
||||
|
||||
//添加支付记录
|
||||
$add_train_payment_data->TOC_Memo = $update_data->ordernumber;
|
||||
//根据订单号获取cold_sn
|
||||
$order_info = $this->ctrip_train_model->get_order_info($update_data->ordernumber);
|
||||
$cold_sn = $order_info->ts_cold_sn;
|
||||
$add_train_payment_data->TOC_COLD_SN = $cold_sn;
|
||||
$add_train_payment_data->TOC_TrainNumber = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfo->OrderTicketCheci;
|
||||
$add_train_payment_data->TOC_DepartureDate = date('Y-m-d',strtotime($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfo->OrderTicketYMD));
|
||||
$add_train_payment_data->TOC_TicketCost = $update_data->OrderTotleFee;
|
||||
$add_train_payment_data->poundage = ($person_num*5)."";//手续费,每人五块,转换成字符串
|
||||
$add_train_payment_data->FOI_TrainNetOrderNo = $update_data->ElectronicOrderNumber;
|
||||
//print_r($add_train_order_data);die();
|
||||
$this->ctrip_train_model->add_train_payment($add_train_payment_data);
|
||||
//记录供应商(瀚特)
|
||||
$this->ctrip_train_model->update_cold_planvei_sn($cold_sn);
|
||||
}else if($update_data->ServiceName == 'web.order.notifyNoTicket'){
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$update_data->OrderStatus = '1';
|
||||
$update_data->ErrorMsg = $ctrip_backdata->TrainOrderService->OrderInfo->NoTicketReasons;
|
||||
$update_data->confirmcallback = $back_json;
|
||||
}else if($update_data->ServiceName == 'web.order.returnTicketNotice'){
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
|
||||
$update_data->OrderStatus = '7';
|
||||
$update_data->ErrorMsg = $ctrip_backdata->TrainOrderService->refundTicket->reason;
|
||||
$update_data->returncallback = $back_json;
|
||||
|
||||
//退票时还需要单独对对每个乘客存储回调信息
|
||||
$passpager_info = new stdClass();
|
||||
$passpager_info->returncallback = $back_json;
|
||||
$passpager_info->status = '7';
|
||||
$passpager_info->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
|
||||
$passpager_info->realname = $ctrip_backdata->TrainOrderService->refundTicket->realName;
|
||||
$passpager_info->numberid = $ctrip_backdata->TrainOrderService->refundTicket->passport;
|
||||
$this->ctrip_train_model->update_passpager_info($passpager_info);
|
||||
}else if($update_data->ServiceName == 'web.order.requestRefund'){
|
||||
$return_order = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$return_money = $ctrip_backdata->TrainOrderService->TotalRefundAmount;
|
||||
|
||||
//根据订单号获取cold_sn
|
||||
$order_info = $this->ctrip_train_model->get_order_info($return_order);
|
||||
$cold_sn = $order_info->ts_cold_sn;
|
||||
//print_r($order_info);
|
||||
|
||||
$add_train_payment_data->TOC_Memo = $return_order.'_'.$ctrip_backdata->TrainOrderService->OrderInfo->OrderTid;
|
||||
$add_train_payment_data->TOC_COLD_SN = $cold_sn;
|
||||
$add_train_payment_data->TOC_TrainNumber = $order_info->ts_checi;
|
||||
$add_train_payment_data->TOC_DepartureDate = $order_info->ts_startdate;
|
||||
$add_train_payment_data->TOC_TicketCost = -$ctrip_backdata->TrainOrderService->TotalRefundAmount;
|
||||
$add_train_payment_data->FOI_TrainNetOrderNo=null;
|
||||
//print_r($add_train_payment_data);die();
|
||||
$this->ctrip_train_model->add_train_payment($add_train_payment_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
//更新订单信息(出票系统)
|
||||
$this->ctrip_train_model->update_orders($update_data);
|
||||
}
|
||||
//print_r($update_data);
|
||||
//print_r(json_decode($back_xml));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,366 @@
|
||||
<?php
|
||||
/**
|
||||
junjun.php
|
||||
用于测试自动出票中出现的问题。
|
||||
查询coli_sn来测试。
|
||||
*/
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class junjun extends CI_Controller{
|
||||
|
||||
public function __construct() {
|
||||
header("Content-Type: text/html;charset=utf-8");
|
||||
parent::__construct();
|
||||
$this->config->load('config');
|
||||
$this->order_status_msg=$this->config->item('train_order_status_msg');
|
||||
$this->key=JUHE_TRAIN_API_KEY;
|
||||
$this->cx_api=JUHE_TRAIN_CX_API;
|
||||
$this->dp_api=JUHE_TRAIN_DP_API;
|
||||
$this->qxdd_api=JUHE_TRAIN_CANCEL_API;
|
||||
$this->pay_api=JUHE_TRAIN_PAY_API;
|
||||
$this->refund_api=JUHE_TRAIN_REFUND_API;
|
||||
$this->status_api=JUHE_TRAIN_STATUS_API;
|
||||
$this->code_zw=$this->config->item('train_zw');
|
||||
$this->piaotype=$this->config->item('train_piaotype');
|
||||
$this->passportty=$this->config->item('train_passportty');
|
||||
$this->balance_api = "http://op.juhe.cn/trainTickets/balance.php";//余额
|
||||
$this->load->model("BIZ_train_model");//加载模型
|
||||
}
|
||||
|
||||
public function test(){
|
||||
$arr = array('','');
|
||||
print_r($arr);
|
||||
echo count($arr);
|
||||
if(!empty($arr)){
|
||||
echo '123';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function index(){
|
||||
$this->ticketype = 1;
|
||||
//筛选出能自动出票的订单
|
||||
$auto_pool = $this->BIZ_train_model->auto_check_ticket();
|
||||
//print_r($auto_pool);
|
||||
$auto_pool = array('0'=>(object)array('COLD_SN'=>'488096935','coli_id'=>'180824444','COLI_State'=>'13'));
|
||||
//print_r($auto_pool);
|
||||
//创建一个不允许自动出票的国际火车票数组
|
||||
$nation_train = array('K19', 'K23', 'Z8701', 'Z8702', 'Z97', 'Z98', 'Z99', 'Z100', 'K9795');
|
||||
|
||||
//创建黑名单
|
||||
$black_list = $this->config->item('black_list');
|
||||
$string = '';
|
||||
foreach($auto_pool as $item){
|
||||
$this->ticketype = 1;
|
||||
$back_message = '';
|
||||
$cold_sn = $item->COLD_SN;
|
||||
$coli_id = $item->coli_id;
|
||||
$back_data = 1;
|
||||
|
||||
$people_arr = $this->BIZ_train_model->biz_people($cold_sn);
|
||||
$train_info = $this->BIZ_train_model->get_biz_foi($cold_sn);
|
||||
/*
|
||||
if($item->COLD_SPFS > 1){
|
||||
//寄送票
|
||||
$back_data = 0;
|
||||
$back_message .= '-邮寄不自动出票';
|
||||
}
|
||||
*/
|
||||
//乘客人数大于5人不出票
|
||||
if(count($people_arr) > 5){
|
||||
$back_data = 0;
|
||||
$back_message .= '-乘客人数大于5不自动出票';
|
||||
}
|
||||
|
||||
//护照号如果在黑名单的就不自动出票
|
||||
foreach($people_arr as $people_info){
|
||||
if(in_array($people_info->BPE_Passport,$black_list)){
|
||||
$back_data = 0;
|
||||
$back_message .= '-此用户为黑名单用户,不自动出票';
|
||||
}
|
||||
|
||||
if(strlen($people_info->BPE_Passport) >= 18){
|
||||
$back_data = 0;
|
||||
$back_message .= '-护照位数大于18不自动出票';
|
||||
}
|
||||
}
|
||||
|
||||
//单张票价不能大于1000人民币
|
||||
if($train_info[0]->adultcost > 1000){
|
||||
$back_data = 0;
|
||||
$back_message .= '-单价大于1000不自动出票';
|
||||
}
|
||||
|
||||
//如果为国际火车票就不出票
|
||||
if(in_array($train_info[0]->FlightsNo, $nation_train)){
|
||||
$back_data = 0;
|
||||
$back_message .= '-国际火车票不自动出票';
|
||||
}
|
||||
|
||||
//无座的订单不做出票
|
||||
if($train_info[0]->Aircraft == 'WZ'){
|
||||
$back_data = 0;
|
||||
$back_message .= '-无座不自动出票';
|
||||
}
|
||||
|
||||
//香港火车不自动出票
|
||||
if($train_info[0]->ArrivalAirport == 'XJA' || $train_info[0]->DepartAirport == 'XJA'){
|
||||
$back_data = 0;
|
||||
$back_message .= '-香港火车不自动出票';
|
||||
}
|
||||
//print_r($train_info);
|
||||
|
||||
//如果刚好是第三十天的订单
|
||||
if(($item->COLI_State == '8' || $item->COLI_State == '63')){
|
||||
$this->ticketype = 3;
|
||||
$time_obj = $this->BIZ_train_model->get_saletime($train_info['0']->DepartAirport_cn);
|
||||
if(!empty($time_obj)){
|
||||
$saletime = strtotime($time_obj->TST_saletime);
|
||||
$now_time = time();
|
||||
$sale_diff = (time() - $saletime) / 3600;
|
||||
if($sale_diff > 1){
|
||||
$back_data = 0;
|
||||
$back_message .= '-超过抢票时间';
|
||||
}else if($sale_diff <0){
|
||||
$back_data = 0;
|
||||
$back_message .= '-未到抢票时间';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($back_data == 0){
|
||||
$string .= '<tr><td>汉特订单号:'.$coli_id.'('.$cold_sn.')'.$back_message.'</td></tr>';
|
||||
}else{
|
||||
//单个订单提交
|
||||
//$this->submit_juhe_order($cold_sn,$coli_id);
|
||||
$string .= '<tr><td>汉特订单号:'.$coli_id.'('.$cold_sn.')可以自动出票</td></tr>';
|
||||
}
|
||||
}
|
||||
print_r('<table border="1">'.$string.'</table>');
|
||||
}
|
||||
|
||||
|
||||
public function submit_juhe_order($cold_sn,$coli_id) {
|
||||
$this->load->model("BIZ_train_model");
|
||||
$cold_sn='488079918';//488084043
|
||||
//$cold_sn=$this->input->get("order");
|
||||
//$bpe_sn=$this->input->get("people");
|
||||
//$selectseat=$this->input->get("selectseat");
|
||||
//$bpe_sn = '(473118360);
|
||||
$data = array();
|
||||
$rebakc=array();//返回数据
|
||||
$rebakc["status"]=0;
|
||||
$rebakc["mes"]="";
|
||||
if(!is_numeric($cold_sn)){
|
||||
$rebakc["mes"]="订单号是数字";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
if(empty($bpe_sn)){
|
||||
$rebakc["mes"]="请选择乘客";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
$data['train'] = $this->BIZ_train_model->biz_order_detail($cold_sn);
|
||||
$data['people_list']=$this->BIZ_train_model->in_bpesn_people_info($bpe_sn);
|
||||
if (empty($data['train'])) {
|
||||
//显示错误,找不到车次
|
||||
$rebakc["mes"]="找不到车次";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
|
||||
}
|
||||
if (empty($data['people_list'])) {
|
||||
//显示错误,找不到用户信息
|
||||
$rebakc["mes"]="找不到乘客信息";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (count($data['people_list']) > 5) {
|
||||
//显示错误,用户超过五个
|
||||
$rebakc["mes"]="乘客不能超过五个";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
$db_train_zw = $this->config->item('db_train_zw');
|
||||
$train_zw = $this->config->item('train_zw');
|
||||
$zwcode = $db_train_zw[$data['train']->Aircraft]; //座位简码
|
||||
$zwname = $train_zw[$db_train_zw[$data['train']->Aircraft]]; //座位名称
|
||||
$black_list = $this->config->item('black_list');
|
||||
|
||||
$passengers="";
|
||||
foreach ($data['people_list'] as $key => $item) {
|
||||
|
||||
//乘客姓名
|
||||
$passengersename = $item->BPE_FirstName.$item->BPE_MiddleName.$item->BPE_LastName;
|
||||
//将特殊字符转换为正常字符以便于出票
|
||||
$passengersename = $this->chk_sp_name($passengersename);
|
||||
//乘客类型
|
||||
switch ($item->BPE_GuestType) {
|
||||
case 1:
|
||||
$piaotype = 1;
|
||||
$piaotypename = "成人票";
|
||||
break;
|
||||
case 2:
|
||||
$piaotype = 2;
|
||||
$piaotypename = "儿童票";
|
||||
break;
|
||||
default://外国人应该就两种票吧
|
||||
$piaotype = 1;
|
||||
$piaotypename = "成人票";
|
||||
break;
|
||||
}
|
||||
|
||||
switch ($item->BPE_PassportType){
|
||||
case 'Chinese ID':
|
||||
$passporttypeseid = "1";
|
||||
$passporttypeseidname = "二代身份证";
|
||||
break;
|
||||
case 'Travel Permit from Hong Kong / Macau':
|
||||
$passporttypeseid = "C";
|
||||
$passporttypeseidname = "港澳通行证";
|
||||
break;
|
||||
case 'Travel Permit from Taiwan':
|
||||
$passporttypeseid = "G";
|
||||
$passporttypeseidname = "台湾通行证";
|
||||
break;
|
||||
default :
|
||||
$passporttypeseid = "B";
|
||||
$passporttypeseidname = "护照";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$passportseno = str_replace(' ','',$item->BPE_Passport);
|
||||
|
||||
//添加一个判断护照号是否在黑名单
|
||||
if(in_array($passportseno,$black_list)){
|
||||
$rebakc["mes"]="乘客为黑名单用户";
|
||||
echo json_encode($rebakc);
|
||||
return false;
|
||||
}
|
||||
|
||||
$passengers.=',{"passengerid":' . ( ++$key) . ',"passengersename":"' . $passengersename . '","piaotype":"' . $piaotype . '","piaotypename":"' . $piaotypename . '","passporttypeseid":"' . $passporttypeseid . '","passporttypeseidname":"' . $passporttypeseidname . '","passportseno":"' . $passportseno . '","price":"1","zwcode":"' . $zwcode . '","zwname":"' . $zwname . '"}';
|
||||
}
|
||||
$passengers.="]";
|
||||
$passengers = substr($passengers, 1);
|
||||
$passengers = "[" . $passengers;
|
||||
$url=$this->dp_api;
|
||||
if(empty($selectseat)){
|
||||
$post_data=array(
|
||||
"key"=>$this->key,
|
||||
"user_orderid"=>$cold_sn,//自定义订单号
|
||||
"train_date"=>substr($data["train"]->DepartureDate, 0, 10),
|
||||
"is_accept_standing"=>"no",
|
||||
"from_station_name"=>$data["train"]->DepartAirport_cn,
|
||||
"from_station_code"=>$data["train"]->DepartAirport,
|
||||
"to_station_code"=>$data["train"]->ArrivalAirport,
|
||||
"to_station_name"=>$data["train"]->ArrivalAirport_cn,
|
||||
"passengers"=>$passengers,
|
||||
"checi"=>$data["train"]->FlightsNo
|
||||
);
|
||||
}else{
|
||||
$post_data=array(
|
||||
"key"=>$this->key,
|
||||
"user_orderid"=>$cold_sn,//自定义订单号
|
||||
"train_date"=>substr($data["train"]->DepartureDate, 0, 10),
|
||||
"is_accept_standing"=>"no",
|
||||
"choose_seats"=>$selectseat,
|
||||
"from_station_name"=>$data["train"]->DepartAirport_cn,
|
||||
"from_station_code"=>$data["train"]->DepartAirport,
|
||||
"to_station_code"=>$data["train"]->ArrivalAirport,
|
||||
"to_station_name"=>$data["train"]->ArrivalAirport_cn,
|
||||
"passengers"=>$passengers,
|
||||
"checi"=>$data["train"]->FlightsNo
|
||||
);
|
||||
}
|
||||
|
||||
return $coli_id.'('.$cold_sn.')可以自动出票';
|
||||
}
|
||||
|
||||
//
|
||||
public function count_select(){
|
||||
$obj = $this->BIZ_train_model->get_juhe_select();
|
||||
//print_r($obj);
|
||||
$html = '';
|
||||
$html .= '<table border="1">';
|
||||
$html .= '<tr><th>序号</th><th>聚合订单号</th><th>出票后信息</th><th>订单原信息</th><th>是否自动出票</th></tr>';
|
||||
$i = 1;
|
||||
foreach($obj as $item){
|
||||
$html .= '<tr><td>'.$i.'</td><td>'.$item->JOL_JuheOrder.'</td>';
|
||||
if(isset(json_decode($item->JOL_BackTxt)->passengers)){
|
||||
$passengers = json_decode($item->JOL_BackTxt)->passengers;
|
||||
}else{
|
||||
$passengers = '';
|
||||
}
|
||||
$ex_obj = '';
|
||||
if(!empty($passengers)){
|
||||
foreach($passengers as $pass_tiem){
|
||||
$ex_obj .= $pass_tiem->cxin;
|
||||
}
|
||||
}
|
||||
if($item->JOL_IsAuto == '1'){
|
||||
$item->JOL_IsAuto ='是';
|
||||
}else{
|
||||
$item->JOL_IsAuto ='否';
|
||||
}
|
||||
$html .= '<td>'.$ex_obj.'</td><td>'.$item->FOI_SelectedSeat.'</td><td>'.$item->JOL_IsAuto.'</td></tr>';
|
||||
$i++;
|
||||
}
|
||||
$html .= '</table>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
public function update_juheorder(){
|
||||
print_r($this->BIZ_train_model->test());
|
||||
}
|
||||
|
||||
public function update_state($cold_sn){
|
||||
//先更新当前订单
|
||||
$flag = $this->BIZ_train_model->update_cold_state($cold_sn);
|
||||
if(!$flag){
|
||||
log_message('error','状态更新失败:'.$cold_sn);
|
||||
}else{
|
||||
$coli_sn = $this->BIZ_train_model->cold_sn_get_coli_sn($cold_sn);
|
||||
$coli_sn = $coli_sn[0]->COLD_COLI_SN;
|
||||
$all_train = $this->BIZ_train_model->get_alltrain($coli_sn);
|
||||
$all_count = count($all_train);
|
||||
$success_count = 0;
|
||||
foreach($all_train as $value){
|
||||
if($value->COLD_State == '61'){
|
||||
$success_count++;
|
||||
}
|
||||
}
|
||||
if($all_count == $success_count){
|
||||
$this->BIZ_train_model->update_coli_state('61',$coli_sn);
|
||||
}else{
|
||||
$this->BIZ_train_model->update_coli_state('62',$coli_sn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//测试发送邮件
|
||||
public function test_send(){
|
||||
$phone = '18677367018';
|
||||
$name = 'sw';
|
||||
$coli_id = '780258';
|
||||
$email = 'sw@hainatravel.com';
|
||||
|
||||
$mail_data = array();
|
||||
$mail_data['name'] = $name;
|
||||
$mail_data['phone'] = $phone;
|
||||
$mailtitle = 'Signup successfully on China Highlights Customer Center';
|
||||
$mail_body = $this->load->view('train_help',$mail_data,true);
|
||||
$fromName = 'China Highlights Customer Center';
|
||||
$fromEmail = 'sharon@chinahighlights.net';
|
||||
$toName = $name;
|
||||
$toEmail = $email;
|
||||
$this->load->model("Sendmail_model");
|
||||
$this->Sendmail_model->SendMailToTable($fromName, $fromEmail, $toName, $toEmail, $mailtitle, $mail_body);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -0,0 +1,251 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
|
||||
class Tuniu_callback extends CI_Controller{
|
||||
public function __construct(){
|
||||
// header("Content-Type: text/html;charset=utf-8");
|
||||
parent::__construct();
|
||||
$this->load->library('Des');
|
||||
$this->load->model("BIZ_train_model");
|
||||
$this->load->model("tuniu_model");
|
||||
}
|
||||
/*
|
||||
接收占位回调
|
||||
*/
|
||||
public function book(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
log_message('error','预定占座回调:'.$back_json);
|
||||
$back_data_one = json_decode(base64_decode($back_json));
|
||||
$back_data = array();
|
||||
$crypt = new DES();
|
||||
$mstr = $crypt->decrypt($back_data_one->data,TUNIU_KEY);
|
||||
$back_data_two = json_decode($mstr);
|
||||
|
||||
$back_data['errorMsg'] = $back_data_one->errorMsg;
|
||||
$back_data['returnCode'] = $back_data_one->returnCode;
|
||||
$back_data['retailOrderId'] = $back_data_two->retailOrderId;
|
||||
$back_data['orderId'] = $back_data_two->orderId;
|
||||
$back_data['orderAmount'] = $back_data_two->orderAmount;
|
||||
$back_data['fromStationCode'] = $back_data_two->fromStationCode;
|
||||
$back_data['fromStationName'] = $back_data_two->fromStationName;
|
||||
$back_data['toStationCode'] = $back_data_two->toStationCode;
|
||||
$back_data['toStationName'] = $back_data_two->toStationName;
|
||||
$back_data['cheCi'] = $back_data_two->cheCi;
|
||||
$back_data['backtxt'] = $mstr;
|
||||
$back_data['status'] = '2';
|
||||
//更新预定异步回调信息
|
||||
$this->tuniu_model->book_tuniu_order($back_data);
|
||||
if($back_data['returnCode'] == '231000'){
|
||||
$url = 'http://www.mycht.cn/info.php/apps/train/tuniu_train/confirm_ticket/'.$back_data['retailOrderId'].'/'.$back_data['orderId'];
|
||||
echo $url;
|
||||
$this->get_http($url,'GET');
|
||||
}
|
||||
}
|
||||
|
||||
public function test(){
|
||||
$back_json = "eyJlcnJvck1zZyI6IuihjOeoi+WGsueqgSIsInJldHVybkNvZGUiOjMwMywiZGF0YSI6IjBwZE4zaWlUWE1ISzFPRndGL2Evei9vZzc1dVZsSVpwVzBKTFdnS3dybUlaYWRUSnhEVmNZeW5ib1BZWFBNaWhJazVEVzBhYlBQbDhcbitXdWFCUUVsbmlzcWhBN1ZJSndEZEVvN0JCR0t4RXZ2K0wya090cEkvV01aK0JGTEFJc1hyYi9ZMWM5MTZnUjhIOUROYTdYdXpUV29cbkpzdmI0eTF6aUI5U3BIYWFPM2pQWXZyRHAvMUJCZndPanRuQVNVK2plcGNyMkZoekVJRDRMOHpRV0hMSFNRc2ZoVzVDeHpoQ1J0VUhcbmNFc0tpL212ZEVRcGFEb0diZE1JOWxlWUp4TFZWT0xrNUdCbEh0cGVSNTVBNTNtckVJbExiYU9TNGlRMURCQjUrUjAydzNDYldreHpcblcwWXFFT2U0Znc4R2U2QksyczFlVlYwc1VMSU90YzBZTU00TU4xeUpITHFMdGxieHFKclhjZTJjNi9WYTNjMnJDSk5DN1ltZ004NWVcbi9wYTk2VHNhaytoYUtSNUFncUQ4OXd4aUhETkNlQmEzRHpXMlh2NUZiYVRUc3RJcHRYbTZEaHo5U1Q3ZkJkcTlzYkhSMHdqMlY1Z25cbkV0VWVSR1F5a1hadTJqUDBaZjc5YTFHaCJ9";
|
||||
//print_r(base64_encode($back_json));
|
||||
$back_data = $this->tuniu_strdecrypt($back_json);
|
||||
print_r($back_data);
|
||||
//echo (count($back_data->data->passengers)*5);
|
||||
}
|
||||
|
||||
/*
|
||||
接收取消占位回调
|
||||
*/
|
||||
public function cancelbook(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
$sn = 5830;
|
||||
log_message('error','取消站位'.$back_json);
|
||||
}
|
||||
|
||||
/*
|
||||
接收确认出票回调
|
||||
*/
|
||||
public function confirm(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
//$back_json = 'eyJlcnJvck1zZyI6IuWkhOeQhuaIluaTjeS9nOaIkOWKnyIsInJldHVybkNvZGUiOjIzMTAwMCwiZGF0YSI6eyJyZXRhaWxPcmRlcklkIjoiNDg4MDkzNDQ4XzE1MzM3OTQwMDIiLCJvcmRlcklkIjoiMTE4NDUxMjM5NyJ9fQ==';
|
||||
$back_data = json_decode(base64_decode($back_json));
|
||||
//print_r($back_data);
|
||||
//die();
|
||||
log_message('error','确认出票回调:'.$back_json);
|
||||
$data = array();
|
||||
$data['errorMsg'] = $back_data->errorMsg;
|
||||
$data['returnCode'] = $back_data->returnCode;
|
||||
$data['retailOrderId'] = $back_data->data->retailOrderId;
|
||||
$data['orderId'] = $back_data->data->orderId;
|
||||
$data['confirmtxt'] = $back_json;
|
||||
|
||||
if($back_data->returnCode != '231000'){
|
||||
$data['status'] = '1';
|
||||
}else{
|
||||
$data['status'] = '4';
|
||||
//通过订单号去获取预定时返回的信息
|
||||
$bookobj = $this->tuniu_model->get_tuniuorder_info($data['retailOrderId'],$data['orderId']);
|
||||
$bookinfo = json_decode($bookobj[0]->tol_booktxt);
|
||||
$obj = explode('_',$back_data->data->retailOrderId);
|
||||
$add_train_order_data->TOC_COLD_SN = $obj[0];
|
||||
$add_train_order_data->TOC_Memo = $back_data->data->orderId;
|
||||
$add_train_order_data->TOC_TrainNumber = $bookinfo->cheCi;
|
||||
$add_train_order_data->TOC_DepartureDate = $bookinfo->trainDate;
|
||||
$add_train_order_data->TOC_TicketCost = $bookinfo->orderAmount;
|
||||
$add_train_order_data->FOI_TrainNetOrderNo = $bookinfo->orderNumber;
|
||||
$add_train_order_data->poundage = (count($bookinfo->passengers)*3)."";
|
||||
$this->tuniu_model->add_grab_order($add_train_order_data);
|
||||
}
|
||||
$this->tuniu_model->confirm_tuniu_order($data);
|
||||
}
|
||||
|
||||
/*
|
||||
接收退票回调
|
||||
*/
|
||||
public function return_ticket(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
log_message('error','退票回调:'.$back_json);
|
||||
$back_data = $this->tuniu_strdecrypt($back_json);
|
||||
//更新途牛订单列表信息
|
||||
$updata_data = array();
|
||||
$updata_data['retailOrderId'] = $back_data->data->retailOrderId;
|
||||
$updata_data['returnCode'] = $back_data->returnCode;
|
||||
$updata_data['errorMsg'] = $back_data->errorMsg;
|
||||
$updata_data['returntxt'] = json_encode($back_data);
|
||||
$this->tuniu_model->return_tuniu_order($updata_data);
|
||||
|
||||
//添加瀚特信息(有问题)
|
||||
/*$add_train_order_data = new stdClass();
|
||||
$obj = explode('_',$back_data->data->retailOrderId);
|
||||
$add_train_order_data->TOC_COLD_SN = $obj[0];
|
||||
$add_train_order_data->TOC_Memo = $back_data->data->orderId." ".$back_data->data->returnTickets->passportNo;
|
||||
$add_train_order_data->TOC_TrainNumber = $back_data->data->cheCi;
|
||||
$add_train_order_data->TOC_TicketCost = $back_data->data->returnMoney;
|
||||
$add_train_order_data->FOI_TrainNetOrderNo = null;
|
||||
$this->tuniu_model->add_return_order($add_train_order_data);*/
|
||||
}
|
||||
|
||||
/*
|
||||
接收线下退款回调
|
||||
*/
|
||||
public function return_cash(){
|
||||
echo '回调接收线下退款数据';
|
||||
}
|
||||
|
||||
/*
|
||||
接收抢票预定(占位)
|
||||
*/
|
||||
public function grabTicketBook(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
$back_data = $this->tuniu_strdecrypt($back_json);
|
||||
log_message('error','抢票预定:'.$back_json);
|
||||
$update_data = array();
|
||||
if($back_data->returnCode == '231000'){
|
||||
$update_data['errorMsg'] = $back_data->errorMsg;
|
||||
$update_data['returnCode'] = $back_data->returnCode;
|
||||
$update_data['retailOrderId'] = $back_data->data->retailOrderId;
|
||||
$update_data['orderId'] = $back_data->data->orderId;
|
||||
$update_data['fromStationCode'] = $back_data->data->fromStationCode;
|
||||
$update_data['fromStationName'] = $back_data->data->fromStationName;
|
||||
$update_data['toStationCode'] = $back_data->data->toStationCode;
|
||||
$update_data['toStationName'] = $back_data->data->toStationName;
|
||||
$update_data['cheCi'] = $back_data->data->cheCi;
|
||||
$update_data['orderAmount'] = $back_data->data->orderAmount;
|
||||
$update_data['booktxt'] = json_encode($back_data);
|
||||
//更新数据库信息
|
||||
$this->tuniu_model->grab_tuniu_order($update_data);
|
||||
|
||||
//添加瀚特信息
|
||||
$add_train_order_data = new stdClass();
|
||||
$obj = explode('_',$back_data->data->retailOrderId);
|
||||
$add_train_order_data->TOC_COLD_SN = $obj[0];
|
||||
$add_train_order_data->TOC_Memo = $back_data->data->orderId;
|
||||
$add_train_order_data->TOC_TrainNumber = $back_data->data->cheCi;
|
||||
$add_train_order_data->TOC_DepartureDate = $back_data->data->trainDate;
|
||||
$add_train_order_data->TOC_TicketCost = $back_data->data->orderAmount;
|
||||
$add_train_order_data->FOI_TrainNetOrderNo = $back_data->data->orderNumber;
|
||||
$add_train_order_data->poundage = (count($back_data->data->passengers)*5)."";
|
||||
$this->tuniu_model->add_grab_order($add_train_order_data);
|
||||
//print_r($update_data['booktxt']);
|
||||
}else{
|
||||
$update_data['retailOrderId'] = $back_data->data->retailOrderId;
|
||||
$update_data['errorMsg'] = $back_data->errorMsg;
|
||||
$update_data['returnCode'] = $back_data->returnCode;
|
||||
$this->tuniu_model->update_status($update_data);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
接收取消抢票
|
||||
*/
|
||||
public function cancelTicketBook(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
log_message('error','取消抢票:'.$back_json);
|
||||
$back_data = json_decode(base64_decode($back_json));
|
||||
$update_data = array();
|
||||
$update_data['errorMsg'] = $back_data->errorMsg;
|
||||
$update_data['returnCode'] = $back_data->returnCode;
|
||||
$update_data['orderId'] = $back_data->data->orderId;
|
||||
$update_data['retailOrderId'] = $back_data->data->retailOrderId;
|
||||
$this->tuniu_model->cancelgragticket($update_data);
|
||||
}
|
||||
|
||||
/*
|
||||
接收改签预定
|
||||
*/
|
||||
public function change_occupy(){
|
||||
echo '回调接收改签预定数据';
|
||||
}
|
||||
|
||||
/*
|
||||
接收改签确认
|
||||
*/
|
||||
public function change_confirm(){
|
||||
echo '回调接收改签确认数据';
|
||||
}
|
||||
|
||||
/*
|
||||
接收改签预定
|
||||
*/
|
||||
public function change_cancel(){
|
||||
echo '回调接收改签取消数据';
|
||||
}
|
||||
|
||||
//解密方法
|
||||
public function tuniu_strdecrypt($str){
|
||||
$back_data_one = json_decode(base64_decode($str));
|
||||
$back_data = array();
|
||||
$crypt = new DES();
|
||||
$mstr = $crypt->decrypt($back_data_one->data,TUNIU_KEY);
|
||||
$back_data_one->data = json_decode($mstr);
|
||||
return $back_data_one;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//发送请求函数
|
||||
public 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_HTTPHEADER, array('Content-Type:application/json'));
|
||||
}
|
||||
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;
|
||||
echo $errno . curl_error($curl); //记录错误日志
|
||||
}
|
||||
curl_close($curl); //关闭CURL会话
|
||||
return $tmpInfo; //返回数据
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
//特殊字符转换
|
||||
function chk_sp_name($name){
|
||||
$name = str_replace(
|
||||
array('á', 'é', 'í', 'ó', 'ú', '?', 'á', 'é', 'í', 'ó', 'ú', '?',' ','/',' ',','),
|
||||
array('a', 'e', 'i', 'o', 'u', 'n', 'A', 'E', 'I', 'O', 'U', 'N','','','',''),
|
||||
$name
|
||||
);
|
||||
return substr(strtoupper($name),0,30);
|
||||
}
|
||||
|
||||
//发送请求函数
|
||||
function GetPost_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_HTTPHEADER, array('Content-Type:application/json'));
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 40000); // 设置超时限制防止死循环
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
||||
$tmpInfo = curl_exec($curl); // 执行操作
|
||||
$errno = curl_errno($curl);
|
||||
if ($errno !== 0) {
|
||||
log_message('error', 'ctripost'.$errno.curl_error($curl));
|
||||
}
|
||||
curl_close($curl); //关闭CURL会话
|
||||
return $tmpInfo; //返回数据
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
class Des
|
||||
{
|
||||
|
||||
function encrypt($string,$key)
|
||||
{
|
||||
$size = mcrypt_get_block_size('des','ecb');
|
||||
//$string = mb_convert_encoding($string, 'GBK', 'UTF-8');
|
||||
$string = $this->pkcs5_pad($string, $size);
|
||||
$td = mcrypt_module_open('des', '', 'ecb', '');
|
||||
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
@mcrypt_generic_init($td, $key, $iv);
|
||||
$data = mcrypt_generic($td, $string);
|
||||
mcrypt_generic_deinit($td);
|
||||
mcrypt_module_close($td);
|
||||
$data = base64_encode($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
function decrypt($string,$key)
|
||||
{
|
||||
$string = base64_decode($string);
|
||||
$td = mcrypt_module_open('des', '', 'ecb', '');
|
||||
//使用MCRYPT_DES算法,cbc模式
|
||||
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
$ks = mcrypt_enc_get_key_size($td);
|
||||
@mcrypt_generic_init($td, $key, $iv);
|
||||
//初始处理
|
||||
$decrypted = mdecrypt_generic($td, $string);
|
||||
//解密
|
||||
mcrypt_generic_deinit($td);
|
||||
//结束
|
||||
mcrypt_module_close($td);
|
||||
|
||||
$result = $this->pkcs5_unpad($decrypted);
|
||||
//$result = mb_convert_encoding($result, 'UTF-8', 'GBK');
|
||||
return $result;
|
||||
}
|
||||
|
||||
function pkcs5_pad($text, $blocksize)
|
||||
{
|
||||
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||
return $text . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
function pkcs5_unpad($text)
|
||||
{
|
||||
$pad = ord($text{strlen($text) - 1});
|
||||
if ($pad > strlen($text)) {
|
||||
return false;
|
||||
}
|
||||
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
|
||||
return false;
|
||||
}
|
||||
return substr($text, 0, -1 * $pad);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
class tuniuprice_model extends CI_Model {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Dear <?php echo $toname?>,</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;"> Thank you for your booking (order number <?php echo $coli_id?>), we have received your payment of USD<?php echo $price->GAI_SQJE?>. </p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;"> Due to the heavy traffic flow of data, the system failed to automatically issue your ticket(s).</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Your travel advisor will purchase your train ticket(s) manually. You will receive an email within half a working day (Our time now: <strong><?php echo date('H:i').' '.date('a');?></strong>, <?php echo date('D');?>,<?php echo date('F').' '.date('d').','.date('Y');?> GMT+8).Should you have any questions or concerns with regards to your train booking, please do not hesitate to contact me at <a href="mailto:<?php echo $emailarr[0]?>"><?php echo $emailarr[0]?></a>;<a href="mailto:<?php echo $emailarr[1]?>"><?php echo $emailarr[1]?></a> or telephone <?php echo $operator[0]->tel;?>. </p>
|
||||
<?php foreach($train_info as $item){
|
||||
echo '<table border="0" cellspacing="0" cellpadding="0" width="60%">';
|
||||
echo '<tr><th width="17%" style="font-family:Verdana, Geneva, sans-serif;font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Train No. </th>';
|
||||
echo '<td width="83%" style="font-family:Verdana, Geneva, sans-serif;font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->FlightsNo.'</td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Departure </th>';
|
||||
echo '<td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->DepartureTime.', '.$item->DepartureCity.' Station(in Chinese '.$item->DepartAirport_cn.'火车站) </td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Arrival </th><td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->ArrivalTime.', '.$item->ArrivalCity.'(in Chinese'. $item->ArrivalAirport_cn.'火车站) </td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Class </th><td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->Cabin.'</td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Passenger(s) </th>';
|
||||
echo '<td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">';
|
||||
if($adult>0){echo $adult.' adult(s)<br/> ';}
|
||||
if($chlid>0){echo $chlid.' chlid(s)<br/> ';}
|
||||
if($baby>0){echo $baby.' baby(s)<br/> ';}
|
||||
$i=0;
|
||||
foreach($allpeople as $item){
|
||||
echo ++$i.'.'.$item->BPE_FirstName.$item->BPE_MiddleName.$item->BPE_LastName.' , passport number '.$item->BPE_Passport.'<br>';
|
||||
}
|
||||
echo '</tr></table>';
|
||||
echo '<p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Regards <br />';
|
||||
echo $operator[0]->Name.'<br/>Travel Advisor<br/>';
|
||||
echo 'Telephone: (Office)'.$operator[0]->tel.', M: '.$operator[0]->Mobile.',';
|
||||
echo 'Email: <a href="mailto:'.$emailarr[0].'">'.$emailarr[0].'</a>;<a href="mailto:'.$emailarr[1].'">'.$emailarr[1].'</a>; </p>';
|
||||
}?>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,23 @@
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">交易记录导出 <a style="margin-left:50px;" target='_blank' href="<?php echo site_url('apps/train/index/ht_order_list');?>">订单列表>></a> </h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form style="width: 500px;float: left;" action="" method="post">
|
||||
<input type="text" name="from_date" class="date" value="">至
|
||||
<input type="text" name="to_date" class="date" value="">
|
||||
<button type="submit" id="sub" class="btn btn-warning btn-sm"><span class="glyphicon glyphicon-download-alt"></span> 导出</button>
|
||||
</form>
|
||||
<p style="margin: 0 0 10px; width: 200px; float: left; line-height: 30px;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(".date").datepicker({
|
||||
'format': 'yyyy-m-d',
|
||||
'autoclose': true
|
||||
});
|
||||
</script>
|
||||
@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Dear <?php echo $name?>,</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Thank you for your interest in China Highlights.</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Your account has been created with your phone number : <?php echo $phone?></p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">If you have any questions, please don't hesitate to contact us : <a href="https://www.chinahighlights.com/contactus/">https://www.chinahighlights.com/contactus/</a></p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Thanks,</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">The China Highlights Team</p>
|
||||
</body></html>
|
||||
@ -0,0 +1,137 @@
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">翰特订单号 <a style="margin-left:50px;" target='_blank' href="<?php echo site_url('apps/train/tuniu_train/ht_order_list');?>">订单列表>></a><a style="margin-left:50px;" target='_blank' href="<?php echo site_url('apps/train/index/export');?>">导出交易记录>></a> <span style="margin-left:200px;">途牛抢票测试版</span></h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form style="width: 300px;float: left;" action="" method="post">
|
||||
<input type="text" name="ht_order" value="<?php echo isset($cols_id)?$cols_id:""; ?>">
|
||||
<button type="submit" id="sub" class="btn btn-warning btn-sm"><span class="glyphicon glyphicon-download-alt"></span> 获取信息</button>
|
||||
</form>
|
||||
<p style="margin: 0 0 10px; width: 200px; float: left; line-height: 30px;">外联:<span><?php if(!empty($wl)){echo $wl[0]->OPI_Name;}?></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">火车订单信息</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php if(!empty($info)):?>
|
||||
<?php $num=1; foreach($info as $v):?>
|
||||
<table class="table table-bordered table-hover" style="text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">车次</th>
|
||||
<th style="text-align:center;">座位</th>
|
||||
<th style="text-align:center;">出发城市</th>
|
||||
<th style="text-align:center;">抵达城市</th>
|
||||
<th style="text-align:center;">发车日期</th>
|
||||
<th style="text-align:center;">发车时间</th>
|
||||
<th style="text-align:center;">抵达时间</th>
|
||||
<th style="text-align:center;">票价</th>
|
||||
<th style="text-align:center;">是否提交过</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td><?php echo $num++;?></td>
|
||||
<td><?php echo $v->train[0]->FlightsNo;?></td>
|
||||
<td><?php echo $v->train[0]->Cabin;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureCity;?></td>
|
||||
<td><?php echo $v->train[0]->ArrivalCity;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureDate;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureTime;?></td>
|
||||
<td><?php echo $v->train[0]->ArrivalTime;?></td>
|
||||
<td><?php echo $v->train[0]->adultcost;?></td>
|
||||
<td><?php echo !empty($v->status)?"否":"<span style='color:green;'>是</span>";?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="11">
|
||||
<table class="table table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;"><input class="check_people" type="checkbox" /></th>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">姓名</th>
|
||||
<th style="text-align:center;">护照</th>
|
||||
<th style="text-align:center;">年龄类型</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($v->people as $key=>$p): ?>
|
||||
<tr>
|
||||
<td><input name="" type="checkbox" value="<?php echo $p->BPE_SN;?>" /></td>
|
||||
<td><?php echo $key+1;?></td>
|
||||
<td class="people_name"><?php echo $p->BPE_FirstName." ".$p->BPE_MiddleName." ".$p->BPE_LastName;?></td>
|
||||
<td><?php echo $p->BPE_Passport;?></td>
|
||||
<td><?php echo $p->BPE_GuestType==1?"成人":($p->BPE_GuestType==2?"儿童":"婴儿");?></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
<tr style="text-align:;">
|
||||
<td>
|
||||
<button type="button" class="btn btn-success checked_pay" data-order="<?php echo $v->train[0]->FOI_COLD_SN;?>">抢票</button>
|
||||
</td>
|
||||
<td colspan="4" class="biaoqian"><span class="back_mes" style="color:red;line-height: 30px;"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="back_<?php echo $v->train[0]->FOI_COLD_SN;?>" style="display:none;">
|
||||
<td colspan="5">
|
||||
快捷订票处理结果:<span style="color:red;"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endforeach;endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(".check_people").click(function(){
|
||||
if($(this).is(":checked")){
|
||||
$(this).parent().parent().parent().parent().find("input[type=checkbox]").attr("checked","checked");
|
||||
}else{
|
||||
$(this).parent().parent().parent().parent().find("input[type=checkbox]").removeAttr("checked");
|
||||
}
|
||||
});
|
||||
$(".checked_pay").click(function(){
|
||||
var url2="<?php echo site_url('apps/train/tuniu_train/grabTicketBook?').'order=';?>";
|
||||
var checkbox=$(this).parent().parent().parent().find(":checked");
|
||||
var people_sn="";
|
||||
checkbox.each(function(i){
|
||||
people_sn+=","+$(this).val();
|
||||
});
|
||||
people_sn=people_sn.substring(1);
|
||||
var coli_id = $('input[name="ht_order"]').val();
|
||||
url2+=$(this).attr("data-order")+"&people="+people_sn+"&coli_id="+coli_id;
|
||||
|
||||
var THIS=$(this);
|
||||
THIS.parent().parent().find(".back_mes").html(" ");//清空提示
|
||||
$.ajax({
|
||||
url:url2,
|
||||
beforeSend:function(data){
|
||||
//THIS.html("处理中...");
|
||||
//THIS.attr("disabled","disabled")
|
||||
},
|
||||
success:function(data){
|
||||
//THIS.removeAttr("disabled");
|
||||
//THIS.html("订票");
|
||||
//THIS.parent().parent().find(".back_mes").html(data.mes);
|
||||
|
||||
},
|
||||
dataType: "json",
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
@ -0,0 +1,82 @@
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">订单搜索</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<form style="" action="" method="get">
|
||||
<div class="col-md-6">
|
||||
<input class="form-control" type="text" placeholder="汉特订单号或聚合订单号" name="order" value="<?php echo !empty($order)?"$order":"";?>">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<button type="submit" id="sub" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-search"></span> 搜索</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">订单列表</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped" style="text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">汉特订单号</th>
|
||||
<th style="text-align:center;">途牛订单号</th>
|
||||
<th style="text-align:center;">车次</th>
|
||||
<th style="text-align:center;">出发</th>
|
||||
<th style="text-align:center;">到达</th>
|
||||
<th style="text-align:center;">状态</th>
|
||||
<th style="text-align:center;">价格</th>
|
||||
<th style="text-align:center;">提交时间</th>
|
||||
<th style="text-align:center;">所属部门</th>
|
||||
<!--<th style="text-align:center;">自动出票</th>
|
||||
<th style="text-align:center;">是否发送邮件</th>
|
||||
<th style="text-align:center;">操作</th>-->
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $num=0; foreach($data as $v):?>
|
||||
<tr>
|
||||
<td><?php echo ++$num;?></td>
|
||||
<td><?php echo $v->COLI_ID;?></td>
|
||||
<td><?php echo $v->tol_orderId;?></td>
|
||||
<td><?php echo $v->tol_cheCi;?></td>
|
||||
<td><?php echo $v->tol_fromStationName;?></td>
|
||||
<td><?php echo $v->tol_toStationName;?></td>
|
||||
<td><?php echo $v->info;?></td>
|
||||
<td><?php echo $v->tol_orderAmount;?></td>
|
||||
<td><?php echo $v->tol_subtime;?></td>
|
||||
<td><?php echo $v->COLI_WebCode;?></td>
|
||||
|
||||
<?php
|
||||
if($v->tol_isauto){
|
||||
echo '<td>是</td>';
|
||||
}else{
|
||||
echo '<td>否</td>';
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if($v->tol_sendmail == 1){
|
||||
if($v->JOL_M_SN){
|
||||
echo '<td><a target="_blank" href="http://www.mycht.cn/info.php/apps/train/index/get_mailinfo/'.$v->JOL_M_SN.'">是</a></td>';
|
||||
}else{
|
||||
echo '<td>是</td>';
|
||||
}
|
||||
}else{
|
||||
echo '<td>否</td>';
|
||||
}
|
||||
?>
|
||||
<td><a target="_blank" href="order?retailOrderId=<?php echo $v->tol_retailOrderId;?>&orderId=<?php echo $v->tol_orderId;?>">详情</a></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="text-align:right;"><ul class="pagination"><?php echo $page_link;?></ul></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,392 @@
|
||||
<style>
|
||||
.clear {clear: both;}
|
||||
.train-summary{ font-size:12px; margin-bottom:10px;}
|
||||
.train-summary span{ color:#9a0918;}
|
||||
a:link.seat-a{background-image:url(/css/images/train/a-seat.jpg); background-repeat:no-repeat; width:131px; display:block; height:42px; float:left;}
|
||||
a:hover.seat-a{background-image:url(/css/images/train/a-seath.jpg);}
|
||||
.selected_seat-a{background-image:url(/css/images/train/a-seata.jpg)!important; background-repeat:no-repeat; width:55px; display:block; height:42px; float:left;}
|
||||
a:link.seat-b{background-image:url(/css/images/train/b-seat.jpg); background-repeat:no-repeat; text-decoration:none; width:55px; display:block; height:42px; float:left;}
|
||||
a:hover.seat-b{background-image:url(/css/images/train/b-seath.jpg);}
|
||||
.selected_seat-b{background-image:url(/css/images/train/b-seata.jpg)!important; background-repeat:no-repeat; width:55px; display:block; height:42px; float:left;}
|
||||
a:link.seat-c{background-image:url(/css/images/train/c-seat.jpg); background-repeat:no-repeat; width:131px; display:block; height:42px; float:left;}
|
||||
a:hover.seat-c{background-image:url(/css/images/train/c-seath.jpg);}
|
||||
.selected_seat-c{background-image:url(/css/images/train/c-seata.jpg)!important; background-repeat:no-repeat; width:55px; display:block; height:42px; float:left;}
|
||||
a:link.seat-d{background-image:url(/css/images/train/d-seat.jpg); background-repeat:no-repeat; width:55px; display:block; height:42px; float:left;}
|
||||
a:hover.seat-d{background-image:url(/css/images/train/d-seath.jpg);}
|
||||
.selected_seat-d{background-image:url(/css/images/train/d-seata.jpg)!important; background-repeat:no-repeat; width:136px; display:block; height:42px; float:left;}
|
||||
a:link.seat-f{background-image:url(/css/images/train/f-seat.jpg); background-repeat:no-repeat; width:136px; display:block; height:42px; float:left;}
|
||||
a:hover.seat-f{background-image:url(/css/images/train/f-seath.jpg);}
|
||||
.selected_seat-f{background-image:url(/css/images/train/f-seata.jpg)!important; background-repeat:no-repeat; width:136px; display:block; height:42px; float:left;}
|
||||
a:link.sleep-a {background-image:url(/css/images/train/l-up.jpg); background-repeat:no-repeat; width:163px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-a { background-image:url(/css/images/train/l-upa.jpg); }
|
||||
.selected_sleep-a { background-image:url(/css/images/train/l-upa.jpg)!important; width:163px; display:block; height:38px; float:left; }
|
||||
a:link.sleep-b {background-image:url(/css/images/train/r-up.jpg); background-repeat:no-repeat; width:104px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-b { background-image:url(/css/images/train/r-upa.jpg); }
|
||||
.selected_sleep-b { background-image:url(/css/images/train/r-upa.jpg)!important; width:163px; display:block; height:38px; float:left; }
|
||||
a:link.sleep-c {background-image:url(/css/images/train/l-mid.jpg); background-repeat:no-repeat; width:163px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-c { background-image:url(/css/images/train/l-mida.jpg); }
|
||||
.selected_sleep-c { background-image:url(/css/images/train/l-mida.jpg)!important; width:163px; display:block; height:38px; float:left; }
|
||||
a:link.sleep-d {background-image:url(/css/images/train/r-mid.jpg); background-repeat:no-repeat; width:104px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-d { background-image:url(/css/images/train/r-mida.jpg); }
|
||||
.selected_sleep-d { background-image:url(/css/images/train/r-mida.jpg)!important; width:163px; display:block; height:38px; float:left; }
|
||||
a:link.sleep-e {background-image:url(/css/images/train/l-low.jpg); background-repeat:no-repeat; width:163px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-e { background-image:url(/css/images/train/l-lowa.jpg); }
|
||||
.selected_sleep-e { background-image:url(/css/images/train/l-lowa.jpg)!important; width:163px; display:block; height:38px; float:left; }
|
||||
a:link.sleep-f {background-image:url(/css/images/train/r-low.jpg); background-repeat:no-repeat; width:104px; display:block; height:38px; float:left; }
|
||||
a:hover.sleep-f { background-image:url(/css/images/train/r-lowa.jpg); }
|
||||
.selected_sleep-f { background-image:url(/css/images/train/r-lowa.jpg)!important; width:104px; display:block; height:38px; float:left; }
|
||||
</style>
|
||||
<script>
|
||||
$(function(){
|
||||
//var selected = $('.selectticket').find('.selected').length;
|
||||
//$('.selected_People').html(selected);
|
||||
});
|
||||
|
||||
function selseat(seat){
|
||||
var type = $(seat).attr('type');
|
||||
var total = $(seat).parent().parent().find('.train-summary .seat_TotalPeople').html();
|
||||
if(total>=5){
|
||||
total = 5;
|
||||
$('.seat_TotalPeople').html(total);
|
||||
}
|
||||
var count = $(seat).parent().parent().find('.selected').length;
|
||||
console.log('执行之前的数量'+count);
|
||||
//处理选座事件
|
||||
|
||||
if($(seat).hasClass('selected_'+type)){
|
||||
$(seat).removeClass('selected');
|
||||
$(seat).removeClass('selected_'+type);
|
||||
count = $(seat).parent().parent().find('.selected').length;
|
||||
$('.selected_People').html(count);
|
||||
console.log('减掉之后'+count);
|
||||
}else{
|
||||
if(count >= total){
|
||||
alert('You already chose seats for all the passengers.');
|
||||
}else{
|
||||
$(seat).addClass('selected_'+type);
|
||||
$(seat).addClass('selected');
|
||||
count = $(seat).parent().parent().find('.selected').length;
|
||||
$('.selected_People').html(count);
|
||||
console.log('增加之后'+count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">翰特订单号 <a style="margin-left:50px;" target='_blank' href="<?php echo site_url('apps/train/tuniu_train/ht_order_list');?>">订单列表>></a><a style="margin-left:50px;" target='_blank' href="<?php echo site_url('apps/train/index/export');?>">导出交易记录>></a> <span style="margin-left:200px;">途牛出票测试版</span></h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form style="width: 300px;float: left;" action="" method="post">
|
||||
<input type="text" name="ht_order" value="<?php echo isset($cols_id)?$cols_id:""; ?>">
|
||||
<button type="submit" id="sub" class="btn btn-warning btn-sm"><span class="glyphicon glyphicon-download-alt"></span> 获取信息</button>
|
||||
</form>
|
||||
<p style="margin: 0 0 10px; width: 200px; float: left; line-height: 30px;">外联:<span><?php if(!empty($wl)){echo $wl[0]->OPI_Name;}?></span></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">火车订单信息</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php if(!empty($info)):?>
|
||||
<?php $num=1; foreach($info as $v):?>
|
||||
<table class="table table-bordered table-hover" style="text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">车次</th>
|
||||
<th style="text-align:center;">座位</th>
|
||||
<th style="text-align:center;">出发城市</th>
|
||||
<th style="text-align:center;">抵达城市</th>
|
||||
<th style="text-align:center;">发车日期</th>
|
||||
<th style="text-align:center;">发车时间</th>
|
||||
<th style="text-align:center;">抵达时间</th>
|
||||
<th style="text-align:center;">票价</th>
|
||||
<th style="text-align:center;">是否提交过</th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<tr>
|
||||
<td><?php echo $num++;?></td>
|
||||
<td><?php echo $v->train[0]->FlightsNo;?></td>
|
||||
<td><?php echo $v->train[0]->Cabin;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureCity;?></td>
|
||||
<td><?php echo $v->train[0]->ArrivalCity;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureDate;?></td>
|
||||
<td><?php echo $v->train[0]->DepartureTime;?></td>
|
||||
<td><?php echo $v->train[0]->ArrivalTime;?></td>
|
||||
<td><?php echo $v->train[0]->adultcost;?></td>
|
||||
<td><?php echo !empty($v->status)?"否":"<span style='color:green;'>是</span>";?></td>
|
||||
<td><button type="button" class="btn btn-success pay_api" data-order="<?php echo $v->train[0]->FOI_COLD_SN;?>" title="超过五个乘客不可用" >快捷订票</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="11">
|
||||
<table class="table table-condensed table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;"><input class="check_people" type="checkbox" /></th>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">姓名</th>
|
||||
<th style="text-align:center;">护照</th>
|
||||
<th style="text-align:center;">年龄类型</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($v->people as $key=>$p): ?>
|
||||
<tr>
|
||||
<td><input name="" type="checkbox" value="<?php echo $p->BPE_SN;?>" /></td>
|
||||
<td><?php echo $key+1;?></td>
|
||||
<td class="people_name"><?php echo $p->BPE_FirstName." ".$p->BPE_MiddleName." ".$p->BPE_LastName;?></td>
|
||||
<td><?php echo $p->BPE_Passport;?></td>
|
||||
<td><?php echo $p->BPE_GuestType==1?"成人":($p->BPE_GuestType==2?"儿童":"婴儿");?></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
<tr style="text-align:;">
|
||||
<td colspan="11" class="selectticket">
|
||||
<?php
|
||||
$traintype = substr($v->train[0]->FlightsNo,0,1);
|
||||
$arr = array('C','D','G');
|
||||
$sel_count = 0;
|
||||
if(in_array($traintype,$arr)){
|
||||
$selectseat = '';
|
||||
$train_select = $v->train[0]->FOI_SelectedSeat;
|
||||
$a1=$b1=$c1=$d1=$f1=$a2=$b2=$c2=$d2=$f2=false;
|
||||
if($train_select){
|
||||
$obj = explode(',',$train_select);
|
||||
foreach($obj as $value){
|
||||
switch($value){
|
||||
case '1A':
|
||||
$a1 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '1B':
|
||||
$b1 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '1C':
|
||||
$c1 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '1D':
|
||||
$d1 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '1F':
|
||||
$f1 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '2A':
|
||||
$a2 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '2B':
|
||||
$b2 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '2C':
|
||||
$c2 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '2D':
|
||||
$d2 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
case '2F':
|
||||
$f2 = true;
|
||||
$sel_count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$html = '';
|
||||
$html .= '<div class="train-summary">'.$v->train[0]->Cabin.' for '.$v->train[0]->FlightsNo.' <span>(<span class="selected_People">'.$sel_count.'</span> of <span class="seat_TotalPeople">'.count($v->people).'</span> Seats)</span></div>';
|
||||
$html .= '<div class="seatPick">';
|
||||
if($a1){
|
||||
$html .= '<a class="seat-a selected_seat-a selected" type="seat-a" href="javascript:void(0);" data="1A" onclick ="selseat(this)";></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-a" type="seat-a" href="javascript:void(0);" data="1A" onclick ="selseat(this)";></a>';
|
||||
}
|
||||
|
||||
if($v->train[0]->Aircraft == 'O' || $v->train[0]->Aircraft == '8'){
|
||||
if($b1){
|
||||
$html .= '<a class="seat-b selected_seat-b selected" type="seat-b" href="javascript:void(0);" data="1B" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-b" type="seat-b" href="javascript:void(0);" data="1B" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
}
|
||||
if($c1){
|
||||
$html .= '<a class="seat-c selected_seat-c selected" type="seat-c" href="javascript:void(0);" data="1C" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-c" type="seat-c" href="javascript:void(0);" data="1C" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
if($v->train[0]->Aircraft != '9'){
|
||||
if($d1){
|
||||
$html .= '<a class="seat-d selected_seat-d selected" type="seat-d" href="javascript:void(0);" data="1D" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-d" type="seat-d" href="javascript:void(0);" data="1D" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
}
|
||||
if($f1){
|
||||
$html .= '<a class="seat-f selected_seat-f selected" type="seat-f" href="javascript:void(0);" data="1F" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-f" type="seat-f" href="javascript:void(0);" data="1F" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
$html .= '<div class="clear"></div></div>';
|
||||
$html .= '<div class="seatPick">';
|
||||
if($a2){
|
||||
$html .= '<a class="seat-a selected_seat-a selected" type="seat-a" href="javascript:void(0);" data="2A" onclick ="selseat(this)";></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-a" type="seat-a" href="javascript:void(0);" data="2A" onclick ="selseat(this)";></a>';
|
||||
}
|
||||
|
||||
if($v->train[0]->Aircraft == 'O' || $v->train[0]->Aircraft == '8'){
|
||||
if($b2){
|
||||
$html .= '<a class="seat-b selected_seat-b selected" type="seat-b" href="javascript:void(0);" data="2B" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-b" type="seat-b" href="javascript:void(0);" data="2B" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
}
|
||||
if($c2){
|
||||
$html .= '<a class="seat-c selected_seat-c selected" type="seat-c" href="javascript:void(0);" data="2C" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-c" type="seat-c" href="javascript:void(0);" data="2C" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
if($v->train[0]->Aircraft != '9'){
|
||||
if($d2){
|
||||
$html .= '<a class="seat-d selected_seat-d selected" type="seat-d" href="javascript:void(0);" data="2D" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-d" type="seat-d" href="javascript:void(0);" data="2D" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
}
|
||||
if($f2){
|
||||
$html .= '<a class="seat-f selected_seat-f selected" type="seat-f" href="javascript:void(0);" data="2F" onclick ="selseat(this);"></a>';
|
||||
}else{
|
||||
$html .= '<a class="seat-f" type="seat-f" href="javascript:void(0);" data="2F" onclick ="selseat(this);"></a>';
|
||||
}
|
||||
|
||||
$html .= '<div class="clear"></div></div>';
|
||||
|
||||
if($v->train[0]->Aircraft != 'F'){
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="text-align:;">
|
||||
<td>
|
||||
<button type="button" class="btn btn-success checked_pay" data-order="<?php echo $v->train[0]->FOI_COLD_SN;?>">订票</button>
|
||||
</td>
|
||||
<td colspan="4" class="biaoqian"><span class="back_mes" style="color:red;line-height: 30px;"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="back_<?php echo $v->train[0]->FOI_COLD_SN;?>" style="display:none;">
|
||||
<td colspan="5">
|
||||
快捷订票处理结果:<span style="color:red;"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endforeach;endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var url="<?php echo site_url('apps/train/index/submit_juhe_order?').'order=';?>";
|
||||
var order_ul="<?php echo site_url('apps/train/index/order?').'order=';?>";//订单详情页面
|
||||
|
||||
$(".pay_api").click(function(){
|
||||
// alert(url+$(this).attr("data-order"));
|
||||
var THIS=$(this);
|
||||
var order=$(this).attr("data-order");
|
||||
$.ajax({
|
||||
url:url+$(this).attr("data-order"),
|
||||
beforeSend:function(data){
|
||||
THIS.html("处理中...");
|
||||
THIS.attr("disabled","disabled")
|
||||
},
|
||||
success:function(data){
|
||||
THIS.removeAttr("disabled");
|
||||
THIS.html("快捷订票");
|
||||
if(data.status==1){
|
||||
THIS.parent().html("<a href='"+order_ul+data.order+"' target='_blank'>订单详情</a>");
|
||||
}
|
||||
|
||||
$("#back_"+order+" span").html(data.mes);
|
||||
$("#back_"+order).show();
|
||||
|
||||
},
|
||||
dataType: "json",
|
||||
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$(".check_people").click(function(){
|
||||
if($(this).is(":checked")){
|
||||
$(this).parent().parent().parent().parent().find("input[type=checkbox]").attr("checked","checked");
|
||||
}else{
|
||||
$(this).parent().parent().parent().parent().find("input[type=checkbox]").removeAttr("checked");
|
||||
}
|
||||
});
|
||||
$(".checked_pay").click(function(){
|
||||
var url2="<?php echo site_url('apps/train/tuniu_train/get_sn_submit_tuniu?').'order=';?>";
|
||||
var checkbox=$(this).parent().parent().parent().find(":checked");
|
||||
var people_sn="";
|
||||
checkbox.each(function(i){
|
||||
people_sn+=","+$(this).val();
|
||||
});
|
||||
|
||||
var selectseat = '';
|
||||
$(this).parent().parent().prev().find('.selected').each(function(){
|
||||
if($(this).hasClass('selected')){
|
||||
selectseat += $(this).attr('data');
|
||||
}
|
||||
});
|
||||
|
||||
people_sn=people_sn.substring(1);
|
||||
var coli_id = $('input[name="ht_order"]').val();
|
||||
url2+=$(this).attr("data-order")+"&people="+people_sn+"&coli_id="+coli_id+'&selectseat='+selectseat;
|
||||
|
||||
var THIS=$(this);
|
||||
THIS.parent().parent().find(".back_mes").html(" ");//清空提示
|
||||
$.ajax({
|
||||
url:url2,
|
||||
beforeSend:function(data){
|
||||
THIS.html("处理中...");
|
||||
THIS.attr("disabled","disabled")
|
||||
},
|
||||
success:function(data){
|
||||
THIS.removeAttr("disabled");
|
||||
THIS.html("订票");
|
||||
THIS.parent().parent().find(".back_mes").html(data.mes);
|
||||
|
||||
},
|
||||
dataType: "json",
|
||||
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
</script>
|
||||
@ -0,0 +1,113 @@
|
||||
<script type="text/javascript" src="/js/StationInfo.js"></script>
|
||||
<!-- 调用接口查询订单信息 -->
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">订单状态</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>途牛订单号:<?php echo $data->orderId?> 途牛订单状态:<?php echo $data->orderStatus?></p>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
//调用订单异步返回的信息
|
||||
//途牛订单状态接口查询不返回订单详细信息,只能在异步返回中查看,非常蛋疼。
|
||||
$info = json_decode($grab_callback);
|
||||
//print_r($info);
|
||||
//print_r($data);
|
||||
if($data->orderStatus == '抢票中'){ ?>
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">途牛操作</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p style="text-align:center;"><a href="#" tuniu_url="/cancelgrabTicket/<?php echo $data->retailOrderId.'/'.$data->orderId?>" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelgrab">取消抢票 <span class="glyphicon glyphicon-forward"></span></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php }else if($data->orderStatus == '出票成功'){ ?>
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><?php echo $info->trainDate;?> <?php echo $info->cheCi;?> <?php echo isset($info->orderNumber)?$info->orderNumber:"";?></h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p style="display:inline-block"><?php echo $info->fromStationName;?><span class="from_station_en"> </span><br><span class="start_time"></span></p><span class="glyphicon glyphicon-arrow-right"> </span><p style="display:inline-block"> <?php echo $info->toStationName;?><span class="to_station_en"> </span><br><span class="arrive_time"></span></p>
|
||||
<?php foreach ($info->passengers as $value){
|
||||
echo '<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>';
|
||||
echo '<p>'.$value->passengerName.'('.$value->piaoTypeName.') '.$value->zwName.' '.$value->cxin.' 票价:¥'.$value->price.'<a href="#" tuniu_url="/cancel_ticket/'.$info->retailOrderId.'/'.$info->orderId.'/'.$value->ticketNo.'/" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelticket pull-right">单人退票 <span class="glyphicon glyphicon-forward"></span></a></p>';
|
||||
}?>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p style="text-align:center;"><a href="#" tuniu_url="/cancel_ticket/<?php echo $info->retailOrderId.'/'.$info->orderId?>" style="padding:5px 15px;" class="btn btn-warning btn-sm cancelticket">一键全退 <span class="glyphicon glyphicon-forward"></span></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var StationInfoArr = StationInfo.split("@");
|
||||
var StationNameArr = new Array();
|
||||
var code_name = new Array();
|
||||
var station_cn_en = new Array();
|
||||
var form_data = {};
|
||||
for (var i = 0; i < StationInfoArr.length; ++i) {
|
||||
StationNameArr.push(StationInfoArr[i].split("|"));
|
||||
code_name[StationNameArr[i][1]] = [StationNameArr[i][2]];
|
||||
station_cn_en[StationNameArr[i][3]] = StationNameArr[i][2];
|
||||
}
|
||||
$(function(){
|
||||
var from_station_en = code_name['<?php echo $info->data->fromStationCode;?>'];
|
||||
var to_station_en = code_name['<?php echo $info->data->toStationCode;?>'];
|
||||
var start_time = '<?php echo $info->data->trainDate.' '.$info->data->startTime;?>';
|
||||
var arrive_time = '<?php echo $info->data->trainDate.' '.$info->data->arriveTime;?>';
|
||||
$('.from_station_en').html('('+from_station_en+') ');
|
||||
$('.to_station_en').html('('+to_station_en+')');
|
||||
$('.start_time').html('('+start_time.substring(0,start_time.length-3)+')');
|
||||
$('.arrive_time').html('('+arrive_time.substring(0,arrive_time.length-3)+')');
|
||||
});
|
||||
</script>
|
||||
<?php }?>
|
||||
<script>
|
||||
$(function(){
|
||||
$('.cancelgrab').click(function(){
|
||||
var cancel_url = $(this).attr('tuniu_url');
|
||||
var url = "<?php echo site_url('apps/train/tuniu_train')?>"+cancel_url;
|
||||
var THIS=$(this);
|
||||
$.ajax({
|
||||
url:url,
|
||||
beforeSend:function(data){
|
||||
THIS.html("处理中...");
|
||||
THIS.attr("disabled","disabled");
|
||||
},
|
||||
success:function(data){
|
||||
THIS.removeAttr("disabled");
|
||||
THIS.html("取消成功");
|
||||
},
|
||||
dataType: "json",
|
||||
});
|
||||
});
|
||||
|
||||
$('.cancelticket').click(function(){
|
||||
var cancel_url = $(this).attr('tuniu_url');
|
||||
var url = "<?php echo site_url('apps/train/tuniu_train')?>"+cancel_url;
|
||||
var THIS=$(this);
|
||||
$.ajax({
|
||||
url:url,
|
||||
beforeSend:function(data){
|
||||
THIS.html("处理中...");
|
||||
THIS.attr("disabled","disabled");
|
||||
},
|
||||
success:function(data){
|
||||
THIS.removeAttr("disabled");
|
||||
THIS.html("退票成功");
|
||||
},
|
||||
dataType: "json",
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
TOC_ID 自增ID
|
||||
TOC_COLI_SN 商务主表COLI_SN
|
||||
TOC_GroupName 团名
|
||||
TOC_COLD_SN 商务明细表COLD_SN
|
||||
TOC_TrainNumber 火车车次
|
||||
TOC_DepartureDate 出发日期
|
||||
TOC_TicketCost 价格
|
||||
TOC_OtherCost 其它成本标识
|
||||
TOC_NBBZ 是否内部报账标识
|
||||
TOC_BCM_Bill 交通银行账单标识
|
||||
TOC_WL 外联
|
||||
TOC_SFBZ 是否已报账标识
|
||||
TOC_Order 排序号
|
||||
TOC_Memo 备注
|
||||
TOC_PicName 上传图片名称(已不用)
|
||||
TOC_Creator 创建者
|
||||
TOC_CreateDate 创建日期
|
||||
TOC_LastEditor 最后修改者
|
||||
TOC_LastEditDate 最后修改日期
|
||||
TOC_DeleteFlag 删除标识
|
||||
TOC_ListOrder 查询排序字段
|
||||
TOC_MoveFlag 是否移动标识
|
||||
TOC_GetTicket 是否已取票
|
||||
TOC_Billing 是否已做账标识
|
||||
TOC_BZDate 报账日期
|
||||
TOC_NeedTicketFee 是否寄送状态
|
||||
|
||||
|
||||
|
||||
https://open-sbox.sf-express.com/rest/v1.0/route/query/access_token/15D008266E5E90964EC3C2F7B98C0A9F/sf_appid/00000111/sf_appkey/B21FA8B875514EBCEFEC7285A33E3000
|
||||
|
||||
|
||||
//令牌
|
||||
https://open-sbox.sf-express.com/public/v1.0/security/access_token/sf_appid/00021240/sf_appkey/2458B56F2B5C3E24B9C1AF1823458DDC
|
||||
|
||||
|
||||
//查询
|
||||
https://open-sbox.sf-express.com/public/v1.1.2/security/access_token/query/sf_appid/00021240/sf_appkey/2458B56F2B5C3E24B9C1AF1823458DDC
|
||||
{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2016-11-30","orderid":"1476686669783H","user_orderid":"488015272","orderamount":"5.50","ordernumber":"E903359160","checi":"D8238","msg":"有乘客退票成功,相关款项已退还至您的账户","status":"7","passengers":[{"passengerid":1,"passengersename":"CSK","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E127233","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E903359160107001A","cxin":"07车厢,01A座","reason":0,"returntickets":{"ticket_no":"E903359160107001A","passengername":"CSK","passporttypeseid":"B","passportseno":"E127233","refund_apply_time":"2016-10-17 14:49:17","returnsuccess":true,"returnmoney":"5.5","returntime":"2016-10-17 14:52:05","returnfailid":"","returnfailmsg":"","returntype":"1"},"refundTimeline":[{"time":"2016-10-17 14:49:17","msg":"线上申请退票"},{"time":"2016-10-17 14:52:05","msg":"线上退票成功","detail":{"returnsuccess":true,"returnmoney":"5.5","returntime":"2016-10-17 14:52:05","returnfailid":"","returnfailmsg":"","returntype":"1","ticket_no":"E903359160107001A","passengername":"CSK","passporttypeseid":"B","passportseno":"E127233"}}]}],"refund_money":"5.50","sign":"49121a3cada0af88b2ce64746dc7b13f"}
|
||||
|
||||
{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2016-11-30","orderid":"1476935104693H","user_orderid":"488015272","orderamount":"8.50","ordernumber":"E974154132","checi":"D8238","msg":"有乘客退票成功,相关款项已退还至您的账户","status":"7","passengers":[{"passengerid":1,"passengersename":"CSK","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E127233","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E974154132107001A","cxin":"07车厢,01A座","reason":0,"returntickets":{"ticket_no":"E974154132107001A","passengername":"CSK","passporttypeseid":"B","passportseno":"E127233","refund_apply_time":"2016-10-21 14:51:00","returnsuccess":true,"returnmoney":"5.5","returntime":"2016-10-21 14:52:06","returnfailid":"","returnfailmsg":"","returntype":"1"},"refundTimeline":[{"time":"2016-10-21 14:51:00","msg":"线上申请退票"},{"time":"2016-10-21 14:52:06","msg":"线上退票成功","detail":{"returnsuccess":true,"returnmoney":"5.5","returntime":"2016-10-21 14:52:06","returnfailid":"","returnfailmsg":"","returntype":"1","ticket_no":"E974154132107001A","passengername":"CSK","passporttypeseid":"B","passportseno":"E127233"}}]},{"passengerid":2,"passengersename":"test k","piaotype":"2","piaotypename":"儿童票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E127234","price":"3.0","zwcode":"O","zwname":"二等座","ticket_no":"E974154132107001D","cxin":"07车厢,01D座","reason":0,"returntickets":{"ticket_no":"E974154132107001D","passengername":"test k","passporttypeseid":"B","passportseno":"E127234","refund_apply_time":"2016-10-21 14:51:04"},"refundTimeline":[{"time":"2016-10-21 14:51:04","msg":"线上申请退票"}]}],"refund_money":"5.50","sign":"9671aa6b0bf8378403473d3a6452ac94"}
|
||||
|
||||
$data_post["data"]='{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2016-11-30","orderid":"1476343928878H","user_orderid":"488015272","orderamount":"5.50","ordernumber":"E098614072","checi":"D8888","msg":"出票成功","status":"4","passengers":[{"passengerid":1,"passengersename":"csk","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E11021322","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E098614072107001C","cxin":"07车厢,01C座","reason":0}],"refund_money":null,"sign":"9cd116f3c333a43e396c0acb115adc3f"}'
|
||||
|
||||
1、出票成功
|
||||
{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2017-01-22","orderid":"1482737845760H","user_orderid":"488020631","orderamount":"11.00","ordernumber":"E179703891","checi":"D8238","msg":"出票成功","status":"4","passengers":[{"passengerid":1,"passengersename":"CSK","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E132124","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014C","cxin":"06车厢,14C座","reason":0},{"passengerid":2,"passengersename":"TW","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E02030609","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014D","cxin":"06车厢,14D座","reason":0}],"refund_money":null,"sign":"a38d8ac11d00f800ae5b5753a693becd"}
|
||||
|
||||
2、CSK退票
|
||||
{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2017-01-22","orderid":"1482737845760H","user_orderid":"488020631","orderamount":"11.00","ordernumber":"E179703891","checi":"D8238","msg":"有乘客退票成功,相关款项已退还至您的账户","status":"7","passengers":[{"passengerid":1,"passengersename":"CSK","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E132124","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014C","cxin":"06车厢,14C座","reason":0,"returntickets":{"ticket_no":"E179703891106014C","passengername":"CSK","passporttypeseid":"B","passportseno":"E132124","refund_apply_time":"2016-12-26 15:50:11","returnsuccess":true,"returnmoney":"5.5","returntime":"2016-12-26 15:52:06","returnfailid":"","returnfailmsg":"","returntype":"1"},"refundTimeline":[{"time":"2016-12-26 15:50:11","msg":"线上申请退票"},{"time":"2016-12-26 15:52:06","msg":"线上退票成功","detail":{"returnsuccess":true,"returnmoney":"5.5","returntime":"2016-12-26 15:52:06","returnfailid":"","returnfailmsg":"","returntype":"1","ticket_no":"E179703891106014C","passengername":"CSK","passporttypeseid":"B","passportseno":"E132124"}}]},{"passengerid":2,"passengersename":"TW","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E02030609","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014D","cxin":"06车厢,14D座","reason":0}],"refund_money":"5.50","sign":"a38d8ac11d00f800ae5b5753a693becd"}
|
||||
|
||||
|
||||
|
||||
{"from_station_name":"桂林","from_station_code":"GLZ","to_station_name":"桂林北","to_station_code":"GBZ","train_date":"2017-01-22","orderid":"1482737845760H","user_orderid":"488020631","orderamount":"11.00","ordernumber":"E179703891","checi":"D8238","msg":"有乘客退票成功,相关款项已退还至您的账户","status":"7","passengers":[{"passengerid":1,"passengersename":"CSK","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E132124","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014C","cxin":"06车厢,14C座","reason":0,"returntickets":{"ticket_no":"E179703891106014C","passengername":"CSK","passporttypeseid":"B","passportseno":"E132124","refund_apply_time":"2016-12-26 15:50:11","returnsuccess":true,"returnmoney":"5.5","returntime":"2016-12-26 15:52:06","returnfailid":"","returnfailmsg":"","returntype":"1"},"refundTimeline":[{"time":"2016-12-26 15:50:11","msg":"线上申请退票"},{"time":"2016-12-26 15:52:06","msg":"线上退票成功","detail":{"returnsuccess":true,"returnmoney":"5.5","returntime":"2016-12-26 15:52:06","returnfailid":"","returnfailmsg":"","returntype":"1","ticket_no":"E179703891106014C","passengername":"CSK","passporttypeseid":"B","passportseno":"E132124"}}]},{"passengerid":2,"passengersename":"TW","piaotype":"1","piaotypename":"成人票","passporttypeseid":"B","passporttypeseidname":"护照","passportseno":"E02030609","price":"5.5","zwcode":"O","zwname":"二等座","ticket_no":"E179703891106014D","cxin":"06车厢,14D座","reason":0}],"refund_money":"5.50","sign":"a38d8ac11d00f800ae5b5753a693becd"}
|
||||
@ -0,0 +1,4 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
|
||||
define("JUHE_API_KEY","123");
|
||||
@ -0,0 +1,339 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class api extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->helper('train');
|
||||
$this->load->model("BIZ_train_model");
|
||||
$this->load->model("train_system_model");
|
||||
$this->load->model("Sendmail_model");
|
||||
}
|
||||
|
||||
public function index(){
|
||||
echo 'api manager';
|
||||
}
|
||||
|
||||
//获取订单出票状态
|
||||
public function isbooktickets(){
|
||||
$cold_sn = $this->input->get('cold_sn');
|
||||
|
||||
$tickets_info = $this->train_system_model->get_tickets_info($cold_sn);
|
||||
//print_r($tickets_info);
|
||||
if(!empty($tickets_info)){
|
||||
$return_data = array();
|
||||
$i = 0;
|
||||
foreach($tickets_info as $items){
|
||||
$return_data[$i] = new stdClass();
|
||||
$return_data[$i]->cold_sn = (int) $items->ts_cold_sn;
|
||||
$return_data[$i]->ordernumber = $items->ts_ordernumber;
|
||||
$return_data[$i]->status = $items->tst_status;
|
||||
$return_data[$i]->passengersename = $items->tst_realname;
|
||||
$return_data[$i]->passportseno = $items->tst_numberid;
|
||||
$i++;
|
||||
}
|
||||
print_r(json_encode($return_data));
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//用于自动发送确认信
|
||||
public function send_confirmmail(){
|
||||
//log_message('error','auto sendmail');
|
||||
$mailarr = $this->BIZ_train_model->auto_sendmail();
|
||||
foreach($mailarr as $obj){
|
||||
$coli_id = $this->BIZ_train_model->cold_sn_get_coli_id($obj->ts_cold_sn);
|
||||
$coli_id = $coli_id[0]->COLI_ID;
|
||||
$juhe_order = $obj->ts_ordernumber;
|
||||
$this->send_mail_to_guest($coli_id,$juhe_order);
|
||||
}
|
||||
}
|
||||
|
||||
//发邮件给客人
|
||||
function send_mail_to_guest($coli_id,$jh_order){
|
||||
$info = $this->BIZ_train_model->get_user_info($jh_order);
|
||||
$guest = $this->BIZ_train_model->get_guest_info($coli_id);
|
||||
//print_r($guest);
|
||||
$operator_info = $this->BIZ_train_model->get_operatorInfo($coli_id);
|
||||
$fromName = $operator_info[0]->Name;
|
||||
$fromEmail = $operator_info[0]->OPI_Email;
|
||||
$toName = $guest[0]->GUT_LastName.$guest[0]->GUT_FirstName;
|
||||
$toEmail = $guest[0]->GUT_Email;//
|
||||
$data['coli_id'] = $coli_id;
|
||||
$data['toname'] = $toName;
|
||||
$data['adult'] = $info->COLD_PersonNum;
|
||||
$data['chlid'] = $info->COLD_ChildNum;
|
||||
$data['baby'] = $info->COLD_BabyNum;
|
||||
$data['price'] = $this->BIZ_train_model->get_paypal($coli_id);
|
||||
$data['allpeople'] = $this->BIZ_train_model->biz_people($info->COLD_SN);
|
||||
$data['train_info'] = $this->BIZ_train_model->get_biz_foi($info->COLD_SN);
|
||||
$differtime = (strtotime($data['train_info'][0]->DepartureTime) - time()) / 3600;
|
||||
$obj = $this->BIZ_train_model->get_biz_jol_info($info->COLD_SN,$jh_order);
|
||||
$data['ordernumber'] = $obj->ts_elecnumber;
|
||||
$status = $obj->ts_status;
|
||||
$data['operator'] = $operator_info;
|
||||
$data['emailarr'] = explode(';',$operator_info[0]->Email);
|
||||
|
||||
$data['seatinfo'] = $obj->ts_seatsinfo;
|
||||
|
||||
if($status == '4' && $differtime > 0){
|
||||
$subject = "Got payment and issued train ticket(s), Order No $coli_id";
|
||||
$body = $this->load->view('email',$data,true);
|
||||
$this->send_mail_to_wl("订单:{$coli_id} 出票成功","翰特订单号:{$coli_id};聚合订单号:{$jh_order}",$coli_id);
|
||||
//发送邮件给客人
|
||||
$flag = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
$this->BIZ_train_model->update_biz_jol(array("ts_ordernumber"=>$jh_order),array("ts_sendmail"=>1,"ts_m_sn"=>$flag));
|
||||
}else if($status == '1'){
|
||||
$subject = "The train ticket(s) will be issued manually, Order No $coli_id";
|
||||
$body = $this->load->view('email_fault',$data,true);
|
||||
$this->send_mail_to_wl("订单:{$coli_id} 出票失败","翰特订单号:{$coli_id};聚合订单号:{$jh_order}",$coli_id);
|
||||
//测试阶段,将失败邮件发送一份给操作外联。
|
||||
$flag = $this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$fromName,$fromEmail,$subject,$body);
|
||||
//测试阶段,将失败邮件发送一份给操作外联。
|
||||
$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
$this->BIZ_train_model->update_biz_jol(array("ts_ordernumber"=>$jh_order),array("ts_sendmail"=>1,"ts_m_sn"=>$flag));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//发邮件给外联
|
||||
function send_mail_to_wl($subject,$body,$coli_id){
|
||||
$fromName = "cyc";
|
||||
$fromEmail = "cyc@hainatravel.com";
|
||||
//获取该订单的操作员的邮箱以及姓名
|
||||
$info = $this->BIZ_train_model->get_operatorInfo($coli_id);
|
||||
$toName = $info[0]->OPI_Name;
|
||||
$toEmail = $info[0]->OPI_Email;
|
||||
$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
}
|
||||
|
||||
//导出账单api
|
||||
public function export_excel(){
|
||||
set_time_limit(0);
|
||||
//创建跟踪号
|
||||
$trackcode = $this->BIZ_train_model->getTrackingCode();
|
||||
$from_date = $this->input->post("from_date");
|
||||
$to_date = $this->input->post("to_date");
|
||||
$examine = $this->input->post("examine");
|
||||
//$operator=$this->input->post("operator");
|
||||
|
||||
$reback=array();//返回的数据
|
||||
$reback["from_date"] = $from_date;
|
||||
$reback["to_date"] = $to_date;
|
||||
$reback["examine"] = $examine;
|
||||
$group = array();
|
||||
|
||||
if(!empty($from_date) && !empty($to_date)){
|
||||
$from_date = date("Y-m-d H:i",strtotime($from_date));
|
||||
$to_date = date("Y-m-d H:i",strtotime($to_date));
|
||||
$r = "";//聚合返回的数据
|
||||
$string_r = "";//输出
|
||||
$coli_id = "";
|
||||
$wl_name = "";
|
||||
$arr = array();//整合完成的数组,写进excel表的数据
|
||||
$url = JUHE_TRAIN_EXPORT_API;//请求的url
|
||||
$url .= "?key=".JUHE_TRAIN_API_KEY;
|
||||
$url .= "&since=".$from_date;
|
||||
$url .= "&before=".$to_date;
|
||||
$r = GetPost_http($url);
|
||||
$r = explode("\n",$r);
|
||||
//print_r($r);
|
||||
//die();
|
||||
for($i=1;$i<count($r)-1;$i++){
|
||||
$r_info=explode(",",$r[$i]);
|
||||
$juhe_order=substr($r_info[4], 1,strlen($r_info[4])-2);
|
||||
$obj = $this->BIZ_train_model->jh_order_get_coli_id($juhe_order);
|
||||
//print_r($obj);
|
||||
if(!empty($obj)){
|
||||
$coli_id = $obj[0]->COLI_ID;
|
||||
$coli_sn = $obj[0]->COLI_SN;
|
||||
}else{
|
||||
echo $juhe_order;
|
||||
}
|
||||
|
||||
$this->BIZ_train_model->linkTrackingCode($coli_sn,$trackcode);
|
||||
|
||||
/*if(empty($coli_sn) || empty($coli_sn)){
|
||||
print_r($juhe_order);
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
$flag = $this->BIZ_train_model->islink($coli_sn);
|
||||
if($flag){
|
||||
$this->BIZ_train_model->linkTrackingCode($coli_sn,$trackcode);
|
||||
}else{
|
||||
echo $coli_sn.'该订单还未关联财务表,不能导出账单。<br>';
|
||||
die();
|
||||
}
|
||||
*/
|
||||
//去掉数据两边的双引号
|
||||
$r_info[2]=substr($r_info[2], stripos($r_info[2],'"')+1,strrpos($r_info[2],'"')-1);
|
||||
$r_info[1]=substr($r_info[1], stripos($r_info[1],'"')+1,strrpos($r_info[1],'"')-1);
|
||||
$r_info[5]=substr($r_info[5], stripos($r_info[5],'"')+1,strrpos($r_info[5],'"')-1);
|
||||
$r_info[6]="";//储存团名
|
||||
$r_info[7] = "";//储存外联名
|
||||
$r_info[8] = "";//储存coli_id
|
||||
if($coli_id){
|
||||
$r_info[8] = $coli_id;
|
||||
$gri_no=$this->BIZ_train_model->get_gri_no($r_info[8]);//团名
|
||||
$wl_name = $this->BIZ_train_model->get_operatorInfo($r_info[8]);
|
||||
if($gri_no){
|
||||
$r_info[6] = $gri_no[0]->GRI_No;
|
||||
}
|
||||
if($wl_name){
|
||||
$r_info[7] = $wl_name[0]->OPI_Name;
|
||||
}
|
||||
}
|
||||
|
||||
//$r_info[3]=mb_convert_encoding($r_info[3],"utf-8","gbk");
|
||||
|
||||
if(is_numeric(mb_strpos($r_info[3],"充值"))){
|
||||
if(is_numeric(mb_strpos($r_info[3],"扣款"))){
|
||||
$r_info[3]="票款(有充值)";
|
||||
}
|
||||
if(is_numeric(mb_strpos($r_info[3],"扣手续费"))){
|
||||
$r_info[3]="手续费(有充值)";
|
||||
}
|
||||
if(is_numeric(mb_strpos($r_info[3],"线上退票成功"))){
|
||||
$r_info[3]="退票费(有充值)";
|
||||
}
|
||||
}
|
||||
if(is_numeric(mb_strpos($r_info[3],"扣款"))){
|
||||
$r_info[3]="票款";
|
||||
}
|
||||
if(is_numeric(mb_strpos($r_info[3],"扣手续费"))){
|
||||
$r_info[3]="手续费";
|
||||
}
|
||||
if(is_numeric(mb_strpos($r_info[3],"线上退票成功"))){
|
||||
$r_info[3]="退票费";
|
||||
}
|
||||
// $r_info[3]=mb_convert_encoding($r_info[3],"gbk","utf-8");
|
||||
$r_info['trackcode'] = $trackcode;
|
||||
$arr[]=$r_info;
|
||||
|
||||
/*
|
||||
//根据外联的名字创建数组来存储对应外联的订单信息
|
||||
if(!empty($r_info[7])){
|
||||
if(!isset($group[$r_info[7]])){
|
||||
$group[$r_info[7]] = array();
|
||||
}
|
||||
array_push($group[$r_info[7]],$r_info);
|
||||
}*/
|
||||
|
||||
}
|
||||
/*
|
||||
//将存储好的分组重新循环出来。
|
||||
foreach($group as $item){
|
||||
foreach ($item as $value){
|
||||
array_push($arr,$value);
|
||||
}
|
||||
}
|
||||
*/
|
||||
//die();
|
||||
if(empty($examine)){
|
||||
header("Content-type:application/vnd.ms-excel;charset=utf-8");
|
||||
header("Content-Disposition:attachment;filename=juhe_train.xls");
|
||||
$string_r= $this->load->view("train_transaction_excel",array("arr"=>$arr),TRUE);
|
||||
echo $string_r;die;
|
||||
}else{
|
||||
krsort($arr);//数组倒序
|
||||
$reback["data"]=$arr;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//登录验证
|
||||
public function check_login(){
|
||||
$code = $this->input->get('code');
|
||||
$signature = getDingSignature();
|
||||
$urlencode_signature = urlencode($signature);
|
||||
$personInfoUrl = 'https://oapi.dingtalk.com/sns/getuserinfo_bycode?signature='.$urlencode_signature.'×tamp='.time().'&accessKey=dingoaystremzlahfew1tb';
|
||||
$post_data = '{"tmp_auth_code":"'.$code.'"}';
|
||||
$returnJson = GetPost_http($personInfoUrl,$post_data,'json');
|
||||
$returnData = json_decode($returnJson);
|
||||
|
||||
if(!empty($returnData->user_info)){
|
||||
//创建session
|
||||
$this->session->set_userdata('dingname', $returnData->user_info->nick);
|
||||
$this->session->set_userdata('dingunionid', $returnData->user_info->unionid);
|
||||
redirect('http://www.mycht.cn/info.php/apps/trainsystem/pages/');
|
||||
}else{
|
||||
redirect('http://www.mycht.cn/info.php/apps/trainsystem/pages/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function check_session(){
|
||||
print_r($this->session->userdata('dingunionid'));
|
||||
}
|
||||
|
||||
//订单同步到trainsystem
|
||||
public function sync_orders(){
|
||||
die();
|
||||
//获取聚合订单
|
||||
$juhe_orders = $this->train_system_model->getallorders();
|
||||
|
||||
$add_data = new stdClass();
|
||||
foreach ($juhe_orders as $items){
|
||||
$add_data->ordernumber = $items->JOL_JuheOrder;
|
||||
$add_data->cold_sn = $items->JOL_COLD_SN;
|
||||
$add_data->status = $items->JOL_Status;
|
||||
$add_data->returncode = '';
|
||||
$add_data->errormsg = $items->JOL_RebackMsg;
|
||||
$add_data->checi = $items->JOL_TrainCode;
|
||||
$add_data->fromstationame = $items->JOL_FromStation;
|
||||
$add_data->fromstationcode = $items->JOL_FromStationCode;
|
||||
$add_data->tostationame = $items->JOL_ToStation;
|
||||
$add_data->tostationcode = $items->JOL_ToStationCode;
|
||||
|
||||
$trains = json_decode($items->JOL_BackTxt);
|
||||
//print_r($trains->passengers);
|
||||
if(isset($trains->train_date)){
|
||||
$add_data->startdate = $trains->train_date;
|
||||
}else{
|
||||
$add_data->startdate = '';
|
||||
}
|
||||
|
||||
foreach ($trains->passengers as $passengers){
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $items->JOL_JuheOrder;
|
||||
$data_passager->realname = $passengers->passengersename;
|
||||
$data_passager->identitytype = $passengers->passporttypeseidname;
|
||||
$data_passager->numberid = $passengers->passportseno;
|
||||
$data_passager->ticketype = $passengers->piaotypename;
|
||||
$data_passager->ticketprice = $passengers->price;
|
||||
$data_passager->seatype = $passengers->zwname;
|
||||
$data_passager->seatdetail = $passengers->cxin;
|
||||
$data_passager->status = $items->JOL_Status;
|
||||
//print_r($data_passager);
|
||||
$this->train_system_model->add_passagers($data_passager);
|
||||
}
|
||||
|
||||
$add_data->startime = '';
|
||||
$add_data->endtime = '';
|
||||
$add_data->runtime = '';
|
||||
|
||||
$add_data->channel = 'juhe';
|
||||
$add_data->isauto = $items->JOL_IsAuto;
|
||||
$this->train_system_model->add_orders($add_data);
|
||||
//print_r($add_data);
|
||||
}
|
||||
}
|
||||
|
||||
public function update_order(){
|
||||
$juhe_orders = $this->train_system_model->getallorders();
|
||||
foreach ($juhe_orders as $tickets_info){
|
||||
$ordernumber = $tickets_info->JOL_JuheOrder;
|
||||
$subtime = $tickets_info->JOL_SubTime;
|
||||
$price = $tickets_info->JOL_Price;
|
||||
$this->train_system_model->update_juheorder($ordernumber,$subtime,$price);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,320 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class callback extends CI_Controller{
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->helper('train');
|
||||
$this->load->model("train_system_model");
|
||||
$this->load->model("BIZ_train_model");
|
||||
}
|
||||
|
||||
public function juhecallback(){
|
||||
$data_post = $this->input->post();
|
||||
if(empty($data_post)){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"reason":"empty infos","status":"404"}');
|
||||
}
|
||||
|
||||
//调试代码
|
||||
/*$test_post = '{"data":"{\"from_station_name\":\"\u6b66\u6c49\",\"from_station_code\":\"WHN\",\"to_station_name\":\"\u897f\u5b89\u5317\",\"to_station_code\":\"EAY\",\"train_date\":\"2019-04-13\",\"orderid\":\"JH155317715892154\",\"user_orderid\":\"488123754\",\"orderamount\":\"1363.50\",\"ordernumber\":\"E946949845\",\"checi\":\"G856\",\"msg\":\"\u51fa\u7968\u6210\u529f\",\"status\":\"4\",\"passengers\":[{\"passengerid\":1,\"passengersename\":\"VENOSLEONARDA\",\"piaotype\":\"1\",\"piaotypename\":\"\u6210\u4eba\u7968\",\"passporttypeseid\":\"B\",\"passporttypeseidname\":\"\u62a4\u7167\",\"passportseno\":\"086925694\",\"price\":\"454.5\",\"zwcode\":\"O\",\"zwname\":\"\u4e8c\u7b49\u5ea7\",\"ticket_no\":\"E946949845102006A\",\"cxin\":\"02\u8f66\u53a2,06A\u5ea7\",\"reason\":0},{\"passengerid\":2,\"passengersename\":\"WAGENSTALLERSANDRA\",\"piaotype\":\"1\",\"piaotypename\":\"\u6210\u4eba\u7968\",\"passporttypeseid\":\"B\",\"passporttypeseidname\":\"\u62a4\u7167\",\"passportseno\":\"CF7NR17M7\",\"price\":\"454.5\",\"zwcode\":\"O\",\"zwname\":\"\u4e8c\u7b49\u5ea7\",\"ticket_no\":\"E946949845102006B\",\"cxin\":\"02\u8f66\u53a2,06B\u5ea7\",\"reason\":0},{\"passengerid\":3,\"passengersename\":\"WALDMANNSOPHIE\",\"piaotype\":\"1\",\"piaotypename\":\"\u6210\u4eba\u7968\",\"passporttypeseid\":\"B\",\"passporttypeseidname\":\"\u62a4\u7167\",\"passportseno\":\"CF26Y6FVK\",\"price\":\"454.5\",\"zwcode\":\"O\",\"zwname\":\"\u4e8c\u7b49\u5ea7\",\"ticket_no\":\"E946949845102006C\",\"cxin\":\"02\u8f66\u53a2,06C\u5ea7\",\"reason\":0}],\"refund_money\":null,\"sign\":\"f74013fa24115eeb9a807aa237054920\"}"}';
|
||||
|
||||
$data_post["data"] = json_decode($test_post)->data;*/
|
||||
|
||||
log_message('error','聚合回调:'.json_encode($data_post));
|
||||
$data = json_decode($data_post["data"]);
|
||||
|
||||
$update_data = new StdClass();
|
||||
$update_data->OrderStatus = $data->status;
|
||||
$update_data->ordernumber = $data->orderid;
|
||||
$update_data->OrderTotleFee = $data->orderamount;
|
||||
$update_data->seatsinfo = '';
|
||||
$update_data->TicketCheck = '';
|
||||
$update_data->bookcallback = '';
|
||||
$update_data->confirmcallback = '';
|
||||
$update_data->returncallback = '';
|
||||
$update_data->ElectronicOrderNumber = $data->ordernumber;
|
||||
$update_data->reschedulecallback = '';
|
||||
$update_data->ErrorMsg = $data->msg;
|
||||
|
||||
//如果返回2则发送出票请求
|
||||
if($data->status == "1"){
|
||||
$update_data->bookcallback = $data_post["data"];
|
||||
}elseif($data->status == "2"){
|
||||
$coach = array();
|
||||
$seats = array();
|
||||
$string = '';
|
||||
$passagers = $data->passengers;
|
||||
foreach($passagers as $item){
|
||||
foreach(explode(',',$item->cxin) as $item_seat){
|
||||
if(strpos($item_seat,'车厢')){
|
||||
$item_seat = str_replace('车厢','',$item_seat);
|
||||
array_push($coach,$item_seat);
|
||||
}else{
|
||||
$find = array('座上铺','座中铺','座下铺','座');
|
||||
$replace = array(' upper',' middle',' lower','');
|
||||
$item_seat = str_replace($find,$replace,$item_seat);
|
||||
array_push($seats,$item_seat);
|
||||
}
|
||||
}
|
||||
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $data->orderid;
|
||||
$data_passager->realname = $item->passengersename;
|
||||
$data_passager->identitytype = $item->passporttypeseidname;
|
||||
$data_passager->numberid = $item->passportseno;
|
||||
$data_passager->ticketype = $item->piaotypename;
|
||||
$data_passager->ticketprice = $item->price;
|
||||
$data_passager->seatype = $item->zwname;
|
||||
$data_passager->seatdetail = $item->cxin;
|
||||
$data_passager->status = '4';
|
||||
$this->train_system_model->add_passagers($data_passager);
|
||||
}
|
||||
|
||||
//判断车厢是否唯一,如果不唯一的话,分成两个车厢
|
||||
if(count(array_unique($coach)) == 1){
|
||||
$onlycoach = array_unique($coach);
|
||||
$string .= 'Coach '.$onlycoach[0].',';
|
||||
}else{
|
||||
foreach (array_unique($coach) as $item_coach){
|
||||
$string .= 'Coach '.$item_coach.',';
|
||||
}
|
||||
}
|
||||
|
||||
$string .= 'Seat ';
|
||||
foreach($seats as $item_seat){
|
||||
$string .= $item_seat.',';
|
||||
}
|
||||
|
||||
$seatinfo = substr($string,0,strlen($string)-1);
|
||||
$update_data->seatsinfo = $seatinfo;
|
||||
|
||||
$post_data = array(
|
||||
"key"=>JUHE_TRAIN_API_KEY,
|
||||
"orderid"=>$data->orderid
|
||||
);
|
||||
$back_json = GetPost_http(JUHE_TRAIN_PAY_API,$post_data);
|
||||
$update_data->bookcallback = $data_post["data"];
|
||||
}elseif($data->status == "4"){
|
||||
$add_train_order_data->TOC_Memo = $data->orderid." 聚合出票";
|
||||
$add_train_order_data->TOC_COLD_SN = $data->user_orderid;
|
||||
$add_train_order_data->TOC_TrainNumber = $data->checi;
|
||||
$add_train_order_data->TOC_DepartureDate = $data->train_date;
|
||||
$add_train_order_data->TOC_TicketCost = $data->orderamount;
|
||||
$add_train_order_data->poundage = (count($data->passengers)*2)."";//手续费,每人两块,转换成字符串
|
||||
$add_train_order_data->FOI_TrainNetOrderNo = $data->ordernumber;
|
||||
$this->BIZ_train_model->add_train_payment($add_train_order_data);
|
||||
|
||||
$update_data->confirmcallback = $data_post["data"];
|
||||
$this->BIZ_train_model->update_cold_planvei_sn($data->user_orderid);
|
||||
}elseif($data->status=="7"){
|
||||
//退票成功 写入TOC表
|
||||
$newtime = "";//记录最新操作时间
|
||||
$refund_passportseno = "";//退票人护照号
|
||||
$refund_money = "";//退票金额
|
||||
foreach ($data->passengers as $p) {
|
||||
if(isset($p->returntickets)){
|
||||
$refund_passportseno = $p->refundTimeline[count($p->refundTimeline)-1]->detail->passportseno;
|
||||
$refund_money = $p->refundTimeline[count($p->refundTimeline)-1]->detail->returnmoney;
|
||||
//退票时还需要单独对对每个乘客存储回调信息
|
||||
$passpager_info = new stdClass();
|
||||
$passpager_info->returncallback = $data_post["data"];
|
||||
$passpager_info->status = '7';
|
||||
$passpager_info->ordernumber = $data->orderid;
|
||||
$passpager_info->realname = $p->refundTimeline[count($p->refundTimeline)-1]->detail->passengername;
|
||||
$passpager_info->numberid = $refund_passportseno;
|
||||
print_r($passpager_info);
|
||||
$this->train_system_model->update_passpager_info($passpager_info);
|
||||
|
||||
//添加退款记录
|
||||
$add_train_order_data->TOC_COLD_SN = $data->user_orderid;
|
||||
$add_train_order_data->TOC_Memo = $data->orderid." ".$refund_passportseno;
|
||||
$add_train_order_data->ordernumber = $data->user_orderid;
|
||||
$add_train_order_data->TOC_TrainNumber = $data->checi;
|
||||
$add_train_order_data->TOC_DepartureDate = $data->train_date;
|
||||
$add_train_order_data->TOC_TicketCost = -$refund_money;
|
||||
$add_train_order_data->FOI_TrainNetOrderNo = null;//退票不用更新取票号,以此在模型里面判断是否为退票消息
|
||||
|
||||
$this->BIZ_train_model->add_train_payment($add_train_order_data);
|
||||
}else{
|
||||
//有可能提交了退票或者还没有退票
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$update_data->returncallback = $data_post["data"];
|
||||
}
|
||||
//print_r($update_data);die();
|
||||
//更新订单信息(出票系统)
|
||||
$this->train_system_model->update_orders($update_data);
|
||||
}
|
||||
|
||||
public function ctripcallback(){
|
||||
$back_json = file_get_contents('php://input');
|
||||
log_message('error','携程回调信息:'.$back_json);
|
||||
/*$back_json = '{"Authentication":{"ServiceName":"web.order.returnTicketNotice","PartnerName":"tieyou","TimeStamp":"2019-1-18 11:35:22","MessageIdentity":"93F2BA3253829E8FAD29B5DEB7646A59"},"TrainOrderService":{"contactName":{},"contactMobile":{},"OrderNumber":"guilintravel1547778269","refundTicket":{"childBillId":{},"orderId":"8360041214","eOrderNumber":"EB59937931","eOrderType":"1","seatNumber":"01D\u53f7","passport":"544712454","passportName":"YANGFRANCISCHENG","realName":"YANGFRANCISCHENG","status":"1","reason":"\u9000\u7968\u6210\u529f\uff0c\u9000\u6b3e\u91d1\u989d:218.50\u5143"}}}';*/
|
||||
$ctrip_backdata = json_decode($back_json);
|
||||
//print_r($ctrip_backdata);
|
||||
if(!empty($ctrip_backdata)){
|
||||
$update_data = new stdClass();
|
||||
$update_data->ServiceName = $ctrip_backdata->Authentication->ServiceName;
|
||||
$update_data->ordernumber = '';
|
||||
$update_data->seatsinfo = '';
|
||||
$update_data->TicketCheck = '';
|
||||
$update_data->bookcallback = '';
|
||||
$update_data->confirmcallback = '';
|
||||
$update_data->returncallback = '';
|
||||
$update_data->OrderTotleFee = 0;
|
||||
$update_data->ElectronicOrderNumber = '';
|
||||
$update_data->reschedulecallback = '';
|
||||
|
||||
if($update_data->ServiceName == 'web.order.notifyTicket'){
|
||||
$update_data->OrderStatus = '4';
|
||||
$update_data->ErrorMsg = '出票成功';
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$update_data->OrderTotleFee = $ctrip_backdata->TrainOrderService->OrderInfo->OrderTotleFee;
|
||||
$update_data->ElectronicOrderNumber = $ctrip_backdata->TrainOrderService->OrderInfo->ElectronicOrderNumber;
|
||||
|
||||
//新添加检票口信息
|
||||
if(isset($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck)){
|
||||
if(!is_object($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck)){
|
||||
$update_data->TicketCheck = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->TicketCheck;
|
||||
}
|
||||
}
|
||||
|
||||
//获取总票数,由于携程接口单人和多人返回的数据结构不一致
|
||||
$person_num = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketCount;
|
||||
|
||||
//存储座位信息 转换为英文
|
||||
$coach_arr = array();
|
||||
$seats_arr = array();
|
||||
$data_passager = new stdClass();
|
||||
$string = '';
|
||||
$i = 0;
|
||||
if($person_num > 1){
|
||||
foreach ($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo as $items){
|
||||
if(strpos($items->SeatNo,'车厢')){
|
||||
$coach = mb_substr($items->SeatNo,0,strpos($items->SeatNo,'车厢'));
|
||||
array_push($coach_arr,$coach);
|
||||
$seat = mb_substr($items->SeatNo,strpos($items->SeatNo,'车厢')+2,mb_strlen($items->SeatNo,'UTF8'));
|
||||
$find = array('号');
|
||||
$replace = array('');
|
||||
$seat = str_replace($find,$replace,$seat);
|
||||
array_push($seats_arr,$seat);
|
||||
}
|
||||
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$data_passager->realname = $items->PassengerName;
|
||||
$data_passager->identitytype = $items->IdentityType;
|
||||
$data_passager->numberid = $items->NumberID;
|
||||
$data_passager->ticketype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketType;
|
||||
$data_passager->ticketprice = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketPrice;
|
||||
$data_passager->seatype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketSeat;
|
||||
$data_passager->seatdetail = $items->SeatNo;
|
||||
$this->train_system_model->add_passagers($data_passager);
|
||||
$i++;
|
||||
}
|
||||
|
||||
}else{
|
||||
$seatinfo_html = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->SeatNo;
|
||||
if(strpos($seatinfo_html,'车厢')){
|
||||
$coach = mb_substr($seatinfo_html,0,strpos($seatinfo_html,'车厢'));
|
||||
array_push($coach_arr,$coach);
|
||||
$seat = mb_substr($seatinfo_html,strpos($seatinfo_html,'车厢')+2,mb_strlen($seatinfo_html,'UTF8'));
|
||||
$find = array('号');
|
||||
$replace = array('');
|
||||
$seat = str_replace($find,$replace,$seat);
|
||||
array_push($seats_arr,$seat);
|
||||
}
|
||||
|
||||
//对订票乘客进行存储
|
||||
$data_passager->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$data_passager->realname = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->PassengerName;
|
||||
$data_passager->identitytype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->IdentityType;
|
||||
$data_passager->numberid = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->NumberID;
|
||||
$data_passager->ticketype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->TicketType;
|
||||
$data_passager->ticketprice = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketPrice;
|
||||
$data_passager->seatype = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->OrderTicketSeat;
|
||||
$data_passager->seatdetail = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfoFinal->Tickets->Ticket->DetailInfos->DetailInfo->SeatNo;
|
||||
$this->train_system_model->add_passagers($data_passager);
|
||||
}
|
||||
|
||||
if(count(array_unique($coach_arr)) == 1){
|
||||
$onlycoach = array_unique($coach_arr);
|
||||
$update_data->seatsinfo .= 'Coach '.$onlycoach[0].',';
|
||||
}else{
|
||||
foreach (array_unique($coach_arr) as $item_coach){
|
||||
$update_data->seatsinfo .= 'Coach '.$item_coach.',';
|
||||
}
|
||||
}
|
||||
|
||||
$update_data->seatsinfo .= 'Seat ';
|
||||
foreach($seats_arr as $item_seat){
|
||||
$update_data->seatsinfo .= $item_seat.',';
|
||||
}
|
||||
|
||||
$update_data->seatsinfo = substr($update_data->seatsinfo,0,strlen($update_data->seatsinfo)-1);
|
||||
|
||||
$update_data->bookcallback = $back_json;
|
||||
|
||||
//添加支付记录
|
||||
$add_train_payment_data->TOC_Memo = $update_data->ordernumber;
|
||||
//根据订单号获取cold_sn
|
||||
$order_info = $this->train_system_model->get_order_info($update_data->ordernumber);
|
||||
$cold_sn = $order_info->ts_cold_sn;
|
||||
$add_train_payment_data->TOC_COLD_SN = $cold_sn;
|
||||
$add_train_payment_data->TOC_TrainNumber = $ctrip_backdata->TrainOrderService->OrderInfo->TicketInfo->OrderTicketCheci;
|
||||
$add_train_payment_data->TOC_DepartureDate = date('Y-m-d',strtotime($ctrip_backdata->TrainOrderService->OrderInfo->TicketInfo->OrderTicketYMD));
|
||||
$add_train_payment_data->TOC_TicketCost = $update_data->OrderTotleFee;
|
||||
$add_train_payment_data->poundage = ($person_num*5)."";//手续费,每人五块,转换成字符串
|
||||
$add_train_payment_data->FOI_TrainNetOrderNo = $update_data->ElectronicOrderNumber;
|
||||
//print_r($add_train_order_data);die();
|
||||
$this->BIZ_train_model->add_train_payment($add_train_payment_data);
|
||||
//记录供应商(瀚特)
|
||||
$this->BIZ_train_model->update_cold_planvei_sn($cold_sn);
|
||||
}else if($update_data->ServiceName == 'web.order.notifyNoTicket'){
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$update_data->OrderStatus = '1';
|
||||
$update_data->ErrorMsg = $ctrip_backdata->TrainOrderService->OrderInfo->NoTicketReasons;
|
||||
$update_data->confirmcallback = $back_json;
|
||||
}else if($update_data->ServiceName == 'web.order.returnTicketNotice'){
|
||||
$update_data->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
|
||||
$update_data->OrderStatus = '7';
|
||||
$update_data->ErrorMsg = $ctrip_backdata->TrainOrderService->refundTicket->reason;
|
||||
$update_data->returncallback = $back_json;
|
||||
|
||||
//退票时还需要单独对对每个乘客存储回调信息
|
||||
$passpager_info = new stdClass();
|
||||
$passpager_info->returncallback = $back_json;
|
||||
$passpager_info->status = '7';
|
||||
$passpager_info->ordernumber = $ctrip_backdata->TrainOrderService->OrderNumber;
|
||||
$passpager_info->realname = $ctrip_backdata->TrainOrderService->refundTicket->realName;
|
||||
$passpager_info->numberid = $ctrip_backdata->TrainOrderService->refundTicket->passport;
|
||||
$this->train_system_model->update_passpager_info($passpager_info);
|
||||
}else if($update_data->ServiceName == 'web.order.requestRefund'){
|
||||
$return_order = $ctrip_backdata->TrainOrderService->OrderInfo->OrderNumber;
|
||||
$return_money = $ctrip_backdata->TrainOrderService->TotalRefundAmount;
|
||||
|
||||
//根据订单号获取cold_sn
|
||||
$order_info = $this->train_system_model->get_order_info($return_order);
|
||||
$cold_sn = $order_info->ts_cold_sn;
|
||||
//print_r($order_info);
|
||||
|
||||
$add_train_payment_data->TOC_Memo = $return_order.'_'.$ctrip_backdata->TrainOrderService->OrderInfo->OrderTid;
|
||||
$add_train_payment_data->TOC_COLD_SN = $cold_sn;
|
||||
$add_train_payment_data->TOC_TrainNumber = $order_info->ts_checi;
|
||||
$add_train_payment_data->TOC_DepartureDate = $order_info->ts_startdate;
|
||||
$add_train_payment_data->TOC_TicketCost = -$ctrip_backdata->TrainOrderService->TotalRefundAmount;
|
||||
$add_train_payment_data->FOI_TrainNetOrderNo=null;
|
||||
//print_r($add_train_payment_data);die();
|
||||
$this->BIZ_train_model->add_train_payment($add_train_payment_data);
|
||||
return false;
|
||||
}
|
||||
|
||||
//更新订单信息(出票系统)
|
||||
$this->train_system_model->update_orders($update_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class orders extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
public function index(){
|
||||
echo 'orders manager';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class pages extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->model("train_system_model");
|
||||
$this->load->model("BIZ_train_model");
|
||||
$this->load->helper('train');
|
||||
$this->order_status_msg = $this->config->item('train_order_status_msg');
|
||||
}
|
||||
|
||||
public function index($coli_id = null){
|
||||
if($this->session->userdata('dingname') == '' && $this->session->userdata('dingunionid') == ''){
|
||||
dingLogin();
|
||||
}
|
||||
if($coli_id == null){
|
||||
$cols_id = $this->input->post("ht_order");
|
||||
}else{
|
||||
$cols_id = $coli_id;
|
||||
}
|
||||
|
||||
$list=new StdClass;
|
||||
if(!empty($cols_id)){
|
||||
$cold_sn = $this->BIZ_train_model->get_biz_cold($cols_id);
|
||||
$list->wl = $this->BIZ_train_model->get_operatorInfo($cols_id);
|
||||
$i=0;
|
||||
$list->info=array();
|
||||
foreach ($cold_sn as $v) {
|
||||
$list->info[$i] = new StdClass;
|
||||
$list->info[$i]->people = $this->BIZ_train_model->biz_people($v->COLD_SN);
|
||||
$list->info[$i]->train = $this->BIZ_train_model->get_biz_foi($v->COLD_SN);
|
||||
$list->info[$i]->status = $this->BIZ_train_model->get_biz_jol($v->COLD_SN);
|
||||
$i++;
|
||||
}
|
||||
$list->cols_id=$cols_id;
|
||||
}
|
||||
|
||||
//查询聚合余额
|
||||
$back_data = GetPost_http("http://op.juhe.cn/trainTickets/balance.php?key=79f03107b921ef31310bd40a1415c1cb");
|
||||
$back_data = json_decode($back_data);
|
||||
if(!empty($back_data->result)){
|
||||
$list->balance = $back_data->result;
|
||||
}else{
|
||||
$list->balance = "NULL";
|
||||
}
|
||||
//print_r($list);
|
||||
$this->load->view('common/header');
|
||||
$this->load->view('homepage',$list);
|
||||
$this->load->view('common/footer');
|
||||
}
|
||||
|
||||
//系统列表页面
|
||||
public function order_list(){
|
||||
if($this->session->userdata('dingname') == '' && $this->session->userdata('dingunionid') == ''){
|
||||
dingLogin();
|
||||
}
|
||||
$page_size = 10;
|
||||
$page = $this->input->get("page");
|
||||
$order = $this->input->get("order");
|
||||
$web_code = $this->input->get("web_code");
|
||||
$where = "1=1";//搜索条件
|
||||
$page_parameter = "";//返回的分页条件参数
|
||||
if(empty($page) or !is_numeric($page)){
|
||||
$page=0;
|
||||
}
|
||||
if(!empty($order)){
|
||||
$where = "BIZ_ConfirmLineInfo.COLI_ID='{$order}' OR InfoManager.dbo.trainsystem.ts_ordernumber='{$order}'";
|
||||
//$where2 = "where BIZ_ConfirmLineInfo.COLI_ID='{$order}' OR JOL_JuheOrder='{$order}'";
|
||||
$list["order"] = $order;
|
||||
$page_parameter = "order=".$order;
|
||||
}
|
||||
if(!empty($web_code)){
|
||||
$where = "BIZ_ConfirmLineInfo.COLI_WebCode='{$web_code}'";
|
||||
$page_parameter = "web_code=".$web_code;
|
||||
}
|
||||
|
||||
//获取订单数据
|
||||
$data = $this->train_system_model->get_order($page_size,$page,$where);
|
||||
//print_r($data);die();
|
||||
$list["data"]=$data->list;
|
||||
|
||||
$this->load->library('pagination');
|
||||
|
||||
$config['base_url'] = site_url("/apps/trainsystem/pages/order_list?{$page_parameter}");
|
||||
$config['total_rows'] = $data->count;
|
||||
$config['per_page'] = $page_size;
|
||||
$config['page_query_string']=TRUE;
|
||||
$config['query_string_segment']="page";
|
||||
$config['cur_tag_open'] = '<li class="active"><a href="#">';
|
||||
$config['cur_tag_close'] = '</a></li>';
|
||||
$config['first_tag_open']=$config['last_tag_open']=$config['next_tag_open']=$config['prev_tag_open']=$config['num_tag_open']="<li>";
|
||||
$config['first_tag_close']=$config['last_tag_close']=$config['next_tag_close']=$config['prev_tag_close']=$config['num_tag_close']="</li>";
|
||||
|
||||
$this->pagination->initialize($config);
|
||||
|
||||
$list["page_link"]=$this->pagination->create_links();
|
||||
|
||||
foreach ($list["data"] as $key => $value) {
|
||||
$value->info = $this->order_status_msg[$value->ts_status];//自定义说明信息;
|
||||
}
|
||||
|
||||
|
||||
$this->load->view('header');
|
||||
$this->load->view('order_list',$list);
|
||||
$this->load->view('footer');
|
||||
}
|
||||
|
||||
//订单详情页面
|
||||
public function order(){
|
||||
if($this->session->userdata('dingname') == '' && $this->session->userdata('dingunionid') == ''){
|
||||
dingLogin();
|
||||
}
|
||||
$ordernumber = $order=$this->input->get("order");
|
||||
|
||||
if(empty($ordernumber)){
|
||||
exit('参数错误');
|
||||
}
|
||||
|
||||
//根据订单号查询订单信息
|
||||
$data = array();
|
||||
$train_infos = $this->train_system_model->get_train_infos($ordernumber);
|
||||
$passpager_detail = $this->train_system_model->get_passager_details($ordernumber);
|
||||
|
||||
//构造详情数组
|
||||
$data['status'] = $train_infos->ts_status;
|
||||
$data['ordernumber'] = $train_infos->ts_ordernumber;
|
||||
$data['train_date'] = $train_infos->ts_startdate;
|
||||
$data['checi'] = $train_infos->ts_checi;
|
||||
$data['elecnumber'] = $train_infos->ts_elecnumber;
|
||||
$data['from_station_name'] = $train_infos->ts_fromstationame;
|
||||
$data['from_station_code'] = $train_infos->ts_fromstationcode;
|
||||
$data['to_station_name'] = $train_infos->ts_tostationame;
|
||||
$data['to_station_code'] = $train_infos->ts_tostationcode;
|
||||
$data['start_time'] = $train_infos->ts_startime;
|
||||
$data['arrive_time'] = $train_infos->ts_endtime;
|
||||
$data['channel'] = $train_infos->ts_channel;
|
||||
$data['msg'] = $train_infos->ts_errormsg;
|
||||
$data['passengers'] = $passpager_detail;
|
||||
|
||||
//聚合订单可以查询实时数据
|
||||
if($train_infos->ts_channel == 'juhe'){
|
||||
$post_data=array(
|
||||
"key"=>"79f03107b921ef31310bd40a1415c1cb",
|
||||
"orderid"=>$train_infos->ts_ordernumber
|
||||
);
|
||||
$back_data = GetPost_http("http://op.juhe.cn/trainTickets/orderStatus",$post_data);
|
||||
$data['train_date'] = '';
|
||||
$data['start_time'] = json_decode($back_data)->result->start_time;
|
||||
$data['arrive_time'] = json_decode($back_data)->result->arrive_time;
|
||||
}
|
||||
|
||||
$this->load->view('bootstrap3/header');
|
||||
$this->load->view('order',$data);
|
||||
$this->load->view('bootstrap3/footer');
|
||||
}
|
||||
|
||||
//退票页面
|
||||
public function refund(){
|
||||
if($this->session->userdata('dingname') == '' && $this->session->userdata('dingunionid') == ''){
|
||||
dingLogin();
|
||||
}
|
||||
$ordernumber = $order=$this->input->get("order");
|
||||
|
||||
if(empty($ordernumber)){
|
||||
exit('参数错误');
|
||||
}
|
||||
|
||||
//根据订单号查询订单信息
|
||||
$data = array();
|
||||
$train_infos = $this->train_system_model->get_train_infos($ordernumber);
|
||||
$passpager_detail = $this->train_system_model->get_passager_details($ordernumber);
|
||||
|
||||
//构造详情数组
|
||||
$data['ordernumber'] = $train_infos->ts_ordernumber;
|
||||
$data['cold_sn'] = $train_infos->ts_cold_sn;
|
||||
$data['train_date'] = $train_infos->ts_startdate;
|
||||
$data['checi'] = $train_infos->ts_checi;
|
||||
$data['elecnumber'] = $train_infos->ts_elecnumber;
|
||||
$data['from_station_name'] = $train_infos->ts_fromstationame;
|
||||
$data['from_station_code'] = $train_infos->ts_fromstationcode;
|
||||
$data['to_station_name'] = $train_infos->ts_tostationame;
|
||||
$data['to_station_code'] = $train_infos->ts_tostationcode;
|
||||
$data['start_time'] = $train_infos->ts_startime;
|
||||
$data['arrive_time'] = $train_infos->ts_endtime;
|
||||
$data['channel'] = $train_infos->ts_channel;
|
||||
$data['msg'] = $train_infos->ts_errormsg;
|
||||
$data['return_json'] = $train_infos->ts_returncallback;
|
||||
$data['passengers'] = $passpager_detail;
|
||||
|
||||
//print_r($data);
|
||||
$this->load->view('header');
|
||||
$this->load->view('refund',$data);
|
||||
$this->load->view('footer');
|
||||
|
||||
}
|
||||
|
||||
public function export(){
|
||||
if($this->session->userdata('dingname') == '' && $this->session->userdata('dingunionid') == ''){
|
||||
dingLogin();
|
||||
}
|
||||
$this->load->view('header');
|
||||
$this->load->view('export');
|
||||
$this->load->view('footer');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,186 @@
|
||||
<?php
|
||||
if (!defined('BASEPATH'))
|
||||
exit('No direct script access allowed');
|
||||
|
||||
class returnorders extends CI_Controller{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
$this->load->helper('train');
|
||||
$this->load->model("train_system_model");
|
||||
$this->load->model("Sendmail_model");
|
||||
$this->load->model('BIZ_train_model');
|
||||
$this->usercenter = 'yes';
|
||||
}
|
||||
|
||||
public function index(){
|
||||
echo 'return tickets';
|
||||
}
|
||||
|
||||
public function returntickets(){
|
||||
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');
|
||||
//第三方订单号(为了避免一个子订单乘客分开出票而产生错误)
|
||||
$ordernumber = $this->input->get_post('ordernumber');
|
||||
//护照姓名
|
||||
$passportname = $this->input->get_post('passportname');
|
||||
//护照号
|
||||
$passportno = $this->input->get_post('passportno');
|
||||
//判断是否为用户中心操作
|
||||
$this->usercenter = $this->input->get_post('usercenter');
|
||||
|
||||
if(!$ordernumber || !$passportname || !$passportno){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"reason":"传参错误","status":"404"}');
|
||||
}
|
||||
|
||||
//网前提交的姓名没有做处理
|
||||
$passportname = chk_sp_name($passportname);
|
||||
|
||||
$ticket_data = $this->train_system_model->ticketfrom($ordernumber);
|
||||
$passenger_data = $this->train_system_model->get_passenger_info($ordernumber,$passportname,$passportno);
|
||||
|
||||
if(empty($passenger_data)){
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
exit('{"reason":"乘客信息为空无法退票","status":"404"}');
|
||||
exit('');
|
||||
}
|
||||
|
||||
$channel = $ticket_data->ts_channel;
|
||||
|
||||
switch ($channel){
|
||||
case 'juhe':
|
||||
$this->juheModel($ticket_data,$passenger_data);
|
||||
break;
|
||||
case 'ctrip':
|
||||
$this->ctripModel($ticket_data,$passenger_data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function juheModel($ticket_data,$data){
|
||||
$post_data = array(
|
||||
"key"=>JUHE_TRAIN_API_KEY,
|
||||
"orderid"=>$ticket_data->ts_ordernumber
|
||||
);
|
||||
$back_json = GetPost_http(JUHE_TRAIN_STATUS_API,$post_data);
|
||||
$back_detail_data = json_decode($back_json);
|
||||
//print_r($back_data);die();
|
||||
foreach($back_detail_data->result->passengers as $items){
|
||||
if($items->passengersename == $data->tst_realname && $items->passportseno == $data->tst_numberid){
|
||||
$ticket_no = $items->ticket_no;
|
||||
}
|
||||
}
|
||||
//发起退票
|
||||
$post_data1 = array(
|
||||
"key"=>JUHE_TRAIN_API_KEY,
|
||||
"orderid"=>$ticket_data->ts_ordernumber,
|
||||
"tickets"=>'[{"ticket_no":"'.$ticket_no.'","passengername":"'.$data->tst_realname.'","passporttypeseid":"'.strexchangeid($data->tst_ticketype).'","passportseno":"'.$data->tst_numberid.'"}]',
|
||||
);
|
||||
//print_r($post_data1);die();
|
||||
$back_json = GetPost_http(JUHE_TRAIN_REFUND_API,$post_data1);
|
||||
//print_r($post_data1);
|
||||
|
||||
log_message('error','聚合退票:'.$ticket_data->ts_ordernumber.'|'.$back_json);
|
||||
$back_data = json_decode($back_json);
|
||||
|
||||
$fromName = 'trainsystem';
|
||||
$fromEmail = 'cyc@hainatravel.com';
|
||||
$coli_id = $this->BIZ_train_model->cold_sn_get_coli_id($ticket_data->ts_cold_sn);
|
||||
$coli_id = $coli_id['0']->COLI_ID;
|
||||
$info = $this->BIZ_train_model->get_operatorInfo($coli_id);
|
||||
$toName = $info[0]->Name;
|
||||
$toEmail = $info[0]->OPI_Email;
|
||||
$Mobile = $info[0]->Mobile;
|
||||
$subject = '退票请求';
|
||||
if($back_data->error_code == '0'){
|
||||
//退票成功后发送邮件
|
||||
$body = $back_detail_data->result->ordernumber.' 提出退票,乘客:'.$data->tst_realname.', '.$back_detail_data->result->start_time.' '.$back_detail_data->result->checi;
|
||||
//发送邮件给外联
|
||||
$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
if($this->usercenter == 'yes'){
|
||||
//发送邮件给客人
|
||||
$customer_subject = 'China Train Ticket(s) Cancelation';
|
||||
$customer_body = '<p>Dear '.$data->tst_realname.',</p><p>Your tickets (ticket number '.$back_detail_data->result->ordernumber.', for name '.$data->tst_realname.', train No. '.$back_detail_data->result->checi.') have been cancelled online successfully. Your travel advisor ('.$toName.', email address: '.$toEmail.', phone number '.$Mobile.') will contact you with the refund details via email within 24 hours.';
|
||||
$customer_email = $this->BIZ_train_model->get_guest_info($coli_id);
|
||||
$customer_email = $customer_email[0]->GUT_Email;
|
||||
$this->Sendmail_model->SendMailToTable($toName,$toEmail,$data->tst_realname,$customer_email,$customer_subject,$customer_body);
|
||||
}
|
||||
echo '{"reason":"退票成功","status":"200"}';
|
||||
}else{
|
||||
//退票失败后发送邮件
|
||||
$body = $ticket_data->ts_ordernumber.'退票失败';
|
||||
//发送邮件给外联
|
||||
$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
if($this->usercenter == 'yes'){
|
||||
//发送邮件给客人
|
||||
$customer_subject = 'China Train Ticket(s) Cancelation';
|
||||
$customer_body = '<p>Dear '.$data->tst_realname.',</p><p>Your application for online ticket cancellation (ticket number '.$back_detail_data->result->ordernumber.', for name '.$data->tst_realname.', train No.'.$back_detail_data->result->checi.') has failed.Your travel advisor('.$toName.', email address: '.$toEmail.', phone number '.$Mobile.') will contact you via email within 24 hours. Please call us if you need to contact us urgently.</p>';
|
||||
$customer_email = $this->BIZ_train_model->get_guest_info($coli_id);
|
||||
$customer_email = $customer_email[0]->GUT_Email;
|
||||
$this->Sendmail_model->SendMailToTable($toName,$toEmail,$data->tst_realname,$customer_email,$customer_subject,$customer_body);
|
||||
}
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
echo '{"reason":"退票失败","status":"404"}';
|
||||
}
|
||||
}
|
||||
|
||||
function ctripModel($ticket_data,$passenger_data){
|
||||
$PostData = array();
|
||||
$TimeStamp = time();
|
||||
$time = date('Y-m-d H:i:s',$TimeStamp);
|
||||
$PostData['Authentication']->TimeStamp = $time;
|
||||
$PostData['Authentication']->ServiceName = 'order.ticketReturn';
|
||||
$PostData['Authentication']->PartnerName = ORDERUSER;
|
||||
$MessageIdentity = md5($time.'order.ticketReturn'.ORDERKEY);
|
||||
$PostData['Authentication']->MessageIdentity = $MessageIdentity;
|
||||
|
||||
$PostData['TrainOrderService']->contactName = '陈宇超';
|
||||
$PostData['TrainOrderService']->contactMobile = '18877381547';
|
||||
$PostData['TrainOrderService']->OrderNumber = $ticket_data->ts_ordernumber;
|
||||
$PostData['TrainOrderService']->OperatorType = '0';
|
||||
$PostData['TrainOrderService']->TicketInfo = '';
|
||||
$PostData['TrainOrderService']->TicketInfo = array();
|
||||
|
||||
$i = 0;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderNumber'] = $passenger_data->ts_elecnumber;
|
||||
if($passenger_data->tst_ticketype == '儿童票'){
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderType'] = '2';
|
||||
}else{
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['eOrderType'] = '1';
|
||||
}
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['seatNumber'] = $passenger_data->tst_seatdetail;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['passportName'] = $passenger_data->tst_realname;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['passport'] = $passenger_data->tst_numberid;
|
||||
$PostData['TrainOrderService']->TicketInfo[$i]['realName'] = $passenger_data->tst_realname;
|
||||
|
||||
//发起退票请求
|
||||
$Url = 'http://m.ctrip.com/restapi/soa2/11009/json/PartnerReturnTicket';
|
||||
$ResponseJson = GetPost_http($Url,json_encode($PostData),'POST');
|
||||
$ResponseData = json_decode($ResponseJson);
|
||||
|
||||
if($ResponseData->Status == 'SUCCESS'){
|
||||
$fromName = 'trainsystem';
|
||||
$fromEmail = 'cyc@hainatravel.com';
|
||||
$coli_id = $this->BIZ_train_model->cold_sn_get_coli_id($ticket_data->ts_cold_sn);
|
||||
$coli_id = $coli_id['0']->COLI_ID;
|
||||
$info = $this->BIZ_train_model->get_operatorInfo($coli_id);
|
||||
$toName = $info[0]->OPI_Name;
|
||||
$toEmail = $info[0]->OPI_Email;
|
||||
$Mobile = $info[0]->Mobile;
|
||||
$subject = '退票请求';
|
||||
$body = '乘客:'.$data->tst_realname.' 对订单:'.$data->ts_ordernumber.'发起退票请求!!!';
|
||||
//发送邮件给外联
|
||||
$this->Sendmail_model->SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body);
|
||||
echo '{"reason":"退票成功","status":"200"}';
|
||||
}else{
|
||||
header("HTTP/1.1 404 Not Found");
|
||||
echo '{"reason":"退票失败","status":"404"}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
//途牛接口创建请求签名
|
||||
function create_sign(){
|
||||
$time = date('Y-m-d H:i:s',time());
|
||||
$secretKey = 'qvHMJVywEQqsd4EneHQl';
|
||||
$id = 'retailId25';
|
||||
$timeStamp = 'timestamp'.$time;
|
||||
$sign = $secretKey.$id.'apiKey'.TUNIU_KEY.$timeStamp.$secretKey;
|
||||
return strtoupper(md5($sign));
|
||||
}
|
||||
|
||||
//证件名称转id
|
||||
function strexchangeid($name){
|
||||
if($name != ''){
|
||||
switch ($name){
|
||||
case '二代身份证':
|
||||
return '1';
|
||||
break;
|
||||
case '护照':
|
||||
return 'B';
|
||||
break;
|
||||
case '台湾通行证':
|
||||
return 'G';
|
||||
break;
|
||||
case '港澳通行证':
|
||||
return 'C';
|
||||
break;
|
||||
default :
|
||||
return 'B';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//特殊字符转换
|
||||
function chk_sp_name($name){
|
||||
$name = str_replace(
|
||||
array('á', 'é', 'è', 'í', 'ó', 'ú', '?', 'á', 'é', 'í', 'ó', 'ú', '?',' ','/',' ',','),
|
||||
array('a', 'e', 'e', 'i', 'o', 'u', 'n', 'A', 'E', 'I', 'O', 'U', 'N','','','',''),
|
||||
$name
|
||||
);
|
||||
return substr(strtoupper($name),0,30);
|
||||
}
|
||||
|
||||
//发送请求函数
|
||||
function GetPost_http($url, $data = '',$format='') {
|
||||
if(!isset($_SERVER['HTTP_USER_AGENT'])){
|
||||
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.2372.400 QQBrowser/9.5.10548.400';
|
||||
}
|
||||
$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 (!empty($data)) {
|
||||
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
|
||||
if($format == 'json'){
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||
}
|
||||
}
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 40000); // 设置超时限制防止死循环
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
||||
$tmpInfo = curl_exec($curl); // 执行操作
|
||||
$errno = curl_errno($curl);
|
||||
if ($errno !== 0) {
|
||||
log_message('error', 'ctripost'.$errno.curl_error($curl));
|
||||
}
|
||||
curl_close($curl); //关闭CURL会话
|
||||
return $tmpInfo; //返回数据
|
||||
}
|
||||
|
||||
function getDingSignature(){
|
||||
$timestamp = time();
|
||||
$signature = hash_hmac('sha256',$timestamp,'emCK5vYFJc-HtMNNgbyGpmbYaNyPkNXn_ayoFd6q2m6rpljhxBn2JQEx9gy8H6DQ',true);
|
||||
$signature = base64_encode($signature);
|
||||
return $signature;
|
||||
}
|
||||
|
||||
function dingLogin(){
|
||||
redirect('https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=dingoaystremzlahfew1tb&response_type=code&scope=snsapi_login&state=STATE&redirect_uri=http://www.mycht.cn/info.php/apps/trainsystem/api/check_login');
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
class Des
|
||||
{
|
||||
|
||||
function encrypt($string,$key)
|
||||
{
|
||||
$size = mcrypt_get_block_size('des','ecb');
|
||||
//$string = mb_convert_encoding($string, 'GBK', 'UTF-8');
|
||||
$string = $this->pkcs5_pad($string, $size);
|
||||
$td = mcrypt_module_open('des', '', 'ecb', '');
|
||||
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
@mcrypt_generic_init($td, $key, $iv);
|
||||
$data = mcrypt_generic($td, $string);
|
||||
mcrypt_generic_deinit($td);
|
||||
mcrypt_module_close($td);
|
||||
$data = base64_encode($data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
function decrypt($string,$key)
|
||||
{
|
||||
$string = base64_decode($string);
|
||||
$td = mcrypt_module_open('des', '', 'ecb', '');
|
||||
//使用MCRYPT_DES算法,cbc模式
|
||||
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
|
||||
$ks = mcrypt_enc_get_key_size($td);
|
||||
@mcrypt_generic_init($td, $key, $iv);
|
||||
//初始处理
|
||||
$decrypted = mdecrypt_generic($td, $string);
|
||||
//解密
|
||||
mcrypt_generic_deinit($td);
|
||||
//结束
|
||||
mcrypt_module_close($td);
|
||||
|
||||
$result = $this->pkcs5_unpad($decrypted);
|
||||
//$result = mb_convert_encoding($result, 'UTF-8', 'GBK');
|
||||
return $result;
|
||||
}
|
||||
|
||||
function pkcs5_pad($text, $blocksize)
|
||||
{
|
||||
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||
return $text . str_repeat(chr($pad), $pad);
|
||||
}
|
||||
|
||||
function pkcs5_unpad($text)
|
||||
{
|
||||
$pad = ord($text{strlen($text) - 1});
|
||||
if ($pad > strlen($text)) {
|
||||
return false;
|
||||
}
|
||||
if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) {
|
||||
return false;
|
||||
}
|
||||
return substr($text, 0, -1 * $pad);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,157 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class Sendmail_model extends CI_Model {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
}
|
||||
|
||||
function SendMailToTable($fromName,$fromEmail,$toName,$toEmail,$subject,$body)
|
||||
{
|
||||
$time = date('Y-m-d H:i:s',time());
|
||||
if($this->validEmail($toEmail))
|
||||
{
|
||||
$data = array(
|
||||
"M_ReplyToName" => $fromName, //回复人
|
||||
"M_ReplyToEmail" => $fromEmail, //回复地址
|
||||
"M_ToName" => $toName, //收件人名
|
||||
"M_ToEmail" => $toEmail, //收件邮件地址
|
||||
"M_Title" => $subject, //主题
|
||||
"M_Body" => $body, //邮件正文
|
||||
"M_Web" => "CHT", //所属站点
|
||||
"M_FromName" => "Chinahighlights.com", //站点名称
|
||||
"M_State" => 0,
|
||||
"M_AddTime" => $time
|
||||
);
|
||||
$this->HT->insert('Email_AutomaticSend',$data);
|
||||
$m_sn = $this->HT->insert_id('Email_AutomaticSend');
|
||||
return $m_sn;
|
||||
}else{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function SendMailToTabletest($fromName,$fromEmail,$toName,$toEmail,$subject,$body)
|
||||
{
|
||||
$time = date('Y-m-d H:i:s',time());
|
||||
if($this->validEmail($toEmail))
|
||||
{
|
||||
$data = array(
|
||||
"M_ReplyToName" => $fromName, //回复人
|
||||
"M_ReplyToEmail" => $fromEmail, //回复地址
|
||||
"M_ToName" => $toName, //收件人名
|
||||
"M_ToEmail" => $toEmail, //收件邮件地址
|
||||
"M_Title" => $subject, //主题
|
||||
"M_Body" => $body, //邮件正文
|
||||
"M_Web" => "CHT", //所属站点
|
||||
"M_FromName" => "Chinahighlights.com", //站点名称
|
||||
"M_State" => 0,
|
||||
"M_AddTime" => $time,
|
||||
);
|
||||
$this->HT->insert('Email_AutomaticSend',$data);
|
||||
$m_sn = $this->HT->insert_id('Email_AutomaticSend');
|
||||
return $m_sn;
|
||||
}else{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function validEmail($email){
|
||||
$isValid = true;
|
||||
$atIndex = strrpos($email, "@");
|
||||
if (is_bool($atIndex) && !$atIndex){
|
||||
$isValid = false;
|
||||
}else{
|
||||
$domain = substr($email, $atIndex+1);
|
||||
$local = substr($email, 0, $atIndex);
|
||||
$localLen = strlen($local);
|
||||
$domainLen = strlen($domain);
|
||||
$domain = str_replace(' ','',$domain);
|
||||
if ($localLen < 1 || $localLen > 64){
|
||||
// local part length exceeded
|
||||
$isValid = false;
|
||||
}else if ($domainLen < 1 || $domainLen > 255){
|
||||
// domain part length exceeded
|
||||
$isValid = false;
|
||||
}else if ($local[0] == '.' || $local[$localLen-1] == '.'){
|
||||
// local part starts or ends with '.'
|
||||
$isValid = false;
|
||||
}else if (preg_match('/\\.\\./', $local)){
|
||||
// local part has two consecutive dots
|
||||
$isValid = false;
|
||||
}else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){
|
||||
// character not valid in domain part
|
||||
$isValid = false;
|
||||
}else if (preg_match('/\\.\\./', $domain)){
|
||||
// domain part has two consecutive dots
|
||||
$isValid = false;
|
||||
}else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))){
|
||||
// character not valid in local part unless
|
||||
// local part is quoted
|
||||
if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))){
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
不检查是否有DNS解析
|
||||
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){
|
||||
// domain not found in DNS
|
||||
$isValid = false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
public function validEmailtest($email){
|
||||
$isValid = true;
|
||||
$atIndex = strrpos($email, "@");
|
||||
if (is_bool($atIndex) && !$atIndex){
|
||||
$isValid = false;
|
||||
}else{
|
||||
$domain = substr($email, $atIndex+1);
|
||||
$local = substr($email, 0, $atIndex);
|
||||
$localLen = strlen($local);
|
||||
$domainLen = strlen($domain);
|
||||
$domain = str_replace(' ','',$domain);
|
||||
print_r(preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain));
|
||||
if ($localLen < 1 || $localLen > 64){
|
||||
// local part length exceeded
|
||||
$isValid = false;
|
||||
}else if ($domainLen < 1 || $domainLen > 255){
|
||||
// domain part length exceeded
|
||||
$isValid = false;
|
||||
}else if ($local[0] == '.' || $local[$localLen-1] == '.'){
|
||||
// local part starts or ends with '.'
|
||||
$isValid = false;
|
||||
}else if (preg_match('/\\.\\./', $local)){
|
||||
// local part has two consecutive dots
|
||||
$isValid = false;
|
||||
}else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)){
|
||||
// character not valid in domain part
|
||||
$isValid = false;
|
||||
}else if (preg_match('/\\.\\./', $domain)){
|
||||
// domain part has two consecutive dots
|
||||
$isValid = false;
|
||||
}else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))){
|
||||
// character not valid in local part unless
|
||||
// local part is quoted
|
||||
if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))){
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
不检查是否有DNS解析
|
||||
if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){
|
||||
// domain not found in DNS
|
||||
$isValid = false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
class train_system_model extends CI_Model {
|
||||
private $order="";//订单号
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->HT = $this->load->database('HT', TRUE);
|
||||
$this->INFO = $this->load->database('INFO', TRUE);
|
||||
}
|
||||
|
||||
public function get_order($pagesize=2,$page=0,$where="1=1"){
|
||||
$data=new StdClass();
|
||||
//获取总条数
|
||||
$sql="SELECT COUNT(*) AS count FROM InfoManager.dbo.trainsystem
|
||||
LEFT JOIN
|
||||
BIZ_ConfirmLineInfo
|
||||
ON
|
||||
BIZ_ConfirmLineInfo.COLI_SN=(SELECT COLD_COLI_SN FROM BIZ_ConfirmLineDetail WHERE COLD_SN = InfoManager.dbo.trainsystem.ts_cold_sn)
|
||||
WHERE
|
||||
{$where}
|
||||
";
|
||||
$query = $this->HT->query($sql);
|
||||
$count=$query->result();
|
||||
$data->count=$count[0]->count;
|
||||
|
||||
$sql="SELECT TOP {$pagesize} InfoManager.dbo.trainsystem.ts_subtime,
|
||||
InfoManager.dbo.trainsystem.ts_cold_sn,
|
||||
InfoManager.dbo.trainsystem.ts_ordernumber,
|
||||
InfoManager.dbo.trainsystem.ts_status,
|
||||
InfoManager.dbo.trainsystem.ts_errormsg,
|
||||
InfoManager.dbo.trainsystem.ts_fromstationame,
|
||||
InfoManager.dbo.trainsystem.ts_tostationame,
|
||||
InfoManager.dbo.trainsystem.ts_checi,
|
||||
InfoManager.dbo.trainsystem.ts_orderamount,
|
||||
InfoManager.dbo.trainsystem.ts_isauto,
|
||||
InfoManager.dbo.trainsystem.ts_sendmail,
|
||||
InfoManager.dbo.trainsystem.ts_m_sn,
|
||||
InfoManager.dbo.trainsystem.ts_channel,
|
||||
BIZ_ConfirmLineInfo.COLI_ID,
|
||||
BIZ_ConfirmLineInfo.COLI_WebCode
|
||||
FROM
|
||||
InfoManager.dbo.trainsystem
|
||||
LEFT JOIN
|
||||
BIZ_ConfirmLineInfo
|
||||
ON
|
||||
BIZ_ConfirmLineInfo.COLI_SN=(SELECT COLD_COLI_SN FROM BIZ_ConfirmLineDetail WHERE COLD_SN = InfoManager.dbo.trainsystem.ts_cold_sn)
|
||||
WHERE
|
||||
InfoManager.dbo.trainsystem.ts_id NOT IN(
|
||||
SELECT
|
||||
TOP {$page} ts_id
|
||||
FROM
|
||||
InfoManager.dbo.trainsystem
|
||||
LEFT JOIN
|
||||
BIZ_ConfirmLineInfo
|
||||
ON
|
||||
BIZ_ConfirmLineInfo.COLI_SN=(SELECT COLD_COLI_SN FROM BIZ_ConfirmLineDetail WHERE COLD_SN = InfoManager.dbo.trainsystem.ts_cold_sn)
|
||||
where {$where}
|
||||
ORDER BY ts_subtime DESC)
|
||||
AND
|
||||
{$where}
|
||||
ORDER BY InfoManager.dbo.trainsystem.ts_subtime DESC";
|
||||
|
||||
$query = $this->HT->query($sql);
|
||||
$data->list=$query->result();
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
//获取指定订单信息
|
||||
public function get_passager_details($ordernumber){
|
||||
$sql = "select * from trainsystem_tickets where tst_ordernumber = '{$ordernumber}'";
|
||||
$query = $this->INFO->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
//获取火车信息
|
||||
public function get_train_infos($ordernumber){
|
||||
$sql = "select * from trainsystem where ts_ordernumber = '{$ordernumber}'";
|
||||
$query = $this->INFO->query($sql);
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function update_passpager_status($status,$passagerid){
|
||||
$sql = "update trainsystem_tickets set tst_status = '{$status}' where tst_id = '{$passagerid}'";
|
||||
$query = $this->INFO->query($sql);
|
||||
}
|
||||
|
||||
//添加订单
|
||||
function add_orders($data){
|
||||
$sql="
|
||||
INSERT INTO trainsystem(
|
||||
ts_cold_sn,
|
||||
ts_ordernumber,
|
||||
ts_subtime,
|
||||
ts_returncode,
|
||||
ts_status,
|
||||
ts_errormsg,
|
||||
ts_fromstationame,
|
||||
ts_fromstationcode,
|
||||
ts_tostationame,
|
||||
ts_tostationcode,
|
||||
ts_startdate,
|
||||
ts_startime,
|
||||
ts_endtime,
|
||||
ts_runtime,
|
||||
ts_checi,
|
||||
ts_channel,
|
||||
ts_isauto
|
||||
)
|
||||
VALUES(
|
||||
'{$data->cold_sn}',
|
||||
'{$data->ordernumber}',
|
||||
getdate(),
|
||||
'{$data->returncode}',
|
||||
'{$data->status}',
|
||||
'{$data->errormsg}',
|
||||
'{$data->fromstationame}',
|
||||
'{$data->fromstationcode}',
|
||||
'{$data->tostationame}',
|
||||
'{$data->tostationcode}',
|
||||
'{$data->startdate}',
|
||||
'{$data->startime}',
|
||||
'{$data->endtime}',
|
||||
'{$data->runtime}',
|
||||
'{$data->checi}',
|
||||
'{$data->channel}',
|
||||
'{$data->isauto}'
|
||||
)
|
||||
";
|
||||
//echo $sql;
|
||||
$query = $this->INFO->query($sql);
|
||||
}
|
||||
|
||||
public function ticketfrom($ts_ordernumber){
|
||||
$sql = "select ts_channel,ts_cold_sn,ts_ordernumber from trainsystem where ts_ordernumber = ?";
|
||||
$query = $this->INFO->query($sql,array($ts_ordernumber));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
public function get_passenger_info($ordernumber,$passportname,$passportno){
|
||||
$sql = "select * from trainsystem_tickets left join trainsystem on tst_ordernumber = ts_ordernumber where tst_realname = ? and tst_numberid = ? and tst_ordernumber = ?";
|
||||
$query = $this->INFO->query($sql,array($passportname,$passportno,$ordernumber));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
function add_passagers($data){
|
||||
$sql = "IF EXISTS (select * from trainsystem_tickets where tst_ordernumber = '{$data->ordernumber}' and tst_numberid = '{$data->numberid}')
|
||||
update
|
||||
trainsystem_tickets
|
||||
set
|
||||
tst_identitytype = '{$data->identitytype}',
|
||||
tst_numberid = '{$data->numberid}',
|
||||
tst_ticketype = '{$data->ticketype}',
|
||||
tst_ticketprice = '{$data->ticketprice}',
|
||||
tst_seatstype = '{$data->seatype}',
|
||||
tst_seatdetail = '{$data->seatdetail}',
|
||||
tst_status = '{$data->status}'
|
||||
where
|
||||
tst_ordernumber = '{$data->ordernumber}'
|
||||
and
|
||||
tst_numberid = '{$data->numberid}'
|
||||
else
|
||||
INSERT INTO trainsystem_tickets (
|
||||
tst_ordernumber,
|
||||
tst_status,
|
||||
tst_realname,
|
||||
tst_identitytype,
|
||||
tst_numberid,
|
||||
tst_ticketype,
|
||||
tst_ticketprice,
|
||||
tst_seatstype,
|
||||
tst_seatdetail
|
||||
)VALUES(
|
||||
'{$data->ordernumber}',
|
||||
'{$data->status}',
|
||||
'{$data->realname}',
|
||||
'{$data->identitytype}',
|
||||
'{$data->numberid}',
|
||||
'{$data->ticketype}',
|
||||
'{$data->ticketprice}',
|
||||
'{$data->seatype}',
|
||||
'{$data->seatdetail}'
|
||||
)
|
||||
";
|
||||
$query =$this->INFO->query($sql);
|
||||
}
|
||||
|
||||
public function update_orders($data){
|
||||
$where = '';
|
||||
if(!empty($data->bookcallback)){
|
||||
$where .= "
|
||||
ts_seatsinfo = '{$data->seatsinfo}',
|
||||
ts_checkdoor = '{$data->TicketCheck}',
|
||||
ts_elecnumber = '{$data->ElectronicOrderNumber}',
|
||||
ts_orderamount = '{$data->OrderTotleFee}',
|
||||
ts_bookcallback = '{$data->bookcallback}',";
|
||||
}else if(!empty($data->confirmcallback)){
|
||||
$where .= "ts_confirmcallback = '{$data->confirmcallback}',";
|
||||
}else if(!empty($data->returncallback)){
|
||||
$where .= "ts_returncallback = '{$data->returncallback}',";
|
||||
}else if(!empty($data->reschedulecallback)){
|
||||
$where .= "ts_reschedulecallback = '{$data->reschedulecallback}',";
|
||||
}
|
||||
$sql ="
|
||||
update trainsystem
|
||||
set
|
||||
ts_status = '{$data->OrderStatus}',
|
||||
ts_errormsg = '{$data->ErrorMsg}',
|
||||
".substr($where,0,strlen($where)-1)."
|
||||
where
|
||||
ts_ordernumber = '{$data->ordernumber}'
|
||||
";
|
||||
//echo $sql;die();
|
||||
$query = $this->INFO->query($sql);
|
||||
}
|
||||
|
||||
//更新乘客表信息
|
||||
public function update_passpager_info($data){
|
||||
$sql = "update
|
||||
trainsystem_tickets
|
||||
set
|
||||
tst_status = '{$data->status}',
|
||||
tst_returncallback = '{$data->returncallback}',
|
||||
tst_lasteditdate = getdate()
|
||||
where
|
||||
tst_ordernumber = '{$data->ordernumber}'
|
||||
and
|
||||
tst_realname = '{$data->realname}'
|
||||
and
|
||||
tst_numberid = '{$data->numberid}'
|
||||
";
|
||||
$query = $this->INFO->query($sql);
|
||||
}
|
||||
|
||||
public function get_tickets_info($cold_sn){
|
||||
$sql = "select ts_cold_sn,ts_ordernumber,tst_realname,tst_numberid,tst_status from trainsystem left join trainsystem_tickets on ts_ordernumber = tst_ordernumber where ts_cold_sn = ? and ts_status = '4'";
|
||||
$query = $this->INFO->query($sql,array($cold_sn));
|
||||
//$sql = "select * from BIZ_JuheOrderList where JOL_COLD_SN = ? and jol_status = '4'";
|
||||
//$query = $this->HT->query($sql,array($cold_sn));
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getallorders(){
|
||||
$sql = "select * from Tourmanager.dbo.BIZ_JuheOrderList where JOL_SubTime > '2019-03-01' and (JOL_Status = '4' or JOL_Status = '7')";
|
||||
$query = $this->HT->query($sql);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function update_juheorder($ordernumber,$subtime,$price){
|
||||
$sql = "update trainsystem set ts_subtime = ? , ts_orderamount = ? where ts_ordernumber = ?";
|
||||
$query = $this->INFO->query($sql,array($subtime,$price,$ordernumber));
|
||||
}
|
||||
|
||||
//根据cold_sn 获取出票情况
|
||||
public function get_ticketinfos($cold_sn){
|
||||
$sql = "select * from trainsystem where ts_cold_sn = ? and ts_status = '4'";
|
||||
$query = $this->INFO->query($sql,array($cold_sn));
|
||||
return $query->row();
|
||||
}
|
||||
|
||||
|
||||
public function test(){
|
||||
$sql = "delete from trainsystem where ts_cold_sn = '488121613_1552637689'";
|
||||
$query = $this->INFO->query($sql);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,131 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>出票系统</title>
|
||||
<link rel="stylesheet" href="/css/information-system3.css?v=201508112" type="text/css" />
|
||||
<script type="text/javascript" src="/min/?f=/js/information-system3.min.js,/js/common.js"></script>
|
||||
<link rel="shortcut icon" href="/bootstrap/img/glyphicons_290_skull.png">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9" aria-expanded="false">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/"><span class="glyphicon glyphicon-home text-white"></span></a>
|
||||
</div>
|
||||
|
||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="<?php echo site_url(''); ?>">信息管理</a></li>
|
||||
<li><a href="<?php echo site_url('product') ?>">产品管理</a></li>
|
||||
<li><a href="<?php echo site_url('author'); ?>">作者平台</a></li>
|
||||
<li><a href="<?php echo site_url('keyworlds') ?>">关键词</a></li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
更多<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="<?php echo site_url('seo') ?>">SEO管理</a></li>
|
||||
<li> <a href="<?php echo site_url('thirdparty/public/infopayauthor') ?>">打赏统计</a></li>
|
||||
<li> <a href="<?php echo site_url('thirdparty/form') ?>">表单管理</a></li>
|
||||
<li><a href="<?php echo site_url('thirdparty/advertise') ?>">广告管理</a></li>
|
||||
<li><a href="<?php echo site_url('setting') ?>">系统设置</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<form id="form_information_search" name="form_information_search" method="post" action="<?php echo $this->router->class == 'infoshare' ? site_url('infoshare/search/') : site_url('welcome/search/'); ?>" class="navbar-form navbar-left" >
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">
|
||||
<input type="checkbox" title="全文搜索" name="all_text_search" id="all_text_search" value="true" >
|
||||
</span>
|
||||
<input type="text" class="form-control input-sm" name="keywords" id="keywords" value="<?php echo isset($keywords) ? $keywords : false; ?>" style="min-width:450px;">
|
||||
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default btn-sm" type="submit">搜索</button>
|
||||
<a href="#" onclick="openKCFinder_fast();" class="btn btn-default btn-sm" title="快速上传图片" ><span class="glyphicon glyphicon-picture"></span></a>
|
||||
<a href="#" title="静态化更新" class="btn btn-default btn-sm" data-toggle="modal" data-target="#cache_refresh_modal" ><span class="glyphicon glyphicon-repeat"></span></a>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<?php
|
||||
$all_unread_sms = get_all_unread_sms();
|
||||
$info_unread_sms = get_all_unread_sms('info');
|
||||
if (isset($information->ic_id))
|
||||
$current_msg = $information->ic_id;
|
||||
if (isset($task->t_id))
|
||||
$current_msg = $task->t_id;
|
||||
$total_count = $all_unread_sms['sms_count'] + $info_unread_sms['sms_count']; //计算未读消息总数
|
||||
$unread_sms_ic_id = 0; //用于设置所有收录消息为已读
|
||||
if ($total_count != 0) {
|
||||
?>
|
||||
<!-- 如果当前页面存在未读消息,则消息数减一 -->
|
||||
<?php
|
||||
if (isset($current_msg) && isset($all_unread_sms['sms'][$current_msg])) {
|
||||
$total_count = $total_count - count($all_unread_sms['sms'][$current_msg]);
|
||||
unset($all_unread_sms['sms'][$current_msg]);
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (isset($current_msg) && isset($info_unread_sms['sms'][$current_msg])) {
|
||||
$total_count = $total_count - count($info_unread_sms['sms'][$current_msg]);
|
||||
unset($info_unread_sms['sms'][$current_msg]);
|
||||
}
|
||||
?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="icon-envelope icon-white pull-left" style="margin-top:3px;"></i> <span class="badge badge-important pull-right"><?php echo $total_count; ?></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- 信息平台的消息 -->
|
||||
<?php if (isset($info_unread_sms['sms']) && !empty($info_unread_sms['sms'])) { ?>
|
||||
<a style="padding-left:20px;" href="javascript:void(0);" onclick="set_allmsg_to_read($('#unreadinfomsg').val());">标记全部收录信息为已读</a>
|
||||
<li class="divider"></li>
|
||||
<?php foreach ($info_unread_sms['sms'] as $m) { ?>
|
||||
<li><a href="<?php echo site_url('information/edit/' . $m[0]->is_id); ?>"><?php
|
||||
$t_title = get_text_short($m[0]->t_title, 15);
|
||||
echo '[' . $m[0]->ic_sitecode . '] ' . $t_title['content'] . ' (' . $m[0]->m_content . ')';
|
||||
?></a></li>
|
||||
<?php $unread_sms_ic_id.=',' . $m[0]->m_object_id; ?>
|
||||
<?php } ?>
|
||||
<li class="divider"></li>
|
||||
<input type="hidden" name="unreadinfomsg" id="unreadinfomsg" value="<?php echo $unread_sms_ic_id; ?>">
|
||||
<?php } ?>
|
||||
<!--作者平台的消息-->
|
||||
<?php foreach ($all_unread_sms['sms'] as $am) { ?>
|
||||
<li><a href="<?php echo site_url('author/edit_task/' . $am[0]->m_object_id); ?>"><?php
|
||||
$t_title = get_text_short($am[0]->t_title, 15);
|
||||
echo $t_title['content'] . ' (' . count($am) . ')';
|
||||
?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<?php
|
||||
echo $this->config->item('site_code');
|
||||
echo ' -';
|
||||
$admin_info = $this->session->userdata('session_admin');
|
||||
echo $admin_info['OPI_Name'];
|
||||
?>
|
||||
<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<?php foreach ($this->config->item('site') as $site_item) { ?>
|
||||
<li> <a href="<?php echo site_url('login/change_site/' . $site_item['site_code']); ?>" ><?php echo $site_item['site_code'] ?></a></li>
|
||||
<?php } ?>
|
||||
<li><a href="<?php echo site_url('login/out'); ?>" >退出</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title></head><body><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Dear <?php echo $toname?>,</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;"> Thank you for your booking (order number <?php echo $coli_id?>), we have received your payment of USD<?php echo $price->GAI_SQJE?>. </p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;"> Due to the heavy traffic flow of data, the system failed to automatically issue your ticket(s).</p><p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Your travel advisor will purchase your train ticket(s) manually. You will receive an email within half a working day (Our time now: <strong><?php echo date('H:i').' '.date('a');?></strong>, <?php echo date('D');?>,<?php echo date('F').' '.date('d').','.date('Y');?> GMT+8).Should you have any questions or concerns with regards to your train booking, please do not hesitate to contact me at <a href="mailto:<?php echo $emailarr[0]?>"><?php echo $emailarr[0]?></a>;<a href="mailto:<?php echo $emailarr[1]?>"><?php echo $emailarr[1]?></a> or telephone <?php echo $operator[0]->tel;?>. </p>
|
||||
<?php foreach($train_info as $item){
|
||||
echo '<table border="0" cellspacing="0" cellpadding="0" width="60%">';
|
||||
echo '<tr><th width="17%" style="font-family:Verdana, Geneva, sans-serif;font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Train No. </th>';
|
||||
echo '<td width="83%" style="font-family:Verdana, Geneva, sans-serif;font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->FlightsNo.'</td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Departure </th>';
|
||||
echo '<td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->DepartureTime.', '.$item->DepartureCity.' Station(in Chinese '.$item->DepartAirport_cn.'火车站) </td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Arrival </th><td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->ArrivalTime.', '.$item->ArrivalCity.'(in Chinese'. $item->ArrivalAirport_cn.'火车站) </td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Class </th><td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">'.$item->Cabin.'</td></tr>';
|
||||
echo '<tr><th style="font-family:Verdana, Geneva, sans-serif; font-size:14px; color:#a31022; background:#e6e6e6; text-align:left; padding:10px;">Passenger(s) </th>';
|
||||
echo '<td style="font-family:Verdana, Geneva, sans-serif; font-size:14px; text-align:left; padding:10px; border-bottom:1px solid #d1d1d1;">';
|
||||
if($adult>0){echo $adult.' adult(s)<br/> ';}
|
||||
if($chlid>0){echo $chlid.' chlid(s)<br/> ';}
|
||||
if($baby>0){echo $baby.' baby(s)<br/> ';}
|
||||
$i=0;
|
||||
foreach($allpeople as $item){
|
||||
echo ++$i.'.'.$item->BPE_FirstName.$item->BPE_MiddleName.$item->BPE_LastName.' , passport number '.$item->BPE_Passport.'<br>';
|
||||
}
|
||||
echo '</tr></table>';
|
||||
echo '<p style="font-family:Verdana, Geneva, sans-serif; font-size:14px; line-height:24px; margin-bottom:12px;">Regards <br />';
|
||||
echo $operator[0]->Name.'<br/>Travel Advisor<br/>';
|
||||
echo 'Telephone: (Office)'.$operator[0]->tel.', M: '.$operator[0]->Mobile.',';
|
||||
echo 'Email: <a href="mailto:'.$emailarr[0].'">'.$emailarr[0].'</a>;<a href="mailto:'.$emailarr[1].'">'.$emailarr[1].'</a>; </p>';
|
||||
}?>
|
||||
</body>
|
||||
</html>
|
||||
@ -0,0 +1,156 @@
|
||||
<?php // 代码各服务器已经同步 2016.06.01 ycc ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>信息平台</title>
|
||||
<link rel="stylesheet" href="/css/information-system3.css?v=201508112" type="text/css" />
|
||||
<script type="text/javascript" src="/min/?f=/js/information-system3.min.js,/js/common.js"></script>
|
||||
<script type="text/javascript" src="/js/kindeditor/kindeditor.js?v=20160601"></script>
|
||||
<link rel="shortcut icon" href="/bootstrap/img/glyphicons_290_skull.png">
|
||||
<script language="javascript">
|
||||
//快速图片上传
|
||||
function openKCFinder_fast() {
|
||||
window.CallBack = oopenKCFinder_fast_callback;
|
||||
window.open('/media/popselectpicture.php?site_code=<?php echo $this->config->item('site_code'); ?>&site_lgc=<?php echo $this->config->item('site_lgc'); ?>', 'kcfinder_textbox', 'status=0, toolbar=0, location=0, menubar=0, directories=0,resizable=1, scrollbars=0, width=800, height=600');
|
||||
}
|
||||
|
||||
function oopenKCFinder_fast_callback(result) {
|
||||
var site_image_url = '<?php echo $this->config->item('site_image_url') ?>';
|
||||
if (result != null && result.Pinfo[0]) {
|
||||
$.modaldialog.success("图片地址:<br/>" + site_image_url + result.Pinfo[0].PUrl);
|
||||
}
|
||||
}
|
||||
//标识所有信息未已读
|
||||
function set_allmsg_to_read(ic_ids) {
|
||||
var url = '<?php echo site_url("author/set_msg_to_read"); ?>';
|
||||
$.post(url, {'msg_ids': ic_ids}, function(result) {
|
||||
window.location.href = window.location.href;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
<nav class="navbar navbar-inverse">
|
||||
<div class="container-fluid">
|
||||
<div class="navbar-header">
|
||||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-9" aria-expanded="false">
|
||||
<span class="sr-only">Toggle navigation</span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="/"><span class="glyphicon glyphicon-home text-white"></span></a>
|
||||
</div>
|
||||
|
||||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-9">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="<?php echo site_url(''); ?>">信息管理</a></li>
|
||||
<li><a href="<?php echo site_url('product') ?>">产品管理</a></li>
|
||||
<li><a href="<?php echo site_url('author'); ?>">作者平台</a></li>
|
||||
<li><a href="<?php echo site_url('keyworlds') ?>">关键词</a></li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
更多<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="<?php echo site_url('seo') ?>">SEO管理</a></li>
|
||||
<li> <a href="<?php echo site_url('thirdparty/public/infopayauthor') ?>">打赏统计</a></li>
|
||||
<li> <a href="<?php echo site_url('thirdparty/form') ?>">表单管理</a></li>
|
||||
<li><a href="<?php echo site_url('thirdparty/advertise') ?>">广告管理</a></li>
|
||||
<li><a href="<?php echo site_url('setting') ?>">系统设置</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<form id="form_information_search" name="form_information_search" method="post" action="<?php echo $this->router->class == 'infoshare' ? site_url('infoshare/search/') : site_url('welcome/search/'); ?>" class="navbar-form navbar-left" >
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">
|
||||
<input type="checkbox" title="全文搜索" name="all_text_search" id="all_text_search" value="true" >
|
||||
</span>
|
||||
<input type="text" class="form-control input-sm" name="keywords" id="keywords" value="<?php echo isset($keywords) ? $keywords : false; ?>" style="min-width:450px;">
|
||||
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default btn-sm" type="submit">搜索</button>
|
||||
<a href="#" onclick="openKCFinder_fast();" class="btn btn-default btn-sm" title="快速上传图片" ><span class="glyphicon glyphicon-picture"></span></a>
|
||||
<a href="#" title="静态化更新" class="btn btn-default btn-sm" data-toggle="modal" data-target="#cache_refresh_modal" ><span class="glyphicon glyphicon-repeat"></span></a>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
<?php
|
||||
$all_unread_sms = get_all_unread_sms();
|
||||
$info_unread_sms = get_all_unread_sms('info');
|
||||
if (isset($information->ic_id))
|
||||
$current_msg = $information->ic_id;
|
||||
if (isset($task->t_id))
|
||||
$current_msg = $task->t_id;
|
||||
$total_count = $all_unread_sms['sms_count'] + $info_unread_sms['sms_count']; //计算未读消息总数
|
||||
$unread_sms_ic_id = 0; //用于设置所有收录消息为已读
|
||||
if ($total_count != 0) {
|
||||
?>
|
||||
<!-- 如果当前页面存在未读消息,则消息数减一 -->
|
||||
<?php
|
||||
if (isset($current_msg) && isset($all_unread_sms['sms'][$current_msg])) {
|
||||
$total_count = $total_count - count($all_unread_sms['sms'][$current_msg]);
|
||||
unset($all_unread_sms['sms'][$current_msg]);
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if (isset($current_msg) && isset($info_unread_sms['sms'][$current_msg])) {
|
||||
$total_count = $total_count - count($info_unread_sms['sms'][$current_msg]);
|
||||
unset($info_unread_sms['sms'][$current_msg]);
|
||||
}
|
||||
?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="icon-envelope icon-white pull-left" style="margin-top:3px;"></i> <span class="badge badge-important pull-right"><?php echo $total_count; ?></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- 信息平台的消息 -->
|
||||
<?php if (isset($info_unread_sms['sms']) && !empty($info_unread_sms['sms'])) { ?>
|
||||
<a style="padding-left:20px;" href="javascript:void(0);" onclick="set_allmsg_to_read($('#unreadinfomsg').val());">标记全部收录信息为已读</a>
|
||||
<li class="divider"></li>
|
||||
<?php foreach ($info_unread_sms['sms'] as $m) { ?>
|
||||
<li><a href="<?php echo site_url('information/edit/' . $m[0]->is_id); ?>"><?php
|
||||
$t_title = get_text_short($m[0]->t_title, 15);
|
||||
echo '[' . $m[0]->ic_sitecode . '] ' . $t_title['content'] . ' (' . $m[0]->m_content . ')';
|
||||
?></a></li>
|
||||
<?php $unread_sms_ic_id.=',' . $m[0]->m_object_id; ?>
|
||||
<?php } ?>
|
||||
<li class="divider"></li>
|
||||
<input type="hidden" name="unreadinfomsg" id="unreadinfomsg" value="<?php echo $unread_sms_ic_id; ?>">
|
||||
<?php } ?>
|
||||
<!--作者平台的消息-->
|
||||
<?php foreach ($all_unread_sms['sms'] as $am) { ?>
|
||||
<li><a href="<?php echo site_url('author/edit_task/' . $am[0]->m_object_id); ?>"><?php
|
||||
$t_title = get_text_short($am[0]->t_title, 15);
|
||||
echo $t_title['content'] . ' (' . count($am) . ')';
|
||||
?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php } ?>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<?php
|
||||
echo $this->config->item('site_code');
|
||||
echo ' -';
|
||||
$admin_info = $this->session->userdata('session_admin');
|
||||
echo $admin_info['OPI_Name'];
|
||||
?>
|
||||
<b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<?php foreach ($this->config->item('site') as $site_item) { ?>
|
||||
<li> <a href="<?php echo site_url('login/change_site/' . $site_item['site_code']); ?>" ><?php echo $site_item['site_code'] ?></a></li>
|
||||
<?php } ?>
|
||||
<li><a href="<?php echo site_url('login/out'); ?>" >退出</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
@ -0,0 +1,64 @@
|
||||
<script type="text/javascript" src="https://data.chinahighlights.com/js/train/StationInfo.js"></script>
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><?php echo $train_date;?> <?php echo $checi;?> <?php echo isset($elecnumber)?$elecnumber:"";?></h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php if((int)$status>1):?>
|
||||
<p style="display:inline-block"><?php echo $from_station_name;?><span class="from_station_en"> </span><br><span class="start_time"></span></p><span class="glyphicon glyphicon-arrow-right"> </span><p style="display:inline-block"> <?php echo $to_station_name;?><span class="to_station_en"> </span><br><span class="arrive_time"></span></p>
|
||||
<?php foreach ($passengers as $v):?>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p><?php echo @$v->tst_realname."({$v->tst_identitytype}) {$v->tst_seatstype} {$v->tst_seatdetail} 票价:¥{$v->tst_ticketprice}";?></p>
|
||||
<?php endforeach;?>
|
||||
<?php if((int)$status === 4):?>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p>出票成功</p>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p style="text-align:center;"><a href="refund?order=<?php echo $ordernumber?>" style="padding:5px 15px;" class="btn btn-warning btn-sm">前往退票 <span class="glyphicon glyphicon-forward"></span></a></p>
|
||||
<?php endif;?>
|
||||
|
||||
<?php if((int)$status === 6):?>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p>正在处理退票</p>
|
||||
<p style="text-align:center;"><a href="refund?order=<?php echo $ordernumber?>" style="padding:5px 15px;" class="btn btn-warning btn-sm">查看详情 <span class="glyphicon glyphicon-forward"></span></a></p>
|
||||
<?php endif;?>
|
||||
|
||||
<?php if((int)$status === 7):?>
|
||||
<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>
|
||||
<p><?php echo $msg;?></p>
|
||||
<p style="text-align:center;"><a href="refund?order=<?php echo $ordernumber?>" style="padding:5px 15px;" class="btn btn-warning btn-sm">查看详情 <span class="glyphicon glyphicon-forward"></span></a></p>
|
||||
<?php endif;?>
|
||||
<?php else:?>
|
||||
<p><?php echo $msg;?></p>
|
||||
<?php endif;?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var StationInfoArr = StationInfo.split("@");
|
||||
var StationNameArr = new Array();
|
||||
var code_name = new Array();
|
||||
var station_cn_en = new Array();
|
||||
var form_data = {};
|
||||
for (var i = 0; i < StationInfoArr.length; ++i) {
|
||||
StationNameArr.push(StationInfoArr[i].split("|"));
|
||||
code_name[StationNameArr[i][1]] = [StationNameArr[i][2]];
|
||||
station_cn_en[StationNameArr[i][3]] = StationNameArr[i][2];
|
||||
}
|
||||
console.log(station_cn_en);
|
||||
$(function(){
|
||||
var from_station_en = code_name['<?php echo $from_station_code?>'];
|
||||
var to_station_en = code_name['<?php echo $to_station_code?>'];
|
||||
var start_date = '<?php echo $train_date?>';
|
||||
var start_time = '<?php echo $start_time?>';
|
||||
var arrive_time = '<?php echo $arrive_time?>';
|
||||
|
||||
//console.log(code_name);
|
||||
$('.from_station_en').html('('+from_station_en+') ');
|
||||
$('.to_station_en').html('('+to_station_en+')');
|
||||
$('.start_time').html('('+start_date+' '+start_time+')');
|
||||
$('.arrive_time').html('('+start_date+' '+arrive_time+')');
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -0,0 +1,101 @@
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">订单搜索</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<form style="" action="" method="get">
|
||||
<div class="col-md-6">
|
||||
<input class="form-control" type="text" placeholder="汉特订单号或聚合订单号" name="order" value="<?php echo !empty($order)?"$order":"";?>" autocomplete="off">
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<select class="form-control" name="web_code">
|
||||
<option value ="分站点查询,默认商旅" disabled="disabled" selected>分站点查询,默认全站</option>
|
||||
<option value ="CHT">商旅</option>
|
||||
<option value ="jp">日本</option>
|
||||
<option value="train_vac">西班牙</option>
|
||||
<option value="train_it">意大利</option>
|
||||
<option value="train_ru">俄罗斯</option>
|
||||
<option value="train_vc">法国</option>
|
||||
</select>
|
||||
</div>
|
||||
<!--<div class="col-md-5">
|
||||
<input type="text" name="from_date" class="date" value="" class="">
|
||||
至
|
||||
<input type="text" name="to_date" class="date" value="">
|
||||
</div>-->
|
||||
<div class="col-md-5">
|
||||
<button type="submit" id="sub" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-search"></span> 搜索</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">订单列表</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<table class="table table-striped" style="text-align:center;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:center;">序号</th>
|
||||
<th style="text-align:center;">汉特订单号(商家订单号)</th>
|
||||
<th style="text-align:center;">聚合订单号</th>
|
||||
<th style="text-align:center;">车次</th>
|
||||
<th style="text-align:center;">出发</th>
|
||||
<th style="text-align:center;">到达</th>
|
||||
<th style="text-align:center;">状态</th>
|
||||
<th style="text-align:center;">价格</th>
|
||||
<th style="text-align:center;">提交时间</th>
|
||||
<th style="text-align:center;">所属部门</th>
|
||||
<th style="text-align:center;">渠道</th>
|
||||
<th style="text-align:center;">出票方式</th>
|
||||
<th style="text-align:center;">是否发送邮件</th>
|
||||
<th style="text-align:center;">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php $num=0; foreach($data as $v):?>
|
||||
<tr>
|
||||
<td><?php echo ++$num;?></td>
|
||||
<td><?php echo $v->COLI_ID.'('.$v->ts_cold_sn.')';?></td>
|
||||
<td><?php echo $v->ts_ordernumber;?></td>
|
||||
<td><?php echo $v->ts_checi;?></td>
|
||||
<td><?php echo $v->ts_fromstationame;?></td>
|
||||
<td><?php echo $v->ts_tostationame;?></td>
|
||||
<td><?php echo $v->info;?></td>
|
||||
<td><?php echo $v->ts_orderamount;?></td>
|
||||
<td><?php echo $v->ts_subtime;?></td>
|
||||
<td><?php echo $v->COLI_WebCode;?></td>
|
||||
<td><?php echo $v->ts_channel;?></td>
|
||||
<?php
|
||||
if($v->ts_isauto == 1){
|
||||
echo '<td>自动</td>';
|
||||
}elseif($v->ts_isauto == 0){
|
||||
echo '<td>手动</td>';
|
||||
}elseif($v->ts_isauto == 3){
|
||||
echo '<td>抢票</td>';
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
if($v->ts_sendmail == 1){
|
||||
if($v->ts_m_sn){
|
||||
echo '<td><a target="_blank" href="http://www.mycht.cn/info.php/apps/train/index/get_mailinfo/'.$v->ts_m_sn.'">是</a></td>';
|
||||
}else{
|
||||
echo '<td>是</td>';
|
||||
}
|
||||
}else{
|
||||
echo '<td>否</td>';
|
||||
}
|
||||
?>
|
||||
<td><a target="_blank" href="order?order=<?php echo $v->ts_ordernumber;?>">详情</a></td>
|
||||
</tr>
|
||||
<?php endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="text-align:right;"><ul class="pagination"><?php echo $page_link;?></ul></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -0,0 +1,48 @@
|
||||
<div style="width:90%;margin:30px auto;">
|
||||
<div class="panel panel-primary" style="width:60%;margin:0 auto;">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title"><?php echo $train_date;?> <?php echo $checi;?> <?php echo isset($elecnumber)?$elecnumber:"";?></h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<?php
|
||||
foreach ($passengers as $items){
|
||||
echo '<p>'.$from_station_name.'<span class="glyphicon glyphicon-arrow-right"></span>'.$to_station_name.'</p>';
|
||||
echo '<p style="border-top:1px dashed #000; height:1px;margin-top:10px;" ></p>';
|
||||
echo '<p>'.$items->tst_realname.'('.$items->tst_ticketype.') '.$items->tst_seatstype.' '.$items->tst_seatdetail.' 票价:¥'.$items->tst_ticketprice.'</p>';
|
||||
if((int)$items->tst_status != 7){
|
||||
echo '<p>';
|
||||
echo '<a href="###" style="padding:5px 15px;" class="btn btn-warning btn-sm returnticket" name="'.$items->tst_realname.'" passid="'.$items->tst_numberid.'"><span class="glyphicon glyphicon-remove"></span>退票</a>';
|
||||
echo '</p>';
|
||||
}else{
|
||||
$info = json_decode($items->tst_returncallback);
|
||||
echo '<p><table class="table table-bordered table-hover" style="text-align:center;"><tr><th colspan="2" style="text-align:center;">退票处理</th></tr>';
|
||||
echo '<tr><td>'.$items->tst_lasteditdate.'</td>';
|
||||
echo '<tr><td>'.$msg.'</td></tr></table></p>';
|
||||
}
|
||||
}?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
$(function(){
|
||||
$('.returnticket').click(function(){
|
||||
var url = <?php echo "'http://www.mycht.cn/info.php/apps/trainsystem/returnorders/returntickets?ordernumber=$ordernumber'"?>;
|
||||
var return_ticket = $(this);
|
||||
name = $(this).attr('name');
|
||||
passid = $(this).attr('passid');
|
||||
url += '&passportname='+name+'&passportno='+passid+'&usercenter=no';
|
||||
//console.log(url);return false;
|
||||
$.ajax({
|
||||
url:url,
|
||||
success:function(json){
|
||||
alert('请求成功,正在处理退票...');
|
||||
return_ticket.html('退票成功');
|
||||
},
|
||||
error:function(json){
|
||||
alert('请求失败,请重新请求...');
|
||||
return_ticket.html('退票失败');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
PHPExcel_Autoloader::register();
|
||||
// As we always try to run the autoloader before anything else, we can use it to do a few
|
||||
// simple checks and initialisations
|
||||
//PHPExcel_Shared_ZipStreamWrapper::register();
|
||||
// check mbstring.func_overload
|
||||
if (ini_get('mbstring.func_overload') & 2) {
|
||||
throw new PHPExcel_Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
|
||||
}
|
||||
PHPExcel_Shared_String::buildCharacterSets();
|
||||
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_Autoloader
|
||||
{
|
||||
/**
|
||||
* Register the Autoloader with SPL
|
||||
*
|
||||
*/
|
||||
public static function register()
|
||||
{
|
||||
if (function_exists('__autoload')) {
|
||||
// Register any existing autoloader function with SPL, so we don't get any clashes
|
||||
spl_autoload_register('__autoload');
|
||||
}
|
||||
// Register ourselves with SPL
|
||||
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
||||
return spl_autoload_register(array('PHPExcel_Autoloader', 'load'), true, true);
|
||||
} else {
|
||||
return spl_autoload_register(array('PHPExcel_Autoloader', 'load'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Autoload a class identified by name
|
||||
*
|
||||
* @param string $pClassName Name of the object to load
|
||||
*/
|
||||
public static function load($pClassName)
|
||||
{
|
||||
if ((class_exists($pClassName, false)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
|
||||
// Either already loaded, or not a PHPExcel class request
|
||||
return false;
|
||||
}
|
||||
|
||||
$pClassFilePath = PHPEXCEL_ROOT .
|
||||
str_replace('_', DIRECTORY_SEPARATOR, $pClassName) .
|
||||
'.php';
|
||||
|
||||
if ((file_exists($pClassFilePath) === false) || (is_readable($pClassFilePath) === false)) {
|
||||
// Can't load
|
||||
return false;
|
||||
}
|
||||
|
||||
require($pClassFilePath);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_APC
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_APC extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
if (!apc_store(
|
||||
$this->cachePrefix . $this->currentObjectID . '.cache',
|
||||
serialize($this->currentObject),
|
||||
$this->cacheTime
|
||||
)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception('Failed to store cell ' . $this->currentObjectID . ' in APC');
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @access public
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @access public
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @throws PHPExcel_Exception
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in apc
|
||||
$success = apc_fetch($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in APC, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @access public
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$obj = apc_fetch($this->cachePrefix . $pCoord . '.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in APC, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in APC cache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @access public
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from APC
|
||||
apc_delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @access public
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @throws PHPExcel_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$obj = apc_fetch($this->cachePrefix . $cellID . '.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in APC, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new PHPExcel_Exception('Cell entry ' . $cellID . ' no longer exists in APC');
|
||||
}
|
||||
if (!apc_store($newCachePrefix . $cellID . '.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception('Failed to store cell ' . $cellID . ' in APC');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if ($this->currentObject !== null) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the APC cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent, $arguments)
|
||||
{
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if ($this->cachePrefix === null) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
apc_delete($this->cachePrefix . $cellID . '.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!function_exists('apc_store')) {
|
||||
return false;
|
||||
}
|
||||
if (apc_sma_info() === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_CacheBase
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
abstract class PHPExcel_CachedObjectStorage_CacheBase
|
||||
{
|
||||
/**
|
||||
* Parent worksheet
|
||||
*
|
||||
* @var PHPExcel_Worksheet
|
||||
*/
|
||||
protected $parent;
|
||||
|
||||
/**
|
||||
* The currently active Cell
|
||||
*
|
||||
* @var PHPExcel_Cell
|
||||
*/
|
||||
protected $currentObject = null;
|
||||
|
||||
/**
|
||||
* Coordinate address of the currently active Cell
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentObjectID = null;
|
||||
|
||||
/**
|
||||
* Flag indicating whether the currently active Cell requires saving
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $currentCellIsDirty = true;
|
||||
|
||||
/**
|
||||
* An array of cells or cell pointers for the worksheet cells held in this cache,
|
||||
* and indexed by their coordinate address within the worksheet
|
||||
*
|
||||
* @var array of mixed
|
||||
*/
|
||||
protected $cellCache = array();
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
// Set our parent worksheet.
|
||||
// This is maintained within the cache controller to facilitate re-attaching it to PHPExcel_Cell objects when
|
||||
// they are woken from a serialized state
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent worksheet for this cell collection
|
||||
*
|
||||
* @return PHPExcel_Worksheet
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry exists in the cache
|
||||
return isset($this->cellCache[$pCoord]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
$this->currentCellIsDirty = true;
|
||||
if (isset($this->cellCache[$fromAddress])) {
|
||||
$this->cellCache[$toAddress] = &$this->cellCache[$fromAddress];
|
||||
unset($this->cellCache[$fromAddress]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache
|
||||
*
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function updateCacheData(PHPExcel_Cell $cell)
|
||||
{
|
||||
return $this->addCacheData($cell->getCoordinate(), $cell);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID && !is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
if (is_object($this->cellCache[$pCoord])) {
|
||||
$this->cellCache[$pCoord]->detach();
|
||||
unset($this->cellCache[$pCoord]);
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
return array_keys($this->cellCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the list of all cell addresses currently held in cache by row and column
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSortedCellList()
|
||||
{
|
||||
$sortKeys = array();
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $column, $row);
|
||||
$sortKeys[sprintf('%09d%3s', $row, $column)] = $coord;
|
||||
}
|
||||
ksort($sortKeys);
|
||||
|
||||
return array_values($sortKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column and highest row that have cell records
|
||||
*
|
||||
* @return array Highest column name and highest row number
|
||||
*/
|
||||
public function getHighestRowAndColumn()
|
||||
{
|
||||
// Lookup highest column and highest row
|
||||
$col = array('A' => '1A');
|
||||
$row = array(1);
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
$row[$r] = $r;
|
||||
$col[$c] = strlen($c).$c;
|
||||
}
|
||||
if (!empty($row)) {
|
||||
// Determine highest column and row
|
||||
$highestRow = max($row);
|
||||
$highestColumn = substr(max($col), 1);
|
||||
}
|
||||
|
||||
return array(
|
||||
'row' => $highestRow,
|
||||
'column' => $highestColumn
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the cell address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentAddress()
|
||||
{
|
||||
return $this->currentObjectID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the column address of the currently active cell object
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentColumn()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return $column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the row address of the currently active cell object
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCurrentRow()
|
||||
{
|
||||
sscanf($this->currentObjectID, '%[A-Z]%d', $column, $row);
|
||||
return (integer) $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet column
|
||||
*
|
||||
* @param string $row Return the highest column for the specified row,
|
||||
* or the highest column of any row if no row number is passed
|
||||
* @return string Highest column name
|
||||
*/
|
||||
public function getHighestColumn($row = null)
|
||||
{
|
||||
if ($row == null) {
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['column'];
|
||||
}
|
||||
|
||||
$columnList = array(1);
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
if ($r != $row) {
|
||||
continue;
|
||||
}
|
||||
$columnList[] = PHPExcel_Cell::columnIndexFromString($c);
|
||||
}
|
||||
return PHPExcel_Cell::stringFromColumnIndex(max($columnList) - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get highest worksheet row
|
||||
*
|
||||
* @param string $column Return the highest row for the specified column,
|
||||
* or the highest row of any column if no column letter is passed
|
||||
* @return int Highest row number
|
||||
*/
|
||||
public function getHighestRow($column = null)
|
||||
{
|
||||
if ($column == null) {
|
||||
$colRow = $this->getHighestRowAndColumn();
|
||||
return $colRow['row'];
|
||||
}
|
||||
|
||||
$rowList = array(0);
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
if ($c != $column) {
|
||||
continue;
|
||||
}
|
||||
$rowList[] = $r;
|
||||
}
|
||||
|
||||
return max($rowList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique ID for cache referencing
|
||||
*
|
||||
* @return string Unique Reference
|
||||
*/
|
||||
protected function getUniqueID()
|
||||
{
|
||||
if (function_exists('posix_getpid')) {
|
||||
$baseUnique = posix_getpid();
|
||||
} else {
|
||||
$baseUnique = mt_rand();
|
||||
}
|
||||
return uniqid($baseUnique, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
$this->parent = $parent;
|
||||
if (($this->currentObject !== null) && (is_object($this->currentObject))) {
|
||||
$this->currentObject->attach($this);
|
||||
}
|
||||
} // function copyCellCollection()
|
||||
|
||||
/**
|
||||
* Remove a row, deleting all cells in that row
|
||||
*
|
||||
* @param string $row Row number to remove
|
||||
* @return void
|
||||
*/
|
||||
public function removeRow($row)
|
||||
{
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
if ($r == $row) {
|
||||
$this->deleteCacheData($coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a column, deleting all cells in that column
|
||||
*
|
||||
* @param string $column Column ID to remove
|
||||
* @return void
|
||||
*/
|
||||
public function removeColumn($column)
|
||||
{
|
||||
foreach ($this->getCellList() as $coord) {
|
||||
sscanf($coord, '%[A-Z]%d', $c, $r);
|
||||
if ($c == $column) {
|
||||
$this->deleteCacheData($coord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_DiscISAM
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_DiscISAM extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileName = null;
|
||||
|
||||
/**
|
||||
* File handle for this cache file
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Directory/Folder where the cache file is located
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cacheDirectory = null;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle, 0, SEEK_END);
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = array(
|
||||
'ptr' => ftell($this->fileHandle),
|
||||
'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newFileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
// Copy the existing cell cache file
|
||||
copy($this->fileName, $newFileName);
|
||||
$this->fileName = $newFileName;
|
||||
// Open the copied cell cache file
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->cacheDirectory = ((isset($arguments['dir'])) && ($arguments['dir'] !== null))
|
||||
? $arguments['dir']
|
||||
: PHPExcel_Shared_File::sys_get_temp_dir();
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->fileName = $this->cacheDirectory.'/PHPExcel.'.$baseUnique.'.cache';
|
||||
$this->fileHandle = fopen($this->fileName, 'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
unlink($this->fileName);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_ICache
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
interface PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell);
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache
|
||||
*
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function updateCacheData(PHPExcel_Cell $cell);
|
||||
|
||||
/**
|
||||
* Fetch a cell from cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to retrieve
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function getCacheData($pCoord);
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord);
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord);
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList();
|
||||
|
||||
/**
|
||||
* Get the list of all cell addresses currently held in cache sorted by column and row
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSortedCellList();
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent);
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable();
|
||||
}
|
||||
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_Igbinary
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_Igbinary extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = igbinary_serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
} // function _storeData()
|
||||
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
} // function addCacheData()
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = igbinary_unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
} // function getCacheData()
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
} // function unsetWorksheetCells()
|
||||
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!function_exists('igbinary_serialize')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_Memcache
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_Memcache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
/**
|
||||
* Memcache interface
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $memcache = null;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
if (!$this->memcache->replace($this->cachePrefix . $this->currentObjectID . '.cache', $obj, null, $this->cacheTime)) {
|
||||
if (!$this->memcache->add($this->cachePrefix . $this->currentObjectID . '.cache', $obj, null, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception("Failed to store cell {$this->currentObjectID} in MemCache");
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
} // function _storeData()
|
||||
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
} // function addCacheData()
|
||||
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in Memcache
|
||||
$success = $this->memcache->get($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in MemCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$obj = $this->memcache->get($this->cachePrefix . $pCoord . '.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception("Cell entry {$pCoord} no longer exists in MemCache");
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Memcache
|
||||
$this->memcache->delete($this->cachePrefix . $pCoord . '.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$obj = $this->memcache->get($this->cachePrefix.$cellID.'.cache');
|
||||
if ($obj === false) {
|
||||
// Entry no longer exists in Memcache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new PHPExcel_Exception("Cell entry {$cellID} no longer exists in MemCache");
|
||||
}
|
||||
if (!$this->memcache->add($newCachePrefix . $cellID . '.cache', $obj, null, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception("Failed to store cell {$cellID} in MemCache");
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the Memcache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent, $arguments)
|
||||
{
|
||||
$memcacheServer = (isset($arguments['memcacheServer'])) ? $arguments['memcacheServer'] : 'localhost';
|
||||
$memcachePort = (isset($arguments['memcachePort'])) ? $arguments['memcachePort'] : 11211;
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8) . '.';
|
||||
|
||||
// Set a new Memcache object and connect to the Memcache server
|
||||
$this->memcache = new Memcache();
|
||||
if (!$this->memcache->addServer($memcacheServer, $memcachePort, false, 50, 5, 5, true, array($this, 'failureCallback'))) {
|
||||
throw new PHPExcel_Exception("Could not connect to MemCache server at {$memcacheServer}:{$memcachePort}");
|
||||
}
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Memcache error handler
|
||||
*
|
||||
* @param string $host Memcache server
|
||||
* @param integer $port Memcache port
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function failureCallback($host, $port)
|
||||
{
|
||||
throw new PHPExcel_Exception("memcache {$host}:{$port} failed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
$this->memcache->delete($this->cachePrefix.$cellID . '.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!function_exists('memcache_add')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_Memory
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_Memory extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Dummy method callable from CacheBase, but unused by Memory cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
$this->cellCache[$pCoord] = $cell;
|
||||
|
||||
// Set current entry to the new/updated entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
$this->currentObjectID = null;
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
// Return requested entry
|
||||
return $this->cellCache[$pCoord];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
|
||||
$newCollection = array();
|
||||
foreach ($this->cellCache as $k => &$cell) {
|
||||
$newCollection[$k] = clone $cell;
|
||||
$newCollection[$k]->attach($this);
|
||||
}
|
||||
|
||||
$this->cellCache = $newCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
// Because cells are all stored as intact objects in memory, we need to detach each one from the parent
|
||||
foreach ($this->cellCache as $k => &$cell) {
|
||||
$cell->detach();
|
||||
$this->cellCache[$k] = null;
|
||||
}
|
||||
unset($cell);
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_MemoryGZip
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_MemoryGZip extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = gzdeflate(serialize($this->currentObject));
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize(gzinflate($this->cellCache[$pCoord]));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_MemorySerialized
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_MemorySerialized extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = serialize($this->currentObject);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($this->cellCache[$pCoord]);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_PHPTemp
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_PHPTemp extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Name of the file for this cache
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $fileHandle = null;
|
||||
|
||||
/**
|
||||
* Memory limit to use before reverting to file cache
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $memoryCacheSize = null;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
fseek($this->fileHandle, 0, SEEK_END);
|
||||
|
||||
$this->cellCache[$this->currentObjectID] = array(
|
||||
'ptr' => ftell($this->fileHandle),
|
||||
'sz' => fwrite($this->fileHandle, serialize($this->currentObject))
|
||||
);
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
if (!isset($this->cellCache[$pCoord])) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
fseek($this->fileHandle, $this->cellCache[$pCoord]['ptr']);
|
||||
$this->currentObject = unserialize(fread($this->fileHandle, $this->cellCache[$pCoord]['sz']));
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Open a new stream for the cell cache data
|
||||
$newFileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
|
||||
// Copy the existing cell cache data to the new stream
|
||||
fseek($this->fileHandle, 0);
|
||||
while (!feof($this->fileHandle)) {
|
||||
fwrite($newFileHandle, fread($this->fileHandle, 1024));
|
||||
}
|
||||
$this->fileHandle = $newFileHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the php://temp file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent, $arguments)
|
||||
{
|
||||
$this->memoryCacheSize = (isset($arguments['memoryCacheSize'])) ? $arguments['memoryCacheSize'] : '1MB';
|
||||
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->fileHandle)) {
|
||||
$this->fileHandle = fopen('php://temp/maxmemory:' . $this->memoryCacheSize, 'a+');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->fileHandle)) {
|
||||
fclose($this->fileHandle);
|
||||
}
|
||||
$this->fileHandle = null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_SQLite
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_SQLite extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
if (!$this->DBHandle->queryExec("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES('".$this->currentObjectID."','".sqlite_escape_string(serialize($this->currentObject))."')")) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$query = "SELECT value FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$cellResult = $cellResultSet->fetchSingle();
|
||||
$this->currentObject = unserialize($cellResult);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "SELECT id FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
$cellResultSet = $this->DBHandle->query($query, SQLITE_ASSOC);
|
||||
if ($cellResultSet === false) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
} elseif ($cellResultSet->numRows() == 0) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$pCoord."'";
|
||||
if (!$this->DBHandle->queryExec($query)) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$query = "DELETE FROM kvp_".$this->TableName." WHERE id='".$toAddress."'";
|
||||
$result = $this->DBHandle->exec($query);
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$query = "UPDATE kvp_".$this->TableName." SET id='".$toAddress."' WHERE id='".$fromAddress."'";
|
||||
$result = $this->DBHandle->exec($query);
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->unbufferedQuery($query, SQLITE_ASSOC);
|
||||
if ($cellIdsResult === false) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
$cellKeys = array();
|
||||
foreach ($cellIdsResult as $row) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.', '_', $this->getUniqueID());
|
||||
if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName)
|
||||
) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$_DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLiteDatabase($_DBName);
|
||||
if ($this->DBHandle === false) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
if (!$this->DBHandle->queryExec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) {
|
||||
throw new PHPExcel_Exception(sqlite_error_string($this->DBHandle->lastError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->queryExec('DROP TABLE kvp_'.$this->TableName);
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!function_exists('sqlite_open')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,346 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_SQLite3
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_SQLite3 extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Database table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $TableName = null;
|
||||
|
||||
/**
|
||||
* Database handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $DBHandle = null;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 select query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $selectQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 insert query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $insertQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 update query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $updateQuery;
|
||||
|
||||
/**
|
||||
* Prepared statement for a SQLite3 delete query
|
||||
*
|
||||
* @var SQLite3Stmt
|
||||
*/
|
||||
private $deleteQuery;
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$this->insertQuery->bindValue('id', $this->currentObjectID, SQLITE3_TEXT);
|
||||
$this->insertQuery->bindValue('data', serialize($this->currentObject), SQLITE3_BLOB);
|
||||
$result = $this->insertQuery->execute();
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
if ($cellData === false) {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
|
||||
$this->currentObject = unserialize($cellData['value']);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->selectQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$cellResult = $this->selectQuery->execute();
|
||||
if ($cellResult === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
$cellData = $cellResult->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
return ($cellData === false) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
// Check if the requested entry exists in the cache
|
||||
$this->deleteQuery->bindValue('id', $pCoord, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a cell object from one address to another
|
||||
*
|
||||
* @param string $fromAddress Current address of the cell to move
|
||||
* @param string $toAddress Destination address of the cell to move
|
||||
* @return boolean
|
||||
*/
|
||||
public function moveCell($fromAddress, $toAddress)
|
||||
{
|
||||
if ($fromAddress === $this->currentObjectID) {
|
||||
$this->currentObjectID = $toAddress;
|
||||
}
|
||||
|
||||
$this->deleteQuery->bindValue('id', $toAddress, SQLITE3_TEXT);
|
||||
$result = $this->deleteQuery->execute();
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$this->updateQuery->bindValue('toid', $toAddress, SQLITE3_TEXT);
|
||||
$this->updateQuery->bindValue('fromid', $fromAddress, SQLITE3_TEXT);
|
||||
$result = $this->updateQuery->execute();
|
||||
if ($result === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
$query = "SELECT id FROM kvp_".$this->TableName;
|
||||
$cellIdsResult = $this->DBHandle->query($query);
|
||||
if ($cellIdsResult === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
$cellKeys = array();
|
||||
while ($row = $cellIdsResult->fetchArray(SQLITE3_ASSOC)) {
|
||||
$cellKeys[] = $row['id'];
|
||||
}
|
||||
|
||||
return $cellKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
$this->currentCellIsDirty;
|
||||
$this->storeData();
|
||||
|
||||
// Get a new id for the new table name
|
||||
$tableName = str_replace('.', '_', $this->getUniqueID());
|
||||
if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$tableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)
|
||||
AS SELECT * FROM kvp_'.$this->TableName)
|
||||
) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
|
||||
// Copy the existing cell cache file
|
||||
$this->TableName = $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
|
||||
// Close down the temporary cache file
|
||||
$this->__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::__construct($parent);
|
||||
if (is_null($this->DBHandle)) {
|
||||
$this->TableName = str_replace('.', '_', $this->getUniqueID());
|
||||
$_DBName = ':memory:';
|
||||
|
||||
$this->DBHandle = new SQLite3($_DBName);
|
||||
if ($this->DBHandle === false) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
if (!$this->DBHandle->exec('CREATE TABLE kvp_'.$this->TableName.' (id VARCHAR(12) PRIMARY KEY, value BLOB)')) {
|
||||
throw new PHPExcel_Exception($this->DBHandle->lastErrorMsg());
|
||||
}
|
||||
}
|
||||
|
||||
$this->selectQuery = $this->DBHandle->prepare("SELECT value FROM kvp_".$this->TableName." WHERE id = :id");
|
||||
$this->insertQuery = $this->DBHandle->prepare("INSERT OR REPLACE INTO kvp_".$this->TableName." VALUES(:id,:data)");
|
||||
$this->updateQuery = $this->DBHandle->prepare("UPDATE kvp_".$this->TableName." SET id=:toId WHERE id=:fromId");
|
||||
$this->deleteQuery = $this->DBHandle->prepare("DELETE FROM kvp_".$this->TableName." WHERE id = :id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if (!is_null($this->DBHandle)) {
|
||||
$this->DBHandle->exec('DROP TABLE kvp_'.$this->TableName);
|
||||
$this->DBHandle->close();
|
||||
}
|
||||
$this->DBHandle = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!class_exists('SQLite3', false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorage_Wincache
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorage_Wincache extends PHPExcel_CachedObjectStorage_CacheBase implements PHPExcel_CachedObjectStorage_ICache
|
||||
{
|
||||
/**
|
||||
* Prefix used to uniquely identify cache data for this worksheet
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $cachePrefix = null;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
private $cacheTime = 600;
|
||||
|
||||
|
||||
/**
|
||||
* Store cell data in cache for the current cell object if it's "dirty",
|
||||
* and the 'nullify' the current cell object
|
||||
*
|
||||
* @return void
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
protected function storeData()
|
||||
{
|
||||
if ($this->currentCellIsDirty && !empty($this->currentObjectID)) {
|
||||
$this->currentObject->detach();
|
||||
|
||||
$obj = serialize($this->currentObject);
|
||||
if (wincache_ucache_exists($this->cachePrefix.$this->currentObjectID.'.cache')) {
|
||||
if (!wincache_ucache_set($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
} else {
|
||||
if (!wincache_ucache_add($this->cachePrefix.$this->currentObjectID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception('Failed to store cell '.$this->currentObjectID.' in WinCache');
|
||||
}
|
||||
}
|
||||
$this->currentCellIsDirty = false;
|
||||
}
|
||||
|
||||
$this->currentObjectID = $this->currentObject = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or Update a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to update
|
||||
* @param PHPExcel_Cell $cell Cell to update
|
||||
* @return PHPExcel_Cell
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function addCacheData($pCoord, PHPExcel_Cell $cell)
|
||||
{
|
||||
if (($pCoord !== $this->currentObjectID) && ($this->currentObjectID !== null)) {
|
||||
$this->storeData();
|
||||
}
|
||||
$this->cellCache[$pCoord] = true;
|
||||
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = $cell;
|
||||
$this->currentCellIsDirty = true;
|
||||
|
||||
return $cell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a value set in the current PHPExcel_CachedObjectStorage_ICache for an indexed cell?
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to check
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDataSet($pCoord)
|
||||
{
|
||||
// Check if the requested entry is the current object, or exists in the cache
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
if ($this->currentObjectID == $pCoord) {
|
||||
return true;
|
||||
}
|
||||
// Check if the requested entry still exists in cache
|
||||
$success = wincache_ucache_exists($this->cachePrefix.$pCoord.'.cache');
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in Wincache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get cell at a specific coordinate
|
||||
*
|
||||
* @param string $pCoord Coordinate of the cell
|
||||
* @throws PHPExcel_Exception
|
||||
* @return PHPExcel_Cell Cell that was found, or null if not found
|
||||
*/
|
||||
public function getCacheData($pCoord)
|
||||
{
|
||||
if ($pCoord === $this->currentObjectID) {
|
||||
return $this->currentObject;
|
||||
}
|
||||
$this->storeData();
|
||||
|
||||
// Check if the entry that has been requested actually exists
|
||||
$obj = null;
|
||||
if (parent::isDataSet($pCoord)) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$pCoord.'.cache', $success);
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($pCoord);
|
||||
throw new PHPExcel_Exception('Cell entry '.$pCoord.' no longer exists in WinCache');
|
||||
}
|
||||
} else {
|
||||
// Return null if requested entry doesn't exist in cache
|
||||
return null;
|
||||
}
|
||||
|
||||
// Set current entry to the requested entry
|
||||
$this->currentObjectID = $pCoord;
|
||||
$this->currentObject = unserialize($obj);
|
||||
// Re-attach this as the cell's parent
|
||||
$this->currentObject->attach($this);
|
||||
|
||||
// Return requested entry
|
||||
return $this->currentObject;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all cell addresses currently held in cache
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCellList()
|
||||
{
|
||||
if ($this->currentObjectID !== null) {
|
||||
$this->storeData();
|
||||
}
|
||||
|
||||
return parent::getCellList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a cell in cache identified by coordinate address
|
||||
*
|
||||
* @param string $pCoord Coordinate address of the cell to delete
|
||||
* @throws PHPExcel_Exception
|
||||
*/
|
||||
public function deleteCacheData($pCoord)
|
||||
{
|
||||
// Delete the entry from Wincache
|
||||
wincache_ucache_delete($this->cachePrefix.$pCoord.'.cache');
|
||||
|
||||
// Delete the entry from our cell address array
|
||||
parent::deleteCacheData($pCoord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone the cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The new worksheet
|
||||
* @return void
|
||||
*/
|
||||
public function copyCellCollection(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
parent::copyCellCollection($parent);
|
||||
// Get a new id for the new file name
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$newCachePrefix = substr(md5($baseUnique), 0, 8) . '.';
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
if ($cellID != $this->currentObjectID) {
|
||||
$success = false;
|
||||
$obj = wincache_ucache_get($this->cachePrefix.$cellID.'.cache', $success);
|
||||
if ($success === false) {
|
||||
// Entry no longer exists in WinCache, so clear it from the cache array
|
||||
parent::deleteCacheData($cellID);
|
||||
throw new PHPExcel_Exception('Cell entry '.$cellID.' no longer exists in Wincache');
|
||||
}
|
||||
if (!wincache_ucache_add($newCachePrefix.$cellID.'.cache', $obj, $this->cacheTime)) {
|
||||
$this->__destruct();
|
||||
throw new PHPExcel_Exception('Failed to store cell '.$cellID.' in Wincache');
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cachePrefix = $newCachePrefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clear the cell collection and disconnect from our parent
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function unsetWorksheetCells()
|
||||
{
|
||||
if (!is_null($this->currentObject)) {
|
||||
$this->currentObject->detach();
|
||||
$this->currentObject = $this->currentObjectID = null;
|
||||
}
|
||||
|
||||
// Flush the WinCache cache
|
||||
$this->__destruct();
|
||||
|
||||
$this->cellCache = array();
|
||||
|
||||
// detach ourself from the worksheet, so that it can then delete this object successfully
|
||||
$this->parent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise this new cell collection
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent The worksheet for this cell collection
|
||||
* @param array of mixed $arguments Additional initialisation arguments
|
||||
*/
|
||||
public function __construct(PHPExcel_Worksheet $parent, $arguments)
|
||||
{
|
||||
$cacheTime = (isset($arguments['cacheTime'])) ? $arguments['cacheTime'] : 600;
|
||||
|
||||
if (is_null($this->cachePrefix)) {
|
||||
$baseUnique = $this->getUniqueID();
|
||||
$this->cachePrefix = substr(md5($baseUnique), 0, 8).'.';
|
||||
$this->cacheTime = $cacheTime;
|
||||
|
||||
parent::__construct($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy this cell collection
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$cacheList = $this->getCellList();
|
||||
foreach ($cacheList as $cellID) {
|
||||
wincache_ucache_delete($this->cachePrefix.$cellID.'.cache');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify whether the caching method is currently available
|
||||
* Some methods are dependent on the availability of certain extensions being enabled in the PHP build
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function cacheMethodIsAvailable()
|
||||
{
|
||||
if (!function_exists('wincache_ucache_add')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CachedObjectStorageFactory
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_CachedObjectStorage
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CachedObjectStorageFactory
|
||||
{
|
||||
const cache_in_memory = 'Memory';
|
||||
const cache_in_memory_gzip = 'MemoryGZip';
|
||||
const cache_in_memory_serialized = 'MemorySerialized';
|
||||
const cache_igbinary = 'Igbinary';
|
||||
const cache_to_discISAM = 'DiscISAM';
|
||||
const cache_to_apc = 'APC';
|
||||
const cache_to_memcache = 'Memcache';
|
||||
const cache_to_phpTemp = 'PHPTemp';
|
||||
const cache_to_wincache = 'Wincache';
|
||||
const cache_to_sqlite = 'SQLite';
|
||||
const cache_to_sqlite3 = 'SQLite3';
|
||||
|
||||
/**
|
||||
* Name of the method used for cell cacheing
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $cacheStorageMethod = null;
|
||||
|
||||
/**
|
||||
* Name of the class used for cell cacheing
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $cacheStorageClass = null;
|
||||
|
||||
/**
|
||||
* List of all possible cache storage methods
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private static $storageMethods = array(
|
||||
self::cache_in_memory,
|
||||
self::cache_in_memory_gzip,
|
||||
self::cache_in_memory_serialized,
|
||||
self::cache_igbinary,
|
||||
self::cache_to_phpTemp,
|
||||
self::cache_to_discISAM,
|
||||
self::cache_to_apc,
|
||||
self::cache_to_memcache,
|
||||
self::cache_to_wincache,
|
||||
self::cache_to_sqlite,
|
||||
self::cache_to_sqlite3,
|
||||
);
|
||||
|
||||
/**
|
||||
* Default arguments for each cache storage method
|
||||
*
|
||||
* @var array of mixed array
|
||||
*/
|
||||
private static $storageMethodDefaultParameters = array(
|
||||
self::cache_in_memory => array(
|
||||
),
|
||||
self::cache_in_memory_gzip => array(
|
||||
),
|
||||
self::cache_in_memory_serialized => array(
|
||||
),
|
||||
self::cache_igbinary => array(
|
||||
),
|
||||
self::cache_to_phpTemp => array( 'memoryCacheSize' => '1MB'
|
||||
),
|
||||
self::cache_to_discISAM => array( 'dir' => null
|
||||
),
|
||||
self::cache_to_apc => array( 'cacheTime' => 600
|
||||
),
|
||||
self::cache_to_memcache => array( 'memcacheServer' => 'localhost',
|
||||
'memcachePort' => 11211,
|
||||
'cacheTime' => 600
|
||||
),
|
||||
self::cache_to_wincache => array( 'cacheTime' => 600
|
||||
),
|
||||
self::cache_to_sqlite => array(
|
||||
),
|
||||
self::cache_to_sqlite3 => array(
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Arguments for the active cache storage method
|
||||
*
|
||||
* @var array of mixed array
|
||||
*/
|
||||
private static $storageMethodParameters = array();
|
||||
|
||||
/**
|
||||
* Return the current cache storage method
|
||||
*
|
||||
* @return string|null
|
||||
**/
|
||||
public static function getCacheStorageMethod()
|
||||
{
|
||||
return self::$cacheStorageMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current cache storage class
|
||||
*
|
||||
* @return PHPExcel_CachedObjectStorage_ICache|null
|
||||
**/
|
||||
public static function getCacheStorageClass()
|
||||
{
|
||||
return self::$cacheStorageClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of all possible cache storage methods
|
||||
*
|
||||
* @return string[]
|
||||
**/
|
||||
public static function getAllCacheStorageMethods()
|
||||
{
|
||||
return self::$storageMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of all available cache storage methods
|
||||
*
|
||||
* @return string[]
|
||||
**/
|
||||
public static function getCacheStorageMethods()
|
||||
{
|
||||
$activeMethods = array();
|
||||
foreach (self::$storageMethods as $storageMethod) {
|
||||
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $storageMethod;
|
||||
if (call_user_func(array($cacheStorageClass, 'cacheMethodIsAvailable'))) {
|
||||
$activeMethods[] = $storageMethod;
|
||||
}
|
||||
}
|
||||
return $activeMethods;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify the cache storage method to use
|
||||
*
|
||||
* @param string $method Name of the method to use for cell cacheing
|
||||
* @param array of mixed $arguments Additional arguments to pass to the cell caching class
|
||||
* when instantiating
|
||||
* @return boolean
|
||||
**/
|
||||
public static function initialize($method = self::cache_in_memory, $arguments = array())
|
||||
{
|
||||
if (!in_array($method, self::$storageMethods)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cacheStorageClass = 'PHPExcel_CachedObjectStorage_'.$method;
|
||||
if (!call_user_func(array( $cacheStorageClass,
|
||||
'cacheMethodIsAvailable'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$storageMethodParameters[$method] = self::$storageMethodDefaultParameters[$method];
|
||||
foreach ($arguments as $k => $v) {
|
||||
if (array_key_exists($k, self::$storageMethodParameters[$method])) {
|
||||
self::$storageMethodParameters[$method][$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
if (self::$cacheStorageMethod === null) {
|
||||
self::$cacheStorageClass = 'PHPExcel_CachedObjectStorage_' . $method;
|
||||
self::$cacheStorageMethod = $method;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the cache storage
|
||||
*
|
||||
* @param PHPExcel_Worksheet $parent Enable cell caching for this worksheet
|
||||
* @return PHPExcel_CachedObjectStorage_ICache
|
||||
**/
|
||||
public static function getInstance(PHPExcel_Worksheet $parent)
|
||||
{
|
||||
$cacheMethodIsAvailable = true;
|
||||
if (self::$cacheStorageMethod === null) {
|
||||
$cacheMethodIsAvailable = self::initialize();
|
||||
}
|
||||
|
||||
if ($cacheMethodIsAvailable) {
|
||||
$instance = new self::$cacheStorageClass(
|
||||
$parent,
|
||||
self::$storageMethodParameters[self::$cacheStorageMethod]
|
||||
);
|
||||
if ($instance !== null) {
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the cache storage
|
||||
*
|
||||
**/
|
||||
public static function finalize()
|
||||
{
|
||||
self::$cacheStorageMethod = null;
|
||||
self::$cacheStorageClass = null;
|
||||
self::$storageMethodParameters = array();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CalcEngine_CyclicReferenceStack
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CalcEngine_CyclicReferenceStack
|
||||
{
|
||||
/**
|
||||
* The call stack for calculated cells
|
||||
*
|
||||
* @var mixed[]
|
||||
*/
|
||||
private $stack = array();
|
||||
|
||||
/**
|
||||
* Return the number of entries on the stack
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a new entry onto the stack
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function push($value)
|
||||
{
|
||||
$this->stack[$value] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the last entry from the stack
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function pop()
|
||||
{
|
||||
return array_pop($this->stack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to see if a specified entry exists on the stack
|
||||
*
|
||||
* @param mixed $value The value to test
|
||||
*/
|
||||
public function onStack($value)
|
||||
{
|
||||
return isset($this->stack[$value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the stack
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->stack = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all entries on the stack
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function showStack()
|
||||
{
|
||||
return $this->stack;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_CalcEngine_Logger
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_CalcEngine_Logger
|
||||
{
|
||||
/**
|
||||
* Flag to determine whether a debug log should be generated by the calculation engine
|
||||
* If true, then a debug log will be generated
|
||||
* If false, then a debug log will not be generated
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $writeDebugLog = false;
|
||||
|
||||
/**
|
||||
* Flag to determine whether a debug log should be echoed by the calculation engine
|
||||
* If true, then a debug log will be echoed
|
||||
* If false, then a debug log will not be echoed
|
||||
* A debug log can only be echoed if it is generated
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $echoDebugLog = false;
|
||||
|
||||
/**
|
||||
* The debug log generated by the calculation engine
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
private $debugLog = array();
|
||||
|
||||
/**
|
||||
* The calculation engine cell reference stack
|
||||
*
|
||||
* @var PHPExcel_CalcEngine_CyclicReferenceStack
|
||||
*/
|
||||
private $cellStack;
|
||||
|
||||
/**
|
||||
* Instantiate a Calculation engine logger
|
||||
*
|
||||
* @param PHPExcel_CalcEngine_CyclicReferenceStack $stack
|
||||
*/
|
||||
public function __construct(PHPExcel_CalcEngine_CyclicReferenceStack $stack)
|
||||
{
|
||||
$this->cellStack = $stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Calculation engine logging
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*/
|
||||
public function setWriteDebugLog($pValue = false)
|
||||
{
|
||||
$this->writeDebugLog = $pValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether calculation engine logging is enabled or disabled
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getWriteDebugLog()
|
||||
{
|
||||
return $this->writeDebugLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable echoing of debug log information
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*/
|
||||
public function setEchoDebugLog($pValue = false)
|
||||
{
|
||||
$this->echoDebugLog = $pValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether echoing of debug log information is enabled or disabled
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getEchoDebugLog()
|
||||
{
|
||||
return $this->echoDebugLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an entry to the calculation engine debug log
|
||||
*/
|
||||
public function writeDebugLog()
|
||||
{
|
||||
// Only write the debug log if logging is enabled
|
||||
if ($this->writeDebugLog) {
|
||||
$message = implode(func_get_args());
|
||||
$cellReference = implode(' -> ', $this->cellStack->showStack());
|
||||
if ($this->echoDebugLog) {
|
||||
echo $cellReference,
|
||||
($this->cellStack->count() > 0 ? ' => ' : ''),
|
||||
$message,
|
||||
PHP_EOL;
|
||||
}
|
||||
$this->debugLog[] = $cellReference .
|
||||
($this->cellStack->count() > 0 ? ' => ' : '') .
|
||||
$message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the calculation engine debug log
|
||||
*/
|
||||
public function clearLog()
|
||||
{
|
||||
$this->debugLog = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the calculation engine debug log
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getLog()
|
||||
{
|
||||
return $this->debugLog;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,676 @@
|
||||
<?php
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Calculation_Database
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_Calculation_Database
|
||||
{
|
||||
/**
|
||||
* fieldExtract
|
||||
*
|
||||
* Extracts the column ID to use for the data field.
|
||||
*
|
||||
* @access private
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param mixed $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @return string|NULL
|
||||
*
|
||||
*/
|
||||
private static function fieldExtract($database, $field)
|
||||
{
|
||||
$field = strtoupper(PHPExcel_Calculation_Functions::flattenSingleValue($field));
|
||||
$fieldNames = array_map('strtoupper', array_shift($database));
|
||||
|
||||
if (is_numeric($field)) {
|
||||
$keys = array_keys($fieldNames);
|
||||
return $keys[$field-1];
|
||||
}
|
||||
$key = array_search($field, $fieldNames);
|
||||
return ($key) ? $key : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* filter
|
||||
*
|
||||
* Parses the selection criteria, extracts the database rows that match those criteria, and
|
||||
* returns that subset of rows.
|
||||
*
|
||||
* @access private
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return array of mixed
|
||||
*
|
||||
*/
|
||||
private static function filter($database, $criteria)
|
||||
{
|
||||
$fieldNames = array_shift($database);
|
||||
$criteriaNames = array_shift($criteria);
|
||||
|
||||
// Convert the criteria into a set of AND/OR conditions with [:placeholders]
|
||||
$testConditions = $testValues = array();
|
||||
$testConditionsCount = 0;
|
||||
foreach ($criteriaNames as $key => $criteriaName) {
|
||||
$testCondition = array();
|
||||
$testConditionCount = 0;
|
||||
foreach ($criteria as $row => $criterion) {
|
||||
if ($criterion[$key] > '') {
|
||||
$testCondition[] = '[:'.$criteriaName.']'.PHPExcel_Calculation_Functions::ifCondition($criterion[$key]);
|
||||
$testConditionCount++;
|
||||
}
|
||||
}
|
||||
if ($testConditionCount > 1) {
|
||||
$testConditions[] = 'OR(' . implode(',', $testCondition) . ')';
|
||||
$testConditionsCount++;
|
||||
} elseif ($testConditionCount == 1) {
|
||||
$testConditions[] = $testCondition[0];
|
||||
$testConditionsCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($testConditionsCount > 1) {
|
||||
$testConditionSet = 'AND(' . implode(',', $testConditions) . ')';
|
||||
} elseif ($testConditionsCount == 1) {
|
||||
$testConditionSet = $testConditions[0];
|
||||
}
|
||||
|
||||
// Loop through each row of the database
|
||||
foreach ($database as $dataRow => $dataValues) {
|
||||
// Substitute actual values from the database row for our [:placeholders]
|
||||
$testConditionList = $testConditionSet;
|
||||
foreach ($criteriaNames as $key => $criteriaName) {
|
||||
$k = array_search($criteriaName, $fieldNames);
|
||||
if (isset($dataValues[$k])) {
|
||||
$dataValue = $dataValues[$k];
|
||||
$dataValue = (is_string($dataValue)) ? PHPExcel_Calculation::wrapResult(strtoupper($dataValue)) : $dataValue;
|
||||
$testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList);
|
||||
}
|
||||
}
|
||||
// evaluate the criteria against the row data
|
||||
$result = PHPExcel_Calculation::getInstance()->_calculateFormulaValue('='.$testConditionList);
|
||||
// If the row failed to meet the criteria, remove it from the database
|
||||
if (!$result) {
|
||||
unset($database[$dataRow]);
|
||||
}
|
||||
}
|
||||
|
||||
return $database;
|
||||
}
|
||||
|
||||
|
||||
private static function getFilteredColumn($database, $field, $criteria)
|
||||
{
|
||||
// reduce the database to a set of rows that match all the criteria
|
||||
$database = self::filter($database, $criteria);
|
||||
// extract an array of values for the requested column
|
||||
$colData = array();
|
||||
foreach ($database as $row) {
|
||||
$colData[] = $row[$field];
|
||||
}
|
||||
|
||||
return $colData;
|
||||
}
|
||||
|
||||
/**
|
||||
* DAVERAGE
|
||||
*
|
||||
* Averages the values in a column of a list or database that match conditions you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DAVERAGE(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DAVERAGE($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::AVERAGE(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DCOUNT
|
||||
*
|
||||
* Counts the cells that contain numbers in a column of a list or database that match conditions
|
||||
* that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DCOUNT(database,[field],criteria)
|
||||
*
|
||||
* Excel Function:
|
||||
* DAVERAGE(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return integer
|
||||
*
|
||||
* @TODO The field argument is optional. If field is omitted, DCOUNT counts all records in the
|
||||
* database that match the criteria.
|
||||
*
|
||||
*/
|
||||
public static function DCOUNT($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::COUNT(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DCOUNTA
|
||||
*
|
||||
* Counts the nonblank cells in a column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DCOUNTA(database,[field],criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return integer
|
||||
*
|
||||
* @TODO The field argument is optional. If field is omitted, DCOUNTA counts all records in the
|
||||
* database that match the criteria.
|
||||
*
|
||||
*/
|
||||
public static function DCOUNTA($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// reduce the database to a set of rows that match all the criteria
|
||||
$database = self::filter($database, $criteria);
|
||||
// extract an array of values for the requested column
|
||||
$colData = array();
|
||||
foreach ($database as $row) {
|
||||
$colData[] = $row[$field];
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::COUNTA(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DGET
|
||||
*
|
||||
* Extracts a single value from a column of a list or database that matches conditions that you
|
||||
* specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DGET(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return mixed
|
||||
*
|
||||
*/
|
||||
public static function DGET($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
$colData = self::getFilteredColumn($database, $field, $criteria);
|
||||
if (count($colData) > 1) {
|
||||
return PHPExcel_Calculation_Functions::NaN();
|
||||
}
|
||||
|
||||
return $colData[0];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DMAX
|
||||
*
|
||||
* Returns the largest number in a column of a list or database that matches conditions you that
|
||||
* specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DMAX(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DMAX($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::MAX(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DMIN
|
||||
*
|
||||
* Returns the smallest number in a column of a list or database that matches conditions you that
|
||||
* specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DMIN(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DMIN($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::MIN(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DPRODUCT
|
||||
*
|
||||
* Multiplies the values in a column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DPRODUCT(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DPRODUCT($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_MathTrig::PRODUCT(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DSTDEV
|
||||
*
|
||||
* Estimates the standard deviation of a population based on a sample by using the numbers in a
|
||||
* column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DSTDEV(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DSTDEV($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::STDEV(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DSTDEVP
|
||||
*
|
||||
* Calculates the standard deviation of a population based on the entire population by using the
|
||||
* numbers in a column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DSTDEVP(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DSTDEVP($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::STDEVP(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DSUM
|
||||
*
|
||||
* Adds the numbers in a column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DSUM(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DSUM($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_MathTrig::SUM(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DVAR
|
||||
*
|
||||
* Estimates the variance of a population based on a sample by using the numbers in a column
|
||||
* of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DVAR(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DVAR($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::VARFunc(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* DVARP
|
||||
*
|
||||
* Calculates the variance of a population based on the entire population by using the numbers
|
||||
* in a column of a list or database that match conditions that you specify.
|
||||
*
|
||||
* Excel Function:
|
||||
* DVARP(database,field,criteria)
|
||||
*
|
||||
* @access public
|
||||
* @category Database Functions
|
||||
* @param mixed[] $database The range of cells that makes up the list or database.
|
||||
* A database is a list of related data in which rows of related
|
||||
* information are records, and columns of data are fields. The
|
||||
* first row of the list contains labels for each column.
|
||||
* @param string|integer $field Indicates which column is used in the function. Enter the
|
||||
* column label enclosed between double quotation marks, such as
|
||||
* "Age" or "Yield," or a number (without quotation marks) that
|
||||
* represents the position of the column within the list: 1 for
|
||||
* the first column, 2 for the second column, and so on.
|
||||
* @param mixed[] $criteria The range of cells that contains the conditions you specify.
|
||||
* You can use any range for the criteria argument, as long as it
|
||||
* includes at least one column label and at least one cell below
|
||||
* the column label in which you specify a condition for the
|
||||
* column.
|
||||
* @return float
|
||||
*
|
||||
*/
|
||||
public static function DVARP($database, $field, $criteria)
|
||||
{
|
||||
$field = self::fieldExtract($database, $field);
|
||||
if (is_null($field)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return
|
||||
return PHPExcel_Calculation_Statistical::VARP(
|
||||
self::getFilteredColumn($database, $field, $criteria)
|
||||
);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_Calculation_Exception
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_Calculation_Exception extends PHPExcel_Exception
|
||||
{
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
* @param mixed $code
|
||||
* @param mixed $string
|
||||
* @param mixed $file
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context)
|
||||
{
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHPExcel_Calculation_ExceptionHandler
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
class PHPExcel_Calculation_ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* Register errorhandler
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
set_error_handler(array('PHPExcel_Calculation_Exception', 'errorHandlerCallback'), E_ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister errorhandler
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,622 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
PARTLY BASED ON:
|
||||
Copyright (c) 2007 E. W. Bachtal, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
The software is provided "as is", without warranty of any kind, express or implied, including but not
|
||||
limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In
|
||||
no event shall the authors or copyright holders be liable for any claim, damages or other liability,
|
||||
whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
|
||||
software or the use or other dealings in the software.
|
||||
|
||||
http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html
|
||||
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Calculation_FormulaParser
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
class PHPExcel_Calculation_FormulaParser
|
||||
{
|
||||
/* Character constants */
|
||||
const QUOTE_DOUBLE = '"';
|
||||
const QUOTE_SINGLE = '\'';
|
||||
const BRACKET_CLOSE = ']';
|
||||
const BRACKET_OPEN = '[';
|
||||
const BRACE_OPEN = '{';
|
||||
const BRACE_CLOSE = '}';
|
||||
const PAREN_OPEN = '(';
|
||||
const PAREN_CLOSE = ')';
|
||||
const SEMICOLON = ';';
|
||||
const WHITESPACE = ' ';
|
||||
const COMMA = ',';
|
||||
const ERROR_START = '#';
|
||||
|
||||
const OPERATORS_SN = "+-";
|
||||
const OPERATORS_INFIX = "+-*/^&=><";
|
||||
const OPERATORS_POSTFIX = "%";
|
||||
|
||||
/**
|
||||
* Formula
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $formula;
|
||||
|
||||
/**
|
||||
* Tokens
|
||||
*
|
||||
* @var PHPExcel_Calculation_FormulaToken[]
|
||||
*/
|
||||
private $tokens = array();
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Calculation_FormulaParser
|
||||
*
|
||||
* @param string $pFormula Formula to parse
|
||||
* @throws PHPExcel_Calculation_Exception
|
||||
*/
|
||||
public function __construct($pFormula = '')
|
||||
{
|
||||
// Check parameters
|
||||
if (is_null($pFormula)) {
|
||||
throw new PHPExcel_Calculation_Exception("Invalid parameter passed: formula");
|
||||
}
|
||||
|
||||
// Initialise values
|
||||
$this->formula = trim($pFormula);
|
||||
// Parse!
|
||||
$this->parseToTokens();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Formula
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormula()
|
||||
{
|
||||
return $this->formula;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token
|
||||
*
|
||||
* @param int $pId Token id
|
||||
* @return string
|
||||
* @throws PHPExcel_Calculation_Exception
|
||||
*/
|
||||
public function getToken($pId = 0)
|
||||
{
|
||||
if (isset($this->tokens[$pId])) {
|
||||
return $this->tokens[$pId];
|
||||
} else {
|
||||
throw new PHPExcel_Calculation_Exception("Token with id $pId does not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token count
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTokenCount()
|
||||
{
|
||||
return count($this->tokens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Tokens
|
||||
*
|
||||
* @return PHPExcel_Calculation_FormulaToken[]
|
||||
*/
|
||||
public function getTokens()
|
||||
{
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse to tokens
|
||||
*/
|
||||
private function parseToTokens()
|
||||
{
|
||||
// No attempt is made to verify formulas; assumes formulas are derived from Excel, where
|
||||
// they can only exist if valid; stack overflows/underflows sunk as nulls without exceptions.
|
||||
|
||||
// Check if the formula has a valid starting =
|
||||
$formulaLength = strlen($this->formula);
|
||||
if ($formulaLength < 2 || $this->formula{0} != '=') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Helper variables
|
||||
$tokens1 = $tokens2 = $stack = array();
|
||||
$inString = $inPath = $inRange = $inError = false;
|
||||
$token = $previousToken = $nextToken = null;
|
||||
|
||||
$index = 1;
|
||||
$value = '';
|
||||
|
||||
$ERRORS = array("#NULL!", "#DIV/0!", "#VALUE!", "#REF!", "#NAME?", "#NUM!", "#N/A");
|
||||
$COMPARATORS_MULTI = array(">=", "<=", "<>");
|
||||
|
||||
while ($index < $formulaLength) {
|
||||
// state-dependent character evaluation (order is important)
|
||||
|
||||
// double-quoted strings
|
||||
// embeds are doubled
|
||||
// end marks token
|
||||
if ($inString) {
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
|
||||
if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE)) {
|
||||
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE;
|
||||
++$index;
|
||||
} else {
|
||||
$inString = false;
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_TEXT);
|
||||
$value = "";
|
||||
}
|
||||
} else {
|
||||
$value .= $this->formula{$index};
|
||||
}
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// single-quoted strings (links)
|
||||
// embeds are double
|
||||
// end does not mark a token
|
||||
if ($inPath) {
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
|
||||
if ((($index + 2) <= $formulaLength) && ($this->formula{$index + 1} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE)) {
|
||||
$value .= PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE;
|
||||
++$index;
|
||||
} else {
|
||||
$inPath = false;
|
||||
}
|
||||
} else {
|
||||
$value .= $this->formula{$index};
|
||||
}
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// bracked strings (R1C1 range index or linked workbook name)
|
||||
// no embeds (changed to "()" by Excel)
|
||||
// end does not mark a token
|
||||
if ($inRange) {
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_CLOSE) {
|
||||
$inRange = false;
|
||||
}
|
||||
$value .= $this->formula{$index};
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// error values
|
||||
// end marks a token, determined from absolute list of values
|
||||
if ($inError) {
|
||||
$value .= $this->formula{$index};
|
||||
++$index;
|
||||
if (in_array($value, $ERRORS)) {
|
||||
$inError = false;
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_ERROR);
|
||||
$value = "";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// scientific notation check
|
||||
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_SN, $this->formula{$index}) !== false) {
|
||||
if (strlen($value) > 1) {
|
||||
if (preg_match("/^[1-9]{1}(\.[0-9]+)?E{1}$/", $this->formula{$index}) != 0) {
|
||||
$value .= $this->formula{$index};
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// independent character evaluation (order not important)
|
||||
|
||||
// establish state-dependent character evaluations
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_DOUBLE) {
|
||||
if (strlen($value > 0)) {
|
||||
// unexpected
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
|
||||
$value = "";
|
||||
}
|
||||
$inString = true;
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::QUOTE_SINGLE) {
|
||||
if (strlen($value) > 0) {
|
||||
// unexpected
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
|
||||
$value = "";
|
||||
}
|
||||
$inPath = true;
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACKET_OPEN) {
|
||||
$inRange = true;
|
||||
$value .= PHPExcel_Calculation_FormulaParser::BRACKET_OPEN;
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::ERROR_START) {
|
||||
if (strlen($value) > 0) {
|
||||
// unexpected
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
|
||||
$value = "";
|
||||
}
|
||||
$inError = true;
|
||||
$value .= PHPExcel_Calculation_FormulaParser::ERROR_START;
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// mark start and end of arrays and array rows
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_OPEN) {
|
||||
if (strlen($value) > 0) {
|
||||
// unexpected
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN);
|
||||
$value = "";
|
||||
}
|
||||
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAY", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
|
||||
$tokens1[] = $tmp;
|
||||
$stack[] = clone $tmp;
|
||||
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
|
||||
$tokens1[] = $tmp;
|
||||
$stack[] = clone $tmp;
|
||||
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::SEMICOLON) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
|
||||
$tmp = array_pop($stack);
|
||||
$tmp->setValue("");
|
||||
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP);
|
||||
$tokens1[] = $tmp;
|
||||
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT);
|
||||
$tokens1[] = $tmp;
|
||||
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken("ARRAYROW", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
|
||||
$tokens1[] = $tmp;
|
||||
$stack[] = clone $tmp;
|
||||
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::BRACE_CLOSE) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
|
||||
$tmp = array_pop($stack);
|
||||
$tmp->setValue("");
|
||||
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP);
|
||||
$tokens1[] = $tmp;
|
||||
|
||||
$tmp = array_pop($stack);
|
||||
$tmp->setValue("");
|
||||
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP);
|
||||
$tokens1[] = $tmp;
|
||||
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// trim white-space
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE);
|
||||
++$index;
|
||||
while (($this->formula{$index} == PHPExcel_Calculation_FormulaParser::WHITESPACE) && ($index < $formulaLength)) {
|
||||
++$index;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// multi-character comparators
|
||||
if (($index + 2) <= $formulaLength) {
|
||||
if (in_array(substr($this->formula, $index, 2), $COMPARATORS_MULTI)) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken(substr($this->formula, $index, 2), PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL);
|
||||
$index += 2;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// standard infix operators
|
||||
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_INFIX, $this->formula{$index}) !== false) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] =new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX);
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// standard postfix operators (only one)
|
||||
if (strpos(PHPExcel_Calculation_FormulaParser::OPERATORS_POSTFIX, $this->formula{$index}) !== false) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($this->formula{$index}, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX);
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// start subexpression or function
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_OPEN) {
|
||||
if (strlen($value) > 0) {
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
|
||||
$tokens1[] = $tmp;
|
||||
$stack[] = clone $tmp;
|
||||
$value = "";
|
||||
} else {
|
||||
$tmp = new PHPExcel_Calculation_FormulaToken("", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START);
|
||||
$tokens1[] = $tmp;
|
||||
$stack[] = clone $tmp;
|
||||
}
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// function, subexpression, or array parameters, or operand unions
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::COMMA) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
|
||||
$tmp = array_pop($stack);
|
||||
$tmp->setValue("");
|
||||
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP);
|
||||
$stack[] = $tmp;
|
||||
|
||||
if ($tmp->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_UNION);
|
||||
} else {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken(",", PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_ARGUMENT);
|
||||
}
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// stop subexpression
|
||||
if ($this->formula{$index} == PHPExcel_Calculation_FormulaParser::PAREN_CLOSE) {
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
$value = "";
|
||||
}
|
||||
|
||||
$tmp = array_pop($stack);
|
||||
$tmp->setValue("");
|
||||
$tmp->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP);
|
||||
$tokens1[] = $tmp;
|
||||
|
||||
++$index;
|
||||
continue;
|
||||
}
|
||||
|
||||
// token accumulation
|
||||
$value .= $this->formula{$index};
|
||||
++$index;
|
||||
}
|
||||
|
||||
// dump remaining accumulation
|
||||
if (strlen($value) > 0) {
|
||||
$tokens1[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND);
|
||||
}
|
||||
|
||||
// move tokenList to new set, excluding unnecessary white-space tokens and converting necessary ones to intersections
|
||||
$tokenCount = count($tokens1);
|
||||
for ($i = 0; $i < $tokenCount; ++$i) {
|
||||
$token = $tokens1[$i];
|
||||
if (isset($tokens1[$i - 1])) {
|
||||
$previousToken = $tokens1[$i - 1];
|
||||
} else {
|
||||
$previousToken = null;
|
||||
}
|
||||
if (isset($tokens1[$i + 1])) {
|
||||
$nextToken = $tokens1[$i + 1];
|
||||
} else {
|
||||
$nextToken = null;
|
||||
}
|
||||
|
||||
if (is_null($token)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() != PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_WHITESPACE) {
|
||||
$tokens2[] = $token;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_null($previousToken)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! (
|
||||
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)
|
||||
) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_null($nextToken)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! (
|
||||
(($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) ||
|
||||
(($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) && ($nextToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_START)) ||
|
||||
($nextToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)
|
||||
) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokens2[] = new PHPExcel_Calculation_FormulaToken($value, PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX, PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_INTERSECTION);
|
||||
}
|
||||
|
||||
// move tokens to final list, switching infix "-" operators to prefix when appropriate, switching infix "+" operators
|
||||
// to noop when appropriate, identifying operand and infix-operator subtypes, and pulling "@" from function names
|
||||
$this->tokens = array();
|
||||
|
||||
$tokenCount = count($tokens2);
|
||||
for ($i = 0; $i < $tokenCount; ++$i) {
|
||||
$token = $tokens2[$i];
|
||||
if (isset($tokens2[$i - 1])) {
|
||||
$previousToken = $tokens2[$i - 1];
|
||||
} else {
|
||||
$previousToken = null;
|
||||
}
|
||||
if (isset($tokens2[$i + 1])) {
|
||||
$nextToken = $tokens2[$i + 1];
|
||||
} else {
|
||||
$nextToken = null;
|
||||
}
|
||||
|
||||
if (is_null($token)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "-") {
|
||||
if ($i == 0) {
|
||||
$token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX);
|
||||
} elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) &&
|
||||
($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) &&
|
||||
($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) ||
|
||||
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH);
|
||||
} else {
|
||||
$token->setTokenType(PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPREFIX);
|
||||
}
|
||||
|
||||
$this->tokens[] = $token;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX && $token->getValue() == "+") {
|
||||
if ($i == 0) {
|
||||
continue;
|
||||
} elseif ((($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) &&
|
||||
($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
(($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_SUBEXPRESSION) &&
|
||||
($previousToken->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_STOP)) ||
|
||||
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORPOSTFIX) ||
|
||||
($previousToken->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND)) {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->tokens[] = $token;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERATORINFIX &&
|
||||
$token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) {
|
||||
if (strpos("<>=", substr($token->getValue(), 0, 1)) !== false) {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL);
|
||||
} elseif ($token->getValue() == "&") {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_CONCATENATION);
|
||||
} else {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_MATH);
|
||||
}
|
||||
|
||||
$this->tokens[] = $token;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_OPERAND &&
|
||||
$token->getTokenSubType() == PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING) {
|
||||
if (!is_numeric($token->getValue())) {
|
||||
if (strtoupper($token->getValue()) == "TRUE" || strtoupper($token->getValue() == "FALSE")) {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_LOGICAL);
|
||||
} else {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_RANGE);
|
||||
}
|
||||
} else {
|
||||
$token->setTokenSubType(PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NUMBER);
|
||||
}
|
||||
|
||||
$this->tokens[] = $token;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($token->getTokenType() == PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_FUNCTION) {
|
||||
if (strlen($token->getValue() > 0)) {
|
||||
if (substr($token->getValue(), 0, 1) == "@") {
|
||||
$token->setValue(substr($token->getValue(), 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->tokens[] = $token;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
PARTLY BASED ON:
|
||||
Copyright (c) 2007 E. W. Bachtal, Inc.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
||||
and associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial
|
||||
portions of the Software.
|
||||
|
||||
The software is provided "as is", without warranty of any kind, express or implied, including but not
|
||||
limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In
|
||||
no event shall the authors or copyright holders be liable for any claim, damages or other liability,
|
||||
whether in an action of contract, tort or otherwise, arising from, out of or in connection with the
|
||||
software or the use or other dealings in the software.
|
||||
|
||||
http://ewbi.blogs.com/develops/2007/03/excel_formula_p.html
|
||||
http://ewbi.blogs.com/develops/2004/12/excel_formula_p.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Calculation_FormulaToken
|
||||
*
|
||||
* Copyright (c) 2006 - 2015 PHPExcel
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Calculation
|
||||
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version ##VERSION##, ##DATE##
|
||||
*/
|
||||
|
||||
|
||||
class PHPExcel_Calculation_FormulaToken
|
||||
{
|
||||
/* Token types */
|
||||
const TOKEN_TYPE_NOOP = 'Noop';
|
||||
const TOKEN_TYPE_OPERAND = 'Operand';
|
||||
const TOKEN_TYPE_FUNCTION = 'Function';
|
||||
const TOKEN_TYPE_SUBEXPRESSION = 'Subexpression';
|
||||
const TOKEN_TYPE_ARGUMENT = 'Argument';
|
||||
const TOKEN_TYPE_OPERATORPREFIX = 'OperatorPrefix';
|
||||
const TOKEN_TYPE_OPERATORINFIX = 'OperatorInfix';
|
||||
const TOKEN_TYPE_OPERATORPOSTFIX = 'OperatorPostfix';
|
||||
const TOKEN_TYPE_WHITESPACE = 'Whitespace';
|
||||
const TOKEN_TYPE_UNKNOWN = 'Unknown';
|
||||
|
||||
/* Token subtypes */
|
||||
const TOKEN_SUBTYPE_NOTHING = 'Nothing';
|
||||
const TOKEN_SUBTYPE_START = 'Start';
|
||||
const TOKEN_SUBTYPE_STOP = 'Stop';
|
||||
const TOKEN_SUBTYPE_TEXT = 'Text';
|
||||
const TOKEN_SUBTYPE_NUMBER = 'Number';
|
||||
const TOKEN_SUBTYPE_LOGICAL = 'Logical';
|
||||
const TOKEN_SUBTYPE_ERROR = 'Error';
|
||||
const TOKEN_SUBTYPE_RANGE = 'Range';
|
||||
const TOKEN_SUBTYPE_MATH = 'Math';
|
||||
const TOKEN_SUBTYPE_CONCATENATION = 'Concatenation';
|
||||
const TOKEN_SUBTYPE_INTERSECTION = 'Intersection';
|
||||
const TOKEN_SUBTYPE_UNION = 'Union';
|
||||
|
||||
/**
|
||||
* Value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Token Type (represented by TOKEN_TYPE_*)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $tokenType;
|
||||
|
||||
/**
|
||||
* Token SubType (represented by TOKEN_SUBTYPE_*)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $tokenSubType;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Calculation_FormulaToken
|
||||
*
|
||||
* @param string $pValue
|
||||
* @param string $pTokenType Token type (represented by TOKEN_TYPE_*)
|
||||
* @param string $pTokenSubType Token Subtype (represented by TOKEN_SUBTYPE_*)
|
||||
*/
|
||||
public function __construct($pValue, $pTokenType = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN, $pTokenSubType = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING)
|
||||
{
|
||||
// Initialise values
|
||||
$this->value = $pValue;
|
||||
$this->tokenType = $pTokenType;
|
||||
$this->tokenSubType = $pTokenSubType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Value
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token Type (represented by TOKEN_TYPE_*)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTokenType()
|
||||
{
|
||||
return $this->tokenType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Token Type
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setTokenType($value = PHPExcel_Calculation_FormulaToken::TOKEN_TYPE_UNKNOWN)
|
||||
{
|
||||
$this->tokenType = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Token SubType (represented by TOKEN_SUBTYPE_*)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTokenSubType()
|
||||
{
|
||||
return $this->tokenSubType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Token SubType
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setTokenSubType($value = PHPExcel_Calculation_FormulaToken::TOKEN_SUBTYPE_NOTHING)
|
||||
{
|
||||
$this->tokenSubType = $value;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue