Users.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. namespace We7\Table\Users;
  7. class Users extends \We7Table {
  8. protected $tableName = 'users';
  9. protected $primaryKey = 'uid';
  10. protected $field = array(
  11. 'owner_uid',
  12. 'groupid',
  13. 'username',
  14. 'password',
  15. 'salt',
  16. 'type',
  17. 'status',
  18. 'joindate',
  19. 'joinip',
  20. 'lastvisit',
  21. 'lastip',
  22. 'remark',
  23. 'starttime',
  24. 'endtime',
  25. 'founder_groupid',
  26. 'register_type',
  27. 'openid',
  28. 'welcome_link',
  29. 'notice_setting',
  30. );
  31. protected $default = array(
  32. 'owner_uid' => '0',
  33. 'groupid' => '0',
  34. 'username' => '',
  35. 'password' => '',
  36. 'salt' => '',
  37. 'type' => '1',
  38. 'status' => '2',
  39. 'joindate' => '0',
  40. 'joinip' => '',
  41. 'lastvisit' => '0',
  42. 'lastip' => '',
  43. 'remark' => '',
  44. 'starttime' => '0',
  45. 'endtime' => '0',
  46. 'founder_groupid' => '0',
  47. 'register_type' => '0',
  48. 'openid' => '0',
  49. 'welcome_link' => '',
  50. 'notice_setting' => '',
  51. );
  52. public function getNoticeSettingByUid($uid) {
  53. $notice_setting = iunserializer($this->where('uid', $uid)->getcolumn('notice_setting'));
  54. if (!is_array($notice_setting)) {
  55. $notice_setting = array();
  56. }
  57. return $notice_setting;
  58. }
  59. public function getUsersList($join_profile = true) {
  60. $this->query->from('users', 'u');
  61. $select = 'u.uid, u.owner_uid, u.groupid, u.username, u.type, u.status, u.joindate, u.joinip, u.lastvisit,
  62. u.lastip, u.remark, u.starttime, u.endtime, u.founder_groupid,u.register_type, u.openid, u.welcome_link,
  63. b.third_nickname bind_console_name';
  64. $this->query->leftjoin('users_bind', 'b')->on(array('u.uid' => 'b.uid', 'b.third_type' => USER_REGISTER_TYPE_CONSOLE));
  65. if ($join_profile) {
  66. $select .= ',p.avatar as avatar, p.mobile as mobile, p.uid as puid, p.mobile as mobile';
  67. $this->query->leftjoin('users_profile', 'p')->on(array('u.uid' => 'p.uid'));
  68. }
  69. return $this->query->select($select)->orderby('u.uid', 'DESC')->getall('uid');
  70. }
  71. public function searchFounderOwnUsers($founder_uid) {
  72. $this->query
  73. ->innerjoin('users_founder_own_users', 'f')
  74. ->on(array('u.uid' => 'f.uid'))
  75. ->where('f.founder_uid', $founder_uid);
  76. return $this;
  77. }
  78. public function searchWithViceFounder() {
  79. global $_W;
  80. if (user_is_vice_founder()) {
  81. $this->query->where('u.owner_uid', $_W['uid']);
  82. }
  83. return $this;
  84. }
  85. public function searchWithStatus($status) {
  86. $this->query->where('u.status', $status);
  87. return $this;
  88. }
  89. public function searchWithType($type) {
  90. $this->query->where('u.type', $type);
  91. return $this;
  92. }
  93. public function searchWithFounder($founder_groupids) {
  94. $this->query->where('u.founder_groupid', $founder_groupids);
  95. return $this;
  96. }
  97. public function searchWithoutFounder()
  98. {
  99. return $this->query->where('u.founder_groupid !=', ACCOUNT_MANAGE_GROUP_FOUNDER);
  100. }
  101. public function searchWithTimelimitStatus($status) {
  102. if ($status == 1) {
  103. $this->where(function ($query) {
  104. $query->where('u.endtime', 0)
  105. ->whereor('u.endtime', USER_ENDTIME_GROUP_UNLIMIT_TYPE)
  106. ->whereor('u.endtime >', TIMESTAMP);
  107. });
  108. } elseif ($status == 2) {
  109. $this->where(function ($query) {
  110. $query->where('u.endtime >', USER_ENDTIME_GROUP_UNLIMIT_TYPE)
  111. ->where('u.endtime <=', TIMESTAMP)
  112. ->whereor('u.endtime', USER_ENDTIME_GROUP_DELETE_TYPE);
  113. });
  114. }
  115. return $this;
  116. }
  117. public function searchWithEndtime($day) {
  118. $this->query->where('u.endtime >', USER_ENDTIME_GROUP_UNLIMIT_TYPE)->where('u.endtime <', TIMESTAMP + 86400 * $day);
  119. return $this;
  120. }
  121. public function searchWithMobile() {
  122. $this->query->where('p.mobile !=', '');
  123. return $this;
  124. }
  125. public function searchWithGroupId($group_id) {
  126. $this->query->where('u.groupid', $group_id);
  127. return $this;
  128. }
  129. public function searchWithSendStatus() {
  130. $this->query->where('p.send_expire_status', 0);
  131. return $this;
  132. }
  133. public function searchWithNameOrMobile($search, $join_profile = true, $uid_in = array()) {
  134. if ($join_profile) {
  135. $this->query->where(function ($query) use ($search) {
  136. $query->where('u.username LIKE', "%{$search}%")->whereor('p.mobile LIKE', "%{$search}%");
  137. });
  138. } else {
  139. if (empty($uid_in)) {
  140. $this->query->where('u.username LIKE', "%{$search}%");
  141. } else {
  142. $this->query->where('u.username LIKE', "%{$search}%")->whereor('u.uid', $uid_in);
  143. }
  144. }
  145. return $this;
  146. }
  147. public function searchWithOwnerUid($owner_uid) {
  148. $this->query->where('u.owner_uid', $owner_uid);
  149. return $this;
  150. }
  151. public function userOrderBy($field = 'uid', $order = 'desc') {
  152. $field = !empty($field) ? $field : 'joindate';
  153. $order = !empty($order) ? $order : 'desc';
  154. $this->query->orderby($field, $order);
  155. return $this;
  156. }
  157. public function searchWithUsersProfile() {
  158. return $this->query->from($this->tableName, 'u')
  159. ->leftjoin('users_profile', 'p')
  160. ->on(array('u.uid' => 'p.uid'));
  161. }
  162. }