table_home_show.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_home_show.php 29635 2012-04-23 09:00:27Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_home_show extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'home_show';
  15. $this->_pk = 'uid';
  16. parent::__construct();
  17. }
  18. public function count_by_credit($unitprice = false) {
  19. $args = array($this->_table);
  20. if($unitprice !== false) {
  21. $sql = 'AND unitprice>=%d';
  22. $args[] = $unitprice;
  23. }
  24. return DB::result_first("SELECT COUNT(*) FROM %t WHERE credit>0 {$sql}", $args);
  25. }
  26. public function fetch_by_uid_credit($uid) {
  27. return DB::fetch_first('SELECT unitprice, credit FROM %t WHERE uid=%d AND credit>0', array($this->_table, $uid));
  28. }
  29. public function fetch_all_by_unitprice($start, $perpage, $selectall = false) {
  30. $selectfields = $selectall ? '*' : 'uid, username, unitprice, credit AS show_credit, note AS show_note';
  31. return DB::fetch_all("SELECT {$selectfields} FROM %t ORDER BY unitprice DESC, credit DESC %i", array($this->_table, DB::limit($start, $perpage)));
  32. }
  33. public function fetch_all_by_credit($start, $perpage) {
  34. return DB::fetch_all('SELECT * FROM %t ORDER BY credit DESC %i', array($this->_table, DB::limit($start, $perpage)));
  35. }
  36. public function delete_by_credit($credit = 1) {
  37. return DB::query('DELETE FROM %t WHERE %i', array($this->_table, DB::field('credit', intval($credit), '<')));
  38. }
  39. public function delete_by_uid($uids) {
  40. if(!$uids) {
  41. return null;
  42. }
  43. return DB::delete($this->_table, DB::field('uid', $uids));
  44. }
  45. public function update_credit_by_uid($uid, $inc_credit, $limit_credit = true, $unitprice = false, $note = false) {
  46. $args = array($this->_table, $inc_credit);
  47. if($limit_credit === true) {
  48. $sql = ' AND credit>0';
  49. }
  50. if($unitprice !== false) {
  51. $args[] = $unitprice;
  52. $set_sql = ', unitprice=%d';
  53. }
  54. if($note !== false) {
  55. $args[] = $note;
  56. $set_sql .= ', note=%s';
  57. }
  58. $args[] = $uid;
  59. return DB::query("UPDATE %t SET credit=credit+'%d' {$set_sql} WHERE uid=%d {$sql}", $args);
  60. }
  61. }
  62. ?>