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.
195 lines
6.2 KiB
PHTML
195 lines
6.2 KiB
PHTML
8 years ago
|
<?php
|
||
|
|
||
|
if (!defined('BASEPATH'))
|
||
|
exit('No direct script access allowed');
|
||
|
|
||
|
class Alipay_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.ALI_sn DESC ';
|
||
|
}
|
||
|
|
||
|
public function unsend($topnum = 2) {
|
||
|
$this->init();
|
||
|
$this->topnum = $topnum;
|
||
|
$this->send = " AND (ALI_sent='unsend' OR ALI_sent='' OR ALI_sent IS NULL) ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function failnote($topnum = 2) {
|
||
|
$this->init();
|
||
|
$this->topnum = $topnum;
|
||
|
$this->send = " AND ALI_sent='sendfail' ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function search_date($date) {
|
||
|
$this->init();
|
||
|
$search_sql = " AND pn.ALI_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
|
||
|
$this->search = $search_sql;
|
||
|
$this->orderby=" ORDER BY CASE pn.ALI_sent WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.ALI_sn DESC ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function note($txn_id){
|
||
|
$this->init();
|
||
|
$this->topnum=1;
|
||
|
$this->dealId=" AND pn.ALI_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.ALI_orderId=".$this->INFO->escape($orderid)." AND pn.ALI_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.ALI_dealId = '$search_key'
|
||
|
OR pn.ALI_orderId 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.ALI_dealId = '".$dealId."' ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* 存储IPayLinks的实时通知
|
||
|
* @author LYT <lyt@hainatravel.com>
|
||
|
* @date 2017-08-29
|
||
|
*/
|
||
|
public function save_alipay($ALI_dealId,$ALI_orderId,$ALI_currencyCode,$ALI_orderAmount,$ALI_payAmount,$ALI_stateCode,$ALI_acquiringTime,$ALI_completeTime,$ALI_memo,$ALI_payType,$ALI_resultCode=null,$ALI_resultMsg=null,$ALI_payerName=null,$ALI_payerEmail=NULL) {
|
||
|
$sql = "
|
||
|
INSERT INTO AlipayLog
|
||
|
(
|
||
|
ALI_dealId,ALI_orderId,ALI_currencyCode,ALI_orderAmount,ALI_payAmount,ALI_stateCode,ALI_acquiringTime,ALI_completeTime,ALI_memo,ALI_sent,ALI_noticeTime,ALI_payType,ALI_resultCode,ALI_resultMsg,ALI_payerName,ALI_payerEmail
|
||
|
)
|
||
|
VALUES
|
||
|
(
|
||
|
?,?,?,?,?,?,?,?,?,'unsend', GETDATE(),?,?,N?,?,N?
|
||
|
)
|
||
|
";
|
||
|
// echo "<br><br>".$this->INFO->compile_binds($sql,
|
||
|
$query = $this->INFO->query($sql,
|
||
|
array($ALI_dealId
|
||
|
,$ALI_orderId
|
||
|
,strtoupper($ALI_currencyCode)
|
||
|
,$ALI_orderAmount
|
||
|
,$ALI_payAmount
|
||
|
,$ALI_stateCode
|
||
|
,$ALI_acquiringTime
|
||
|
,$ALI_completeTime
|
||
|
,$ALI_memo
|
||
|
,$ALI_payType
|
||
|
,$ALI_resultCode
|
||
|
,$ALI_resultMsg
|
||
|
,$ALI_payerName
|
||
|
,$ALI_payerEmail
|
||
|
));
|
||
|
$insertid = $this->INFO->last_id('AlipayLog');
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
public function get_list() {
|
||
|
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
|
||
|
$sql .= "
|
||
|
pn.ALI_sn
|
||
|
,pn.ALI_dealId
|
||
|
,pn.ALI_orderId
|
||
|
,pn.ALI_currencyCode
|
||
|
,pn.ALI_orderAmount
|
||
|
,pn.ALI_payAmount
|
||
|
,pn.ALI_stateCode
|
||
|
,pn.ALI_resultCode
|
||
|
,pn.ALI_resultMsg
|
||
|
,pn.ALI_acquiringTime
|
||
|
,pn.ALI_completeTime
|
||
|
,pn.ALI_memo
|
||
|
,pn.ALI_sent
|
||
|
,pn.ALI_payType
|
||
|
,pn.ALI_noticeTime
|
||
|
,pn.ALI_payerName
|
||
|
,pn.ALI_payerEmail
|
||
|
FROM AlipayLog 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 AlipayLog
|
||
|
SET ALI_sent = ?
|
||
|
WHERE ALI_dealId = ?
|
||
|
";
|
||
|
return $this->INFO->query($sql, array($pn_send, $pn_txn_id));
|
||
|
}
|
||
|
|
||
|
//设置订单号
|
||
|
public function set_invoice($pn_txn_id, $pn_invoice) {
|
||
|
$sql = "
|
||
|
UPDATE AlipayLog
|
||
|
SET ALI_orderId = ?
|
||
|
WHERE ALI_dealId = ?
|
||
|
";
|
||
|
return $this->INFO->query($sql, array($pn_invoice, $pn_txn_id));
|
||
|
}
|
||
|
|
||
|
public function update_query($dealId,$stateCode,$payAmount)
|
||
|
{
|
||
|
$sql = "
|
||
|
UPDATE AlipayLog
|
||
|
SET ALI_stateCode = ?,
|
||
|
ALI_payAmount = ?
|
||
|
where ALI_dealId = ?
|
||
|
";
|
||
|
return $this->INFO->query($sql, array($stateCode,$payAmount,$dealId));
|
||
|
}
|
||
|
|
||
|
}
|