You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/webht/third_party/trippestOrderSync/models/order_update.php

594 lines
22 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
class Order_update extends CI_Model {
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
//读取默认配置
$this->COLI_WebCode = $this->config->item('Site_Code');
$this->COLI_Area = $this->config->item('Site_Area');
$this->COLI_CustomerType = $this->config->item('Site_DepartmentID');
$this->COLI_department = $this->config->item('Site_Department');
$this->COLI_Currency = $this->config->item('Site_Currency');
$this->COLI_InterestRate = $this->config->item('Site_InterestRate');
$this->COLI_TrueCardRate = $this->config->item('Site_TrueCardRate');
$this->COLI_TouristLGC = $this->config->item('Site_ServiceLGC');
$this->COLI_OrderStartDate = null;
$this->COLI_Keywords = NULL;
switch ($this->check_device()) {
case 'mobile':
$this->COLI_OrderSource = '62003';
break;
case 'tablet':
$this->COLI_OrderSource = '62002';
break;
default:
$this->COLI_OrderSource = '62001';
}
}
public $coli_where_update = "";
public function biz_confirmlineinfo_update($column_data)
{
if ($this->coli_where_update == "" || empty($column_data)) {
return false;
}
$update_str = $this->HT->update_string('BIZ_ConfirmLineInfo', $column_data, $this->coli_where_update);
$update_exc = $this->HT->query($update_str);
return $update_exc;
}
public $cold_where_update = "";
public function biz_confirmlinedetail_update($column_data)
{
if ($this->cold_where_update == "" || empty($column_data)) {
return false;
}
$update_str = $this->HT->update_string('BIZ_ConfirmLineDetail', $column_data, $this->cold_where_update);
$update_exc = $this->HT->query($update_str);
return $update_exc;
}
public $gci_where_update = "";
public function biz_groupcombineinfo_update($column_data)
{
if ($this->gci_where_update == "" || empty($column_data)) {
return false;
}
$update_str = $this->HT->update_string('BIZ_GroupCombineInfo', $column_data, $this->gci_where_update);
$update_exc = $this->HT->query($update_str);
return $update_exc;
}
public function combineoperation_exist($combineNo='', $operation="")
{
if( ! $combineNo) { return false; }
$sql = "SELECT TOP 1 GCOD_GCI_combineNo
FROM BIZ_GroupCombineOperationDetail
WHERE GCOD_GCI_combineNo = N? and GCOD_operationType=?";
$query = $this->HT->query($sql, array(
$combineNo,$operation
));
return $query->result();
}
public function get_SN_by_vendorOrderId($vendorOrderId)
{
$sql = "SELECT TOP 1 coli.COLI_GRI_SN,coli.COLI_SN,gci.GCI_SN
FROM BIZ_GroupCombineInfo gci
INNER JOIN BIZ_ConfirmLineInfo coli ON coli.COLI_SN=gci.GCI_COLI_SN
WHERE gci.GCI_VendorOrderId='$vendorOrderId'";
$query = $this->HT->query($sql);
if ($query->row()) {
$this->BIZ_COLI_SN = $query->row()->COLI_SN;
$this->GRI_SN = $query->row()->COLI_GRI_SN;
$this->GCI_SN = $query->row()->GCI_SN;
return $query->row();
}
return NULL;
}
public function get_SN_by_groupCode($code)
{
$sql = "SELECT top 1 COLI_SN,GRI_SN
FROM BIZ_ConfirmLineInfo coli
LEFT JOIN GRoupInfo gri ON coli.COLI_GRI_SN=gri.GRI_SN
WHERE gri.GRI_No LIKE '$code%'";
$query = $this->HT->query($sql);
if ($query->row()) {
$this->BIZ_COLI_SN = $query->row()->COLI_SN;
$this->GRI_SN = $query->row()->GRI_SN;
return $query->row();
}
return NULL;
}
public function update_confirmLineInfo()
{
$sql = "UPDATE BIZ_ConfirmLineInfo SET
COLI_GRI_SN=?,
COLI_GroupCode=?
WHERE COLI_SN=?
";
$query = $this->HT->query($sql, array(
$this->BIZ_COLI_GRI_SN
,$this->BIZ_COLI_GroupCode
,$this->BIZ_COLI_SN
));
return $this->query;
}
/*
* 生成订单号
* 根据系统时间生成精确到0.0001微秒
*/
function MakeOrderNumber() {
return str_replace('.', '', sprintf('%11.4f', gettimeofday(TRUE)));
}
/**
* 生成商务订单号
*/
function biz_make_order_number() {
/*
$date = date('ymd',time());
$sql = "SELECT MAX( \n"
. " CONVERT( \n"
. " INT, \n"
. " CASE \n"
. " WHEN ISNUMERIC(RIGHT(COLI_ID, 3)) = 0 THEN LEFT(RIGHT(COLI_ID, 4), 3) \n"
. " ELSE RIGHT(COLI_ID, 3) \n"
. " END \n"
. " ) \n"
. " ) AS SN \n"
. "FROM dbo.BIZ_ConfirmLineInfo \n"
. "WHERE (LEFT(COLI_ID, 6) = ?)";
$query = $this->HT->query($sql,array($date));
$id = $query->row()->SN;
if (is_null($id)||empty($id))
{
$id = 0;
}
$ids = $date.(sprintf('%03d',(int)$id+1));
return $ids;
*/
//call $conn
include('c:/database_conn.php');
$connection = array(
'UID' => $db['HT']['username'],
'PWD' => $db['HT']['password'],
'Database' => 'tourmanager',
'ConnectionPooling' => 1,
'CharacterSet' => 'utf-8',
'ReturnDatesAsStrings' => 1
);
$conn = sqlsrv_connect($db['HT']['hostname'], $connection);
$stmt = sqlsrv_query($conn, "declare @ccid varchar(20);exec dbo.SP_GetBIZOrderNo @ccid out;select @ccid as ccid;");
if ($stmt === false) {
echo "Error in executing statement 3.\n";
die(print_r(sqlsrv_errors(), true));
} else {
//存储过程中每一个select都会产生一个结果集取某个结果集就需要从第一个移动到需要的那个结果集
//如果结果集为空就移到下一个
while (sqlsrv_has_rows($stmt) !== TRUE) {
sqlsrv_next_result($stmt);
}
$result_object = array();
while ($row = sqlsrv_fetch_object($stmt)) {
$result_object[] = $row;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
return($result_object[0]->ccid);
}
}
/**
*
* 更新订单状态(商务订单)
*
*/
public function update_biz_order($order_id, $pay_manager, $source_type, $state, $text = '') {
//更新订单
$sql = "UPDATE BIZ_ConfirmLineInfo SET COLI_PayManner=?,COLI_sourcetype=?,COLI_State=?,COLI_OrderDetailText=COLI_OrderDetailText+? WHERE COLI_ID=?";
$query = $this->HT->query($sql, array($pay_manager, $source_type, $state, $text, $order_id . ''));
$this->insert_acc_info($order_id);
return '是否执行:' . print_r($query, true) . ' sql:' . $sql . ' 参数:' . print_r(array($pay_manager, $source_type, $state, $text, $order_id . ''), true);
}
/**
*
* 更新火车订单购票截图
*
*/
public function update_train_order_pic($order_pic_id) {
//更新订单
$sql = "exec dbo.SP_BIZ_GroupFinanceList_Insert '" . $order_pic_id . "'";
//$query = $this->HT->query($sql);
include('c:/database_conn.php');
$connection = array(
'UID' => $db['HT']['username'],
'PWD' => $db['HT']['password'],
'Database' => 'tourmanager',
'ConnectionPooling' => 1,
'CharacterSet' => 'utf-8',
'ReturnDatesAsStrings' => 1
);
$conn = sqlsrv_connect($db['HT']['hostname'], $connection);
$stmt = sqlsrv_query($conn, $sql);
return $stmt;
}
/**
*
* 插入收款记录
*
*/
public function insert_acc_info($order_id) {
//获取订单
$sql = "Select Top 1 COLI_SN,COLI_ID,COLI_PayManner,COLI_Price From BIZ_ConfirmLineInfo Where COLI_ID = ?";
$query = $this->HT->query($sql, array($order_id));
$order_info = $query->row();
//插入记录
$sql = "INSERT INTO BIZ_GroupAccountInfo \n"
. " ( \n"
. " GAI_COLI_SN, \n"
. " GAI_COLI_ID, \n"
. " GAI_Type, \n"
. " GAI_SQJE, \n"
. " GAI_SQDate, \n"
. " GAI_SSJE, \n"
. " GAI_SQJECurrency, \n"
. " GAI_SSDate, \n"
. " GAI_CusName, \n"
. " GAI_CusEmail, \n"
. " GAI_Memo \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ?, \n"
. " ? \n"
. " )";
$query = $this->HT->query($sql, array($order_info->COLI_SN,
$order_info->COLI_ID,
$order_info->COLI_PayManner,
$order_info->COLI_Price,
date('Y-m-d H:i:s'),
$order_info->COLI_Price,
$this->config->item('Site_Currency'),
date('Y-m-d H:i:s'),
"", "", " "));
}
function GetNationalityID($nationalityName) {
if (!$nationalityName) {
return 0;
}
if (is_numeric($nationalityName)) {
return $nationalityName;
} else {
$sql = "SELECT TOP 1 ci2.COI2_COI_SN \n"
. "FROM COuntryInfo2 ci2 \n"
. "WHERE ci2.COI2_Country = ? ";
$query = $this->HT->query($sql, array($nationalityName));
if ($query->result()) {
$row = $query->row();
return $row->COI2_COI_SN;
} else {
return 0;
}
}
}
function GetNationalityName($nationalityID) {
if (!is_numeric($nationalityID)) {
return $nationalityID;
} else {
$sql = "SELECT TOP 1 ci2.COI2_Country \n"
. "FROM COuntryInfo2 ci2 \n"
. "WHERE ci2.COI2_LGC = 2 \n"
. " AND ci2.COI2_COI_SN = ? ";
$query = $this->HT->query($sql, array($nationalityID));
if ($query->result()) {
$row = $query->row();
return $row->COI2_Country;
} else {
return $nationalityID;
}
}
}
/**
*
* 获取商务订单信息
* @param string $order_id 订单id
* @return mixed 订单信息
*
*/
public function get_flight_order_by_id($order_id) {
$sql = "SELECT DISTINCT cli.COLI_ID, \n"
. " cli.COLI_Price, \n"
. " bg.GUT_FirstName, \n"
. " bg.GUT_LastName, \n"
. " bg.GUT_Email, \n"
. " bg.GUT_Email2, \n"
. " bpe.BPE_SN, \n"
. " bpe.BPE_GuestType, \n"
. " bpe.BPE_FirstName, \n"
. " bpe.BPE_MiddleName, \n"
. " bpe.BPE_LastName, \n"
. " bpe.BPE_GuestType, \n"
. " bpe.BPE_Passport, \n"
. " cld.COLD_Count, \n"
. " foi.FlightsNo, \n"
. " foi.DepartureDate, \n"
. " foi.DepartureTime, \n"
. " foi.ArrivalTime, \n"
. " cli.COLI_PayManner, \n"
. " cli.COLI_State, \n"
. " cli.COLI_sourcetype, \n"
. " foi.Cabin, \n"
. " foi.DepartAirport, \n"
. " foi.ArrivalAirport, \n"
. " cld.COLD_SN, \n"
. " foi.DepartureCity, \n"
. " foi.ArrivalCity, \n"
. " bg.GUT_TEL, \n"
. " bg.GUT_NationalityID, \n"
. " cli.COLI_OrderDetailText, \n"
. " bpe.BPE_imageSrc, \n"
. " cli.COLI_Cost, \n"
. " cld.COLD_TotalPrice, \n"
. " cld.COLD_TotalCost \n"
. "FROM BIZ_ConfirmLineInfo cli \n"
. " INNER JOIN BIZ_ConfirmLineDetail cld \n"
. " ON cli.COLI_SN = cld.COLD_COLI_SN \n"
. " INNER JOIN BIZ_GUEST bg \n"
. " ON bg.GUT_SN = cli.COLI_GUT_SN \n"
. " INNER JOIN BIZ_BookPeopleList bpl \n"
. " ON bpl.BPL_COLD_SN = cld.COLD_SN \n"
. " INNER JOIN BIZ_BookPeople bpe \n"
. " ON bpl.BPL_BPE_SN = bpe.BPE_SN \n"
. " INNER JOIN BIZ_FlightsOrderInfo foi \n"
. " ON foi.FOI_COLD_SN = cld.COLD_SN \n"
. "WHERE cli.COLI_ID = ? AND isnull(cld.deleteflag,0) = 0 ";
$query = $this->HT->query($sql, array($order_id));
return $query->result();
}
/**
*
* 获取机票订单乘员列表
* @param string $order_id 订单id
* @return mixed 订单信息
*
*/
public function get_bpe_list_by_id($order_id) {
$sql = "SELECT DISTINCT bpe.BPE_SN, \n"
. " bpe.BPE_FirstName, \n"
. " bpe.BPE_MiddleName, \n"
. " bpe.BPE_LastName, \n"
. " bpe.BPE_Passport \n"
. "FROM BIZ_BookPeople bpe \n"
. " INNER JOIN BIZ_BookPeopleList bpl \n"
. " ON bpe.BPE_SN = bpl.BPL_BPE_SN \n"
. " INNER JOIN BIZ_ConfirmLineDetail cold \n"
. " ON bpl.BPL_COLD_SN = cold.COLD_SN \n"
. " INNER JOIN BIZ_ConfirmLineInfo coli \n"
. " ON coli.COLI_SN = cold.COLD_COLI_SN \n"
. "WHERE coli.COLI_ID = ?";
$query = $this->HT->query($sql, array($order_id));
//echo('<!--'.$this->HT->compile_binds($sql,array($order_id)).'-->');
return $query->result();
}
/**
*
* 获取机票电子票号
* @param array bpe_sn 乘客sn数组
* @return mixed 机票票号
*
*/
public function get_ticket_no($bpe_sn) {
if (is_array($bpe_sn)) {
$instr = join(',', $bpe_sn);
} elseif (is_string($bpe_sn)) {
$instr = $bpe_sn;
} else {
$instr = 0;
}
$sql = "SELECT DISTINCT ftn.FTN_FilghtsNo, \n"
. " ftn.FTN_TicketNo, \n"
. " ftn.FTN_GuestNo \n"
. "FROM BIZ_FlightsTicketNo ftn \n"
. "WHERE ftn.FTN_GuestNo IN (" . $instr . ")";
$query = $this->HT->query($sql);
return $query->result();
}
/*
* 发送邮件
*/
function SendMail($fromName, $fromEmail, $toName, $toEmail, $subject, $body) {
$sql = "INSERT INTO Email_AutomaticSend \n"
. " ( \n"
. " M_ReplyToName, M_ReplyToEmail, M_ToName, M_ToEmail, M_Title, M_Body, M_Web, \n"
. " M_FromName, M_State \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, ?, ?, ?, ?, N?, ?, ?, 0 \n"
. " ) ";
$query = $this->HT->query($sql,
array(substr($fromName, 0, 127), $fromEmail, substr($toName, 0, 127), $toEmail, $subject, $body, $this->config->item('Site_Code'), $this->config->item('Site_SenderName'))
);
return $query;
}
/**
*
* 返回成行订单
* 条件1订单类型
* 天剑2网站来源
*
*/
public function get_order_info($COLI_sourcetype, $COLI_WebCode, $biz = true) {
if ($biz) {
$sql = "SELECT TOP 200 c.COLI_WebCode, \n"
. " c.COLI_ID, \n"
. " c.COLI_ConfirmDate, \n"
. " c.COLI_ApplyDate, \n"
. " ISNULL(c.COLI_IsSuccess, 0) AS success \n"
. "FROM BIZ_ConfirmLineInfo c \n"
. "WHERE c.COLI_sourcetype = ? \n"
. " AND c.COLI_WebCode = ? \n"
. "ORDER BY \n"
. " c.COLI_SN DESC";
$query = $this->HT->query($sql, array($COLI_sourcetype, $COLI_WebCode));
} else {
$sql = "SELECT TOP 200 c.COLI_WebCode, \n"
. " c.COLI_ID, \n"
. " c.COLI_ConfirmDate, \n"
. " c.COLI_ApplyDate, \n"
. " CASE WHEN c.COLI_Sended = 5 THEN 1 ELSE 0 END AS success \n"
. "FROM ConfirmLineInfo c \n"
. "WHERE c.COLI_sourcetype = ? \n"
. " AND c.COLI_WebCode = ? \n"
. "ORDER BY \n"
. " c.COLI_SN DESC";
$query = $this->HT->query($sql, array($COLI_sourcetype, $COLI_WebCode));
}
$this->sql = $this->HT->queries;
return $query->result();
}
//传统订单支付之后,插入新的订单信息
public function insert_daytrip_order($coli_sn, $pay_manner, $gri_sn, $state, $deleteflag) {
//获取订单
$order_info_sql = "
SELECT confirmlineinfotmp.COLI_OrderPrice,
memberinfotmp.MEI_FirstName,
memberinfotmp.MEI_LastName,
memberinfotmp.MEI_Mail
FROM memberinfotmp
INNER JOIN customerlisttmp
ON memberinfotmp.mei_sn = customerlisttmp.cul_cui_sn
INNER JOIN confirmlineinfotmp
ON customerlisttmp.cul_coli_sn = confirmlineinfotmp.coli_sn
WHERE (customerlisttmp.cul_coli_sn = ? )";
$query = $this->HT->query($order_info_sql, array($coli_sn));
$order_info = $query->row();
//插入记录
$sql = "INSERT INTO GroupAccountInfoTmp
(
GAI_COLI_SN,
GAI_SQJE,
GAI_SQDate,
GAI_CusName,
GAI_CusEmail,
GAI_SQJECurrency,
GAI_Type,
LastEditTime,
GAI_GRI_SN,
GAI_State,
DeleteFlag
)
VALUES (?,?,?,?,?,?,?,?,?,?,?)";
$query = $this->HT->query($sql, array($coli_sn,
$order_info->COLI_OrderPrice,
date('Y-m-d H:i:s'),
$order_info->MEI_FirstName . " " . $order_info->MEI_LastName,
$order_info->MEI_Mail,
$this->config->item('Site_Currency'),
$pay_manner,
date('Y-m-d H:i:s'),
$gri_sn,
$state,
$deleteflag
)
);
}
//来源终端 tablet mobile desktop
public function check_device() {
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = $_SERVER['HTTP_USER_AGENT'];
} else {
$ua = '';
}
## This credit must stay intact (Unless you have a deal with @lukasmig or frimerlukas@gmail.com
## Made by Lukas Frimer Tholander from Made In Osted Webdesign.
## Price will be $2
$iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that)
$android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent
$windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that)
if (!function_exists('androidTablet')) {
function androidTablet($ua) { //Find out if it is a tablet
if (strstr(strtolower($ua), 'android')) { //Search for android in user-agent
if (!strstr(strtolower($ua), 'mobile')) { //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets)
return true;
}
}
}
}
$androidTablet = androidTablet($ua); //Do androidTablet function
$ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent
if ($androidTablet || $ipad) { //If it's a tablet (iPad / Android)
return 'tablet';
} elseif ($iphone && !$ipad || $android && !$androidTablet || $windowsPhone) { //If it's a phone and NOT a tablet
return 'mobile';
} else { //If it's not a mobile device
return 'desktop';
}
}
public function ip_limit($ip = "0.0.0.0")
{
if (strcmp($ip, "0.0.0.0") === 0 || empty($ip)) {
return TRUE;
}
$sql = "SELECT COUNT(1) cnt
FROM ConfirmLineInfoTmp
WHERE 1=1
AND COLI_SenderIP = ?
AND DateDiff(dd,COLI_ApplyDate,getdate())=0";
$query = $this->HT->query($sql, array($ip));
$ret = $query->row();
if ($ret->cnt > 50) {
return FALSE;
} else {
return TRUE;
}
}
}