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, $pn_id=null){ $this->init(); $this->topnum=1; $this->dealId=" AND IPL_dealId=".$this->INFO->escape($txn_id); $this->dealId .= ($pn_id===null) ? " " : " AND IPL_sn=" . $pn_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; //限制最大数量,防止查询单词过短 $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 * @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)); } //设置订单号 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; } /** 插入实收金额更改记录日志 */ 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; } }