table_forum_tradelog.php
3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: table_forum_tradelog.php 27751 2012-02-14 02:26:11Z monkey $
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class table_forum_tradelog extends discuz_table
{
public function __construct() {
$this->_table = 'forum_tradelog';
$this->_pk = 'orderid';
parent::__construct();
}
public function count_by_status($status) {
$status = $status >= 0 ? 'WHERE status='.intval($status) : '';
return DB::fetch_first("SELECT COUNT(*) AS num, SUM(price) AS pricesum, SUM(credit) AS creditsum, SUM(tax) AS taxsum FROM %t %i", array($this->_table, $status));
}
public function fetch_all_by_status($status, $start, $limit) {
$status = $status >= 0 ? 'WHERE status='.intval($status) : '';
return DB::fetch_all("SELECT * FROM %t %i ORDER BY lastupdate DESC LIMIT %d, %d", array($this->_table, $status, $start, $limit));
}
public function clear_failure($days) {
DB::query("DELETE FROM %t WHERE buyerid>0 AND status=0 AND lastupdate<%d", array($this->_table, TIMESTAMP - intval($days) * 86400));
}
public function expiration_payed($days) {
$expiration = TIMESTAMP - intval($days) * 86400;
$logs = DB::fetch_all("SELECT * FROM %t WHERE buyerid>0 AND status=4 AND lastupdate<%d", array($this->_table, $expiration));
$members = array();
foreach($logs as $log) {
$members[$log['buyerid']]['extcredits'.$log['basecredit']] += $log['credit'];
}
foreach($members as $uid => $data) {
updatemembercount($uid, $data);
}
DB::query("DELETE FROM %t WHERE buyerid>0 AND status=4 AND lastupdate<%d", array($this->_table, $expiration));
}
public function expiration_finished($days) {
$expiration = TIMESTAMP - intval($days) * 86400;
$logs = DB::fetch_all("SELECT * FROM %t WHERE sellerid>0 AND status=5 AND lastupdate<%d", array($this->_table, $expiration));
$members = array();
foreach($logs as $log) {
$members[$log['sellerid']]['extcredits'.$log['basecredit']] += $log['credit'];
}
foreach($members as $uid => $data) {
updatemembercount($uid, $data);
}
DB::query("DELETE FROM %t WHERE sellerid>0 AND status=5 AND lastupdate<%d", array($this->_table, $expiration));
}
public function fetch_last($uid) {
return DB::fetch_first("SELECT * FROM %t WHERE buyerid=%d AND status!=0 AND buyername!='' ORDER BY lastupdate DESC LIMIT 1", array($this->_table, $uid));
}
public function fetch_all_log($viewtype, $uid, $tid, $pid, $ratestatus, $typestatus, $start, $limit) {
$sql = ($tid ? 'tl.tid=\''.dintval($tid).'\' AND '.($pid ? 'tl.pid=\''.dintval($pid).'\' AND ' : '') : '').
('tl.'.($viewtype == 'sell' ? 'sellerid' : 'buyerid').'='.intval($uid)).' '.
($ratestatus = $ratestatus ? 'AND (tl.ratestatus=0 OR tl.ratestatus='.intval($ratestatus).')' : '').
($typestatus = $typestatus ? 'AND tl.status IN ('.dimplode($typestatus).')' : '');
return DB::fetch_all("SELECT tl.*, tr.aid, t.subject AS threadsubject FROM %t tl, %t t, %t tr WHERE %i
AND tl.tid=t.tid AND tr.pid=tl.pid AND tr.tid=tl.tid ORDER BY tl.lastupdate DESC LIMIT %d, %d",
array($this->_table, 'forum_thread', 'forum_trade', $sql, $start, $limit));
}
public function count_log($viewtype, $uid, $tid, $pid, $ratestatus, $typestatus) {
$sql = ($tid ? 'tl.tid=\''.dintval($tid).'\' AND '.($pid ? 'tl.pid=\''.dintval($pid).'\' AND ' : '') : '').
('tl.'.($viewtype == 'sell' ? 'sellerid' : 'buyerid').'='.intval($uid)).' '.
($ratestatus = $ratestatus ? 'AND (tl.ratestatus=0 OR tl.ratestatus='.intval($ratestatus).')' : '').
($typestatus = $typestatus ? 'AND tl.status IN ('.dimplode($typestatus).')' : '');
return DB::result_first("SELECT COUNT(*) FROM %t tl WHERE %i", array($this->_table,$sql));
}
}
?>