table_common_member_status.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_member_status.php 28405 2012-02-29 03:47:50Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_member_status extends discuz_table_archive
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_member_status';
  15. $this->_pk = 'uid';
  16. $this->_pre_cache_key = 'common_member_status_';
  17. parent::__construct();
  18. }
  19. public function increase($uids, $setarr) {
  20. $uids = array_map('intval', (array)$uids);
  21. $sql = array();
  22. $allowkey = array('buyercredit', 'sellercredit', 'favtimes', 'sharetimes');
  23. foreach($setarr as $key => $value) {
  24. if(($value = intval($value)) && in_array($key, $allowkey)) {
  25. $sql[] = "`$key`=`$key`+'$value'";
  26. }
  27. }
  28. if(!empty($sql)){
  29. DB::query("UPDATE ".DB::table($this->_table)." SET ".implode(',', $sql)." WHERE uid IN (".dimplode($uids).")", 'UNBUFFERED');
  30. $this->increase_cache($uids, $setarr);
  31. }
  32. }
  33. public function count_by_ip($ips) {
  34. return !empty($ips) ? DB::result_first('SELECT COUNT(*) FROM %t WHERE regip IN(%n) OR lastip IN (%n)', array($this->_table, $ips, $ips)) : 0;
  35. }
  36. public function fetch_all_by_ip($ips, $start, $limit) {
  37. $data = array();
  38. if(!empty($ips) && $limit) {
  39. $data = DB::fetch_all('SELECT * FROM %t WHERE regip IN(%n) OR lastip IN (%n) LIMIT %d, %d', array($this->_table, $ips, $ips, $start, $limit), 'uid');
  40. }
  41. return $data;
  42. }
  43. public function fetch_all_orderby_lastpost($uids, $start, $limit) {
  44. $uids = dintval($uids, true);
  45. if($uids) {
  46. return DB::fetch_all('SELECT * FROM %t WHERE uid IN(%n) ORDER BY lastpost DESC '.DB::limit($start, $limit), array($this->_table, $uids), $this->_pk);
  47. }
  48. return array();
  49. }
  50. public function count_by_lastactivity_invisible($timestamp, $invisible = 0) {
  51. $addsql = '';
  52. if($invisible === 1) {
  53. $addsql = ' AND invisible = 1';
  54. } elseif($invisible === 2) {
  55. $addsql = ' AND invisible = 0';
  56. }
  57. return $timestamp ? DB::result_first('SELECT COUNT(*) FROM %t WHERE lastactivity >= %d'.$addsql, array($this->_table, $timestamp)) : 0;
  58. }
  59. public function fetch_all_by_lastactivity_invisible($timestamp, $invisible = 0, $start = 0, $limit = 0) {
  60. $data = array();
  61. if($timestamp) {
  62. $addsql = '';
  63. if($invisible === 1) {
  64. $addsql = ' AND invisible = 1';
  65. } elseif($invisible === 2) {
  66. $addsql = ' AND invisible = 0';
  67. }
  68. $data = DB::fetch_all('SELECT * FROM %t WHERE lastactivity >= %d'.$addsql.' ORDER BY lastactivity DESC'.DB::limit($start, $limit), array($this->_table, $timestamp), $this->_pk);
  69. }
  70. return $data;
  71. }
  72. public function fetch_all_onlines($uids, $lastactivity, $start = 0, $limit = 0) {
  73. $data = array();
  74. $uids = dintval($uids, true);
  75. if(!empty($uids)) {
  76. $ppp = ($ppp = getglobal('ppp')) ? $ppp + 30 : 100;
  77. if(count($uids) > $ppp) {
  78. $uids = array_slice($uids, 0, $ppp);
  79. }
  80. $length = $limit ? $limit : $start;
  81. $i = 0;
  82. foreach($this->fetch_all($uids) as $uid => $member) {
  83. if($member['lastactivity'] >= $lastactivity) {
  84. $data[$uid] = $member;
  85. if($length && $i >= $length) {
  86. break;
  87. }
  88. $i++;
  89. }
  90. }
  91. }
  92. return $data;
  93. }
  94. }
  95. ?>