table_forum_tradelog.php 3.7 KB

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