table_common_magic.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_common_magic.php 27449 2012-02-01 05:32:35Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_magic extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_magic';
  15. $this->_pk = 'magicid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_data($available = false) {
  19. $available = $available !== false ? ' WHERE available='.intval($available) : '';
  20. return DB::fetch_all('SELECT * FROM %t %i ORDER BY displayorder', array($this->_table, $available));
  21. }
  22. public function check_identifier($identifier, $magicid) {
  23. return DB::result_first("SELECT COUNT(*) FROM %t WHERE identifier=%s AND magicid!=%d", array($this->_table, $identifier, $magicid));
  24. }
  25. public function count_page($operation) {
  26. $salevolume = $operation == 'index' ? '' : 'AND salevolume>0';
  27. return DB::result_first('SELECT COUNT(*) FROM %t WHERE available=1 %i', array($this->_table, $salevolume));
  28. }
  29. public function fetch_all_page($operation, $start, $limit) {
  30. if($operation == 'index') {
  31. $salevolume = '';
  32. $orderby = "displayorder";
  33. } else {
  34. $salevolume = 'AND salevolume>0';
  35. $orderby = "salevolume DESC";
  36. }
  37. return DB::fetch_all('SELECT * FROM %t WHERE available=1 %i ORDER BY %i LIMIT %d,%d', array($this->_table, $salevolume, $orderby, $start, $limit));
  38. }
  39. public function fetch_all_name_by_available($available = 1) {
  40. return DB::fetch_all('SELECT magicid, name FROM %t WHERE available=%d ORDER BY displayorder', array($this->_table, $available), $this->_pk);
  41. }
  42. public function fetch_by_identifier($identifier) {
  43. return DB::fetch_first('SELECT * FROM %t WHERE identifier=%s', array($this->_table, $identifier));
  44. }
  45. public function update_salevolume($magicid, $number) {
  46. DB::query("UPDATE %t SET num=num+('-%d'), salevolume=salevolume+'%d' WHERE magicid=%d", array($this->_table, $number, $number, $magicid));
  47. }
  48. public function fetch_member_magic($uid, $identifier) {
  49. return DB::fetch_first('SELECT mm.* FROM %t cm INNER JOIN %t mm ON mm.uid=%d AND mm.magicid=cm.magicid WHERE cm.identifier=%s', array($this->_table, 'common_member_magic', $uid, $identifier));
  50. }
  51. }
  52. ?>