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/pay/models/note_model.php

293 lines
9.2 KiB
PHP

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden 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
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Note_model extends CI_Model {
var $topnum = null;
var $orderby = null;
var $send = null;
var $search = null;
var $dealId = null;
var $payment_status = null;
function __construct() {
parent::__construct();
$this->INFO = $this->load->database('INFO', TRUE);
}
public function init() {
$this->topnum = null;
$this->send = null;
$this->search = null;
$this->payment_status = null;
$this->dealId = null;
$this->orderby = ' ORDER BY IPL_sent DESC ,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 (IPL_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' or IPL_sent<>'send') ";
$this->search = $search_sql;
$this->orderby=" ORDER BY IPL_sent DESC ,IPL_sn DESC ";
return $this->get_list();
}
public function note($txn_id){
$this->init();
$this->topnum=1;
$this->dealId=" AND 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 IPL_orderId=".$this->INFO->escape($orderid)." AND IPL_noticeTime=".$this->INFO->escape($notice_time);
return $this->get_list();
}
public function search_key($search_key) {
$this->init();
$this->topnum = 300; //é™<C3A9>制最大数é‡<C3A9>,防止查询å<C2A2>•è¯<C3A8>过短
$search_sql = '';
$search_key = trim($search_key);
if (!empty($search_key)) {
$search_sql.=" AND ( IPL_dealId = '$search_key'
OR IPL_orderId like '%$search_key%'
OR 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 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 ";
$this->topnum ? $top_sql = " TOP " . $this->topnum : $top_sql = " ";
$sql = "SELECT $top_sql
pn.*
FROM IPayLinksLog pn
WHERE 1=1
and pn.IPL_payType='pay'
and (pn.IPL_stateCode=2 or pn.IPL_resultCode='0000')
$this->send
$this->search
$this->dealId
UNION ALL
select $top_sql * from InfoManager.dbo.IPayLinksLog ipl2
where 1=1
and ipl2.IPL_payType='refund'
and ipl2.IPL_stateCode=2
$this->send
$this->search
$this->dealId
$this->orderby
";
$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));
}
//设置订å<C2A2>•å<E280A2>·
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 = ? AND IPL_payType='refund'
)
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;
}
/** æ<>入实收é‡é¢<C3A9>æ´æ”¹è®°å½•日志 */
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 IPL_resultCode='0000' ";
$search_sql .= " AND 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();
}
public function test()
{
$sql = " ";
$this->INFO->query($sql);
return;
}
}