table_forum_trade.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_trade.php 27769 2012-02-14 06:29:36Z liulanbo $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_forum_trade extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'forum_trade';
  15. $this->_pk = '';
  16. parent::__construct();
  17. }
  18. public function fetch_all_thread_goods($tid, $pid = 0) {
  19. $pidsql = $pid ? ' AND '.DB::field('pid', $pid) : '';
  20. return DB::fetch_all("SELECT * FROM %t WHERE tid=%d $pidsql ORDER BY displayorder", array($this->_table, $tid));
  21. }
  22. public function fetch_counter_thread_goods($tid) {
  23. return DB::result_first('SELECT COUNT(*) FROM %t WHERE tid=%d', array($this->_table, $tid));
  24. }
  25. public function fetch_all_for_seller($sellerid, $limit = 10, $tid = 0) {
  26. $tidsql = $tid ? ' AND '.DB::field('tid', $tid) : '';
  27. return DB::fetch_all("SELECT * FROM %t WHERE sellerid=%d $tidsql ORDER BY displayorder DESC LIMIT %d", array($this->_table, $sellerid, $limit));
  28. }
  29. public function fetch_first_goods($tid) {
  30. return DB::fetch_first('SELECT * FROM %t WHERE tid=%d ORDER BY displayorder DESC LIMIT 1', array($this->_table, $tid));
  31. }
  32. public function fetch_goods($tid, $pid, $orderby = '', $ascdesc = 'asc', $start = 0, $limit = 0) {
  33. if(empty($pid)) {
  34. return array();
  35. }
  36. if($tid) {
  37. $tidsql = DB::field('tid', $tid).' AND ';
  38. }
  39. if($orderby) {
  40. $ordersql = " ORDER BY ".DB::order($orderby, $ascdesc);
  41. }
  42. return DB::fetch_first("SELECT * FROM %t WHERE $tidsql ".DB::field('pid', $pid).$ordersql.DB::limit($start, $limit), array($this->_table));
  43. }
  44. public function fetch_all_statvars($fieldname, $limit = 10) {
  45. if(empty($fieldname)) {
  46. return array();
  47. }
  48. return DB::fetch_all("SELECT subject, tid, pid, seller, sellerid, SUM(%s) as %s
  49. FROM ".DB::table('forum_trade')."
  50. WHERE %s>0
  51. GROUP BY sellerid
  52. ORDER BY %s DESC ".DB::limit($limit), array($fieldname, $fieldname, $fieldname));
  53. }
  54. public function update_closed($expiration) {
  55. DB::query("UPDATE %t SET closed='1' WHERE expiration>0 AND expiration<%d", array($this->_table, $expiration));
  56. }
  57. public function check_goods($pid) {
  58. return DB::result_first('SELECT count(*) FROM %t WHERE pid=%d', array($this->_table, $pid));
  59. }
  60. public function update($tid, $pid, $data) {
  61. if(empty($data) || !is_array($data)) {
  62. return false;
  63. }
  64. DB::update('forum_trade', $data, array('tid' => $tid, 'pid' => $pid));
  65. }
  66. public function update_counter($tid, $pid, $items, $price, $credit, $amount = 0) {
  67. DB::query('UPDATE %t SET totalitems=totalitems+\'%d\', tradesum=tradesum+\'%d\', credittradesum=credittradesum+\'%d\', amount=amount+\'%d\' WHERE tid=%d AND pid=%d', array($this->_table, $items, $price, $credit, $amount, $tid, $pid));
  68. }
  69. public function delete_by_id_idtype($ids, $idtype) {
  70. if(empty($ids) || empty($idtype)) {
  71. return false;
  72. }
  73. DB::delete($this->_table, DB::field($idtype, $ids));
  74. }
  75. public function fetch_all_for_search($digestltd, $fids, $topltd, $sqlsrch, $start = 0, $limit = 0) {
  76. return DB::fetch_all("SELECT tr.tid, tr.pid, t.closed FROM ".DB::table('forum_trade')." tr INNER JOIN ".DB::table('forum_thread')." t ON tr.tid=t.tid AND $digestltd t.".DB::field('fid', $fids)." $topltd WHERE$sqlsrch ORDER BY tr.pid DESC".DB::limit($start, $limit));
  77. }
  78. public function fetch_all_for_space($wheresql, $ordersql, $count = 0, $start = 0, $limit = 0) {
  79. if(empty($wheresql)) {
  80. return array();
  81. }
  82. if($count) {
  83. return DB::result_first("SELECT COUNT(*) FROM ".DB::table('forum_trade')." t WHERE $wheresql");
  84. }
  85. if($ordersql && is_string($ordersql)) {
  86. $ordersql = ' ORDER BY '.$ordersql;
  87. }
  88. return DB::fetch_all("SELECT t.* FROM ".DB::table('forum_trade')." t
  89. INNER JOIN ".DB::table('forum_thread')." th ON t.tid=th.tid AND th.displayorder>='0'
  90. WHERE $wheresql $ordersql ".DB::limit($start, $limit));
  91. }
  92. }
  93. ?>