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.
155 lines
5.4 KiB
PHTML
155 lines
5.4 KiB
PHTML
8 years ago
|
<?php
|
||
|
|
||
|
if (!defined('BASEPATH'))
|
||
|
exit('No direct script access allowed');
|
||
|
|
||
|
class Note_model extends CI_Model {
|
||
|
|
||
|
var $topnum = false;
|
||
|
var $orderby = false;
|
||
|
var $pn_send = false;
|
||
|
var $search = false;
|
||
|
var $pn_txn_id=false;
|
||
|
var $pn_payment_status = false;
|
||
|
|
||
|
function __construct() {
|
||
|
parent::__construct();
|
||
|
$this->HT = $this->load->database('HT', TRUE);
|
||
|
//$this->DEST = $this->load->database('DEST', TRUE);
|
||
|
}
|
||
|
|
||
|
public function init() {
|
||
|
$this->topnum = false;
|
||
|
$this->pn_send = false;
|
||
|
$this->search = false;
|
||
|
$this->pn_payment_status = false;
|
||
|
$this->pn_txn_id = false;
|
||
|
$this->orderby = ' ORDER BY pn.pn_sn DESC ';
|
||
|
//$this->pn_payment_status=' AND pn_payment_status= ';
|
||
|
}
|
||
|
|
||
|
public function unsend($topnum = 2) {
|
||
|
$this->init();
|
||
|
$this->topnum = $topnum;
|
||
|
$this->pn_send = " AND (pn_send='unsend' OR pn_send='' OR pn_send IS NULL) ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function failnote($topnum = 2) {
|
||
|
$this->init();
|
||
|
$this->topnum = $topnum;
|
||
|
$this->pn_send = " AND pn_send='sendfail' ";
|
||
|
//$this->orderby = ' ORDER BY pn.pn_sn ASC ';
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function search_date($date) {
|
||
|
$this->init();
|
||
|
$search_sql = " AND pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' ";
|
||
|
$this->search = $search_sql;
|
||
|
$this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.pn_sn DESC ";
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
public function note($pn_txn_id){
|
||
|
$this->init();
|
||
|
$this->topnum=1;
|
||
|
$this->pn_txn_id=" AND pn.pn_txn_id=".$this->HT->escape($pn_txn_id);
|
||
|
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.pn_txn_id = '$search_key'
|
||
|
OR pn.pn_invoice like '%$search_key%'
|
||
|
OR pn.pn_custom like '%$search_key%'
|
||
|
OR pn.pn_item_name like '%$search_key%'
|
||
|
OR pn.pn_item_number like '%$search_key%'
|
||
|
OR pn.pn_payer like '%$search_key%'
|
||
|
OR pn.pn_payer_email like '%$search_key%' )";
|
||
|
}
|
||
|
$this->search = $search_sql;
|
||
|
return $this->get_list();
|
||
|
}
|
||
|
|
||
|
//存储paypal的实时通知
|
||
|
public function save_paypal_note($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo) {
|
||
|
$sql = "
|
||
|
INSERT INTO paypal_note
|
||
|
(
|
||
|
pn_txn_id,pn_invoice,pn_custom, pn_mc_gross, pn_item_name, pn_item_number,pn_mc_currency, pn_payment_status,pn_payer,pn_payer_email,pn_payment_date, pn_memo,pn_datetime,pn_send
|
||
|
)
|
||
|
VALUES
|
||
|
(
|
||
|
?,N?,N?,?,N?,N?,?,?,N?,N?,?, N?, GETDATE(),'unsend'
|
||
|
)
|
||
|
";
|
||
|
$query = $this->HT->query($sql, array($pn_txn_id, $pn_invoice, $pn_custom, $pn_mc_gross, $pn_item_name, $pn_item_number, $pn_mc_currency, $pn_payment_status, $pn_payer, $pn_payer_email, $pn_payment_date, $pn_memo));
|
||
|
$insertid = $this->HT->last_id('paypal_note');
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
public function get_list() {
|
||
|
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
|
||
|
$sql .= "
|
||
|
pn.pn_sn
|
||
|
,pn.pn_txn_id
|
||
|
,pn.pn_invoice
|
||
|
,pn.pn_custom
|
||
|
,pn.pn_mc_gross
|
||
|
,pn.pn_item_name
|
||
|
,pn.pn_item_number
|
||
|
,pn.pn_mc_currency
|
||
|
,pn.pn_payment_status
|
||
|
,pn.pn_payer
|
||
|
,pn.pn_payer_email
|
||
|
,pn.pn_memo
|
||
|
,pn.pn_datetime
|
||
|
,pn.pn_payment_date
|
||
|
,pn.pn_send
|
||
|
FROM paypal_note pn
|
||
|
WHERE 1=1
|
||
|
";
|
||
|
$this->pn_send ? $sql.=$this->pn_send : false;
|
||
|
$this->search ? $sql.=$this->search : false;
|
||
|
$this->pn_txn_id ? $sql.=$this->pn_txn_id : false;
|
||
|
$this->orderby ? $sql.=$this->orderby : false;
|
||
|
$query = $this->HT->query($sql);
|
||
|
//print_r($this->HT->queries);
|
||
|
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 paypal_note
|
||
|
SET pn_send = ?
|
||
|
WHERE pn_txn_id = ?
|
||
|
";
|
||
|
return $this->HT->query($sql, array($pn_send, $pn_txn_id));
|
||
|
}
|
||
|
|
||
|
//设置订单号
|
||
|
public function set_invoice($pn_txn_id, $pn_invoice) {
|
||
|
$sql = "
|
||
|
UPDATE paypal_note
|
||
|
SET pn_invoice = ?
|
||
|
WHERE pn_txn_id = ?
|
||
|
";
|
||
|
return $this->HT->query($sql, array($pn_invoice, $pn_txn_id));
|
||
|
}
|
||
|
|
||
|
}
|