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.
290 lines
9.2 KiB
PHP
290 lines
9.2 KiB
PHP
<?php
|
|
|
|
if (!defined('BASEPATH'))
|
|
exit('No direct script access allowed');
|
|
|
|
class Note_model extends CI_Model {
|
|
|
|
var $topnum = false;
|
|
var $orderby = false;
|
|
var $send = false;
|
|
var $search = false;
|
|
var $dealId = false;
|
|
var $payment_status = false;
|
|
|
|
function __construct() {
|
|
parent::__construct();
|
|
$this->INFO = $this->load->database('INFO', TRUE);
|
|
}
|
|
|
|
public function init() {
|
|
$this->topnum = false;
|
|
$this->send = false;
|
|
$this->search = false;
|
|
$this->payment_status = false;
|
|
$this->dealId = false;
|
|
$this->orderby = ' ORDER BY pn.IPL_sn DESC ';
|
|
}
|
|
|
|
public function unsend($topnum = 2) {
|
|
$this->init();
|
|
$this->topnum = $topnum;
|
|
$this->send = " AND (IPL_sent='unsend' OR IPL_sent='' OR IPL_sent IS NULL) ";
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function failnote($topnum = 2) {
|
|
$this->init();
|
|
$this->topnum = $topnum;
|
|
$this->send = " AND IPL_sent='sendfail' ";
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function search_date($date) {
|
|
$this->init();
|
|
$search_sql = " AND pn.IPL_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
|
|
$this->search = $search_sql;
|
|
$this->orderby=" ORDER BY CASE pn.IPL_sent WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.IPL_sn DESC ";
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function note($txn_id){
|
|
$this->init();
|
|
$this->topnum=1;
|
|
$this->dealId=" AND pn.IPL_dealId=".$this->INFO->escape($txn_id);
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function note_order($orderid,$notice_time)
|
|
{
|
|
$this->init();
|
|
$this->topnum=1;
|
|
$this->dealId=" AND pn.IPL_orderId=".$this->INFO->escape($orderid)." AND pn.IPL_noticeTime=".$this->INFO->escape($notice_time);
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function search_key($search_key) {
|
|
$this->init();
|
|
$this->topnum = 300; //限制最大数量,防止查询单词过短
|
|
$search_sql = '';
|
|
$search_key = trim($search_key);
|
|
if (!empty($search_key)) {
|
|
$search_sql.=" AND ( pn.IPL_dealId = '$search_key'
|
|
OR pn.IPL_orderId like '%$search_key%'
|
|
OR pn.IPL_memo like '%$search_key%' )";
|
|
}
|
|
$this->search = $search_sql;
|
|
return $this->get_list();
|
|
}
|
|
|
|
public function note_exists($dealId)
|
|
{
|
|
$this->init();
|
|
$this->topnum = 1;
|
|
$this->search = " AND pn.IPL_dealId = '".$dealId."' ";
|
|
return $this->get_list();
|
|
}
|
|
|
|
/*!
|
|
* 存储IPayLinks的实时通知
|
|
* @author LYT <lyt@hainatravel.com>
|
|
* @date 2017-08-29
|
|
*/
|
|
public function save_ipl($IPL_dealId,$IPL_orderId,$IPL_currencyCode,$IPL_orderAmount,$IPL_payAmount,$IPL_stateCode,$IPL_acquiringTime,$IPL_completeTime,$IPL_memo,$IPL_payType,$IPL_resultCode=null,$IPL_resultMsg=null,$IPL_payerName=null,$IPL_payerEmail=NULL) {
|
|
$sql = "
|
|
INSERT INTO IPayLinksLog
|
|
(
|
|
IPL_dealId,IPL_orderId,IPL_currencyCode,IPL_orderAmount,IPL_payAmount,IPL_stateCode,IPL_acquiringTime,IPL_completeTime,IPL_memo,IPL_sent,IPL_noticeTime,IPL_payType,IPL_resultCode,IPL_resultMsg,IPL_payerName,IPL_payerEmail
|
|
)
|
|
VALUES
|
|
(
|
|
?,?,?,?,?,?,?,?,?,'unsend', GETDATE(),?,?,N?,N?,N?
|
|
)
|
|
";
|
|
$query = $this->INFO->query($sql,
|
|
array($IPL_dealId
|
|
,$IPL_orderId
|
|
,strtoupper($IPL_currencyCode)
|
|
,$IPL_orderAmount
|
|
,$IPL_payAmount
|
|
,$IPL_stateCode
|
|
,$IPL_acquiringTime
|
|
,$IPL_completeTime
|
|
,$IPL_memo
|
|
,$IPL_payType
|
|
,$IPL_resultCode
|
|
,$IPL_resultMsg
|
|
,$IPL_payerName
|
|
,$IPL_payerEmail
|
|
));
|
|
$insertid = $this->INFO->last_id('IPayLinksLog');
|
|
return $query;
|
|
}
|
|
|
|
public function get_list() {
|
|
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
|
|
$sql .= "
|
|
pn.IPL_sn
|
|
,pn.IPL_dealId
|
|
,pn.IPL_orderId
|
|
,pn.IPL_currencyCode
|
|
,pn.IPL_orderAmount
|
|
,pn.IPL_payAmount
|
|
,pn.IPL_stateCode
|
|
,pn.IPL_resultCode
|
|
,pn.IPL_resultMsg
|
|
,pn.IPL_acquiringTime
|
|
,pn.IPL_completeTime
|
|
,pn.IPL_memo
|
|
,pn.IPL_sent
|
|
,pn.IPL_payType
|
|
,pn.IPL_noticeTime
|
|
,pn.IPL_payerName
|
|
,pn.IPL_payerEmail
|
|
FROM IPayLinksLog pn
|
|
WHERE 1=1
|
|
";
|
|
$this->send ? $sql.=$this->send : false;
|
|
$this->search ? $sql.=$this->search : false;
|
|
$this->dealId ? $sql.=$this->dealId : false;
|
|
$this->orderby ? $sql.=$this->orderby : false;
|
|
$query = $this->INFO->query($sql);
|
|
if ($this->topnum === 1) {
|
|
if ($query->num_rows() > 0) {
|
|
$row = $query->row();
|
|
return $row;
|
|
} else {
|
|
return FALSE;
|
|
}
|
|
} else {
|
|
return $query->result();
|
|
}
|
|
}
|
|
|
|
public function update_send($pn_txn_id, $pn_send) {
|
|
$sql = "
|
|
UPDATE IPayLinksLog
|
|
SET IPL_sent = ?
|
|
WHERE IPL_dealId = ?
|
|
";
|
|
return $this->INFO->query($sql, array($pn_send, $pn_txn_id));
|
|
}
|
|
|
|
//设置订单号
|
|
public function set_invoice($pn_txn_id, $pn_invoice) {
|
|
$sql = "
|
|
UPDATE IPayLinksLog
|
|
SET IPL_orderId = ?
|
|
WHERE IPL_dealId = ?
|
|
";
|
|
return $this->INFO->query($sql, array($pn_invoice, $pn_txn_id));
|
|
}
|
|
|
|
public function update_query($dealId,$stateCode,$payAmount)
|
|
{
|
|
$sql = "
|
|
UPDATE IPayLinksLog
|
|
SET IPL_stateCode = ?,
|
|
IPL_payAmount = ?
|
|
where IPL_dealId = ?
|
|
";
|
|
return $this->INFO->query($sql, array($stateCode,$payAmount,$dealId));
|
|
}
|
|
|
|
public function save_refund($dealId, $orderId, $refundAmount, $refundTime, $completeTime, $stateCode, $resultcode, $memo, $paytype)
|
|
{
|
|
$sql = "IF NOT EXISTS(
|
|
SELECT TOP 1 1
|
|
FROM IPayLinksLog
|
|
WHERE IPL_dealId = ?
|
|
)
|
|
INSERT INTO IPayLinksLog
|
|
(
|
|
IPL_dealId
|
|
,IPL_orderId
|
|
,IPL_orderAmount
|
|
,IPL_stateCode
|
|
,IPL_acquiringTime
|
|
,IPL_completeTime
|
|
,IPL_memo
|
|
,IPL_sent
|
|
,IPL_noticeTime
|
|
,IPL_payType
|
|
,IPL_resultCode
|
|
)
|
|
VALUES
|
|
(
|
|
?,?,?,?,?,?,?,'send',?,?,?
|
|
)
|
|
";
|
|
$query = $this->INFO->query($sql,
|
|
array($dealId
|
|
,$dealId
|
|
,$orderId
|
|
,$refundAmount
|
|
,$stateCode
|
|
,$refundTime
|
|
,$completeTime
|
|
,$memo
|
|
,$completeTime
|
|
,$paytype
|
|
,$resultcode
|
|
));
|
|
return $query;
|
|
}
|
|
|
|
/** 插入实收金额更改记录日志 */
|
|
public function new_warrant($warrant_arr = array())
|
|
{
|
|
$sql = "INSERT INTO PayWarrantLog
|
|
(PW_GAI_AccreditNo
|
|
,PW_GAI_Type
|
|
,PW_orderType
|
|
,PW_COLI_SN
|
|
,PW_GAI_SQJECurrency_pre
|
|
,PW_GAI_SSJE_pre
|
|
,PW_entry_currency
|
|
,PW_entry_amount
|
|
,PW_GAI_SSJE_new
|
|
,PW_time)
|
|
VALUES
|
|
(?
|
|
,?
|
|
,?
|
|
,?
|
|
,?
|
|
,?
|
|
,?
|
|
,?
|
|
,?
|
|
,GETDATE()
|
|
)";
|
|
$query = $this->INFO->query($sql,array(
|
|
$warrant_arr['PW_GAI_AccreditNo'],
|
|
$warrant_arr['PW_GAI_Type'],
|
|
$warrant_arr['PW_orderType'],
|
|
$warrant_arr['PW_COLI_SN'],
|
|
$warrant_arr['PW_GAI_SQJECurrency_pre'],
|
|
$warrant_arr['PW_GAI_SSJE_pre'],
|
|
$warrant_arr['PW_entry_currency'],
|
|
$warrant_arr['PW_entry_amount'],
|
|
$warrant_arr['PW_GAI_SSJE_new']
|
|
));
|
|
return $query;
|
|
}
|
|
|
|
public function date_range($from, $to, $currency=NULL)
|
|
{
|
|
$this->init();
|
|
$search_sql = " AND pn.IPL_resultCode='0000' ";
|
|
$search_sql .= " AND pn.IPL_acquiringTime BETWEEN '$from 00:00:00' AND '$to 23:59:59' ";
|
|
if ( ! empty($currency)) {
|
|
$search_sql .= " AND IPL_currencyCode = '$currency' ";
|
|
}
|
|
$this->search = $search_sql;
|
|
$this->orderby = "";
|
|
return $this->get_list();
|
|
}
|
|
|
|
}
|