Users.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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() {
  60. return $this->query
  61. ->from('users', 'u')
  62. ->select(
  63. 'u.uid, u.owner_uid, u.groupid, u.username, u.type, u.status, u.joindate, u.joinip, u.lastvisit,
  64. u.lastip, u.remark, u.starttime, u.endtime, u.founder_groupid,u.register_type, u.openid, u.welcome_link,
  65. p.avatar as avatar, p.mobile as mobile, p.uid as puid, p.mobile as mobile'
  66. )
  67. ->leftjoin('users_profile', 'p')
  68. ->on(array('u.uid' => 'p.uid'))
  69. ->orderby('u.uid', 'DESC')
  70. ->getall('uid');
  71. }
  72. public function searchFounderOwnUsers($founder_uid) {
  73. $this->query
  74. ->innerjoin('users_founder_own_users', 'f')
  75. ->on(array('u.uid' => 'f.uid'))
  76. ->where('f.founder_uid', $founder_uid);
  77. return $this;
  78. }
  79. public function searchWithViceFounder() {
  80. global $_W;
  81. if (user_is_vice_founder()) {
  82. $this->query->where('u.owner_uid', $_W['uid']);
  83. }
  84. return $this;
  85. }
  86. public function searchWithStatus($status) {
  87. $this->query->where('u.status', $status);
  88. return $this;
  89. }
  90. public function searchWithType($type) {
  91. $this->query->where('u.type', $type);
  92. return $this;
  93. }
  94. public function searchWithFounder($founder_groupids) {
  95. $this->query->where('u.founder_groupid', $founder_groupids);
  96. return $this;
  97. }
  98. public function searchWithoutFounder()
  99. {
  100. return $this->query->where('u.founder_groupid !=', ACCOUNT_MANAGE_GROUP_FOUNDER);
  101. }
  102. public function searchWithTimelimitStatus($status) {
  103. if ($status == 1) {
  104. $this->where(function ($query) {
  105. $query->where('u.endtime', 0)->whereor('u.endtime >', TIMESTAMP);
  106. });
  107. } elseif ($status == 2) {
  108. $this->where('u.endtime !=', 0)->where('u.endtime <=', TIMESTAMP);
  109. }
  110. return $this;
  111. }
  112. public function searchWithEndtime($day) {
  113. $this->query->where('u.endtime !=', 0)->where('u.endtime <', TIMESTAMP + 86400 * $day);
  114. return $this;
  115. }
  116. public function searchWithMobile() {
  117. $this->query->where('p.mobile !=', '');
  118. return $this;
  119. }
  120. public function searchWithGroupId($group_id) {
  121. $this->query->where('u.groupid', $group_id);
  122. return $this;
  123. }
  124. public function searchWithSendStatus() {
  125. $this->query->where('p.send_expire_status', 0);
  126. return $this;
  127. }
  128. public function searchWithNameOrMobile($search) {
  129. $this->query->where('u.username LIKE', "%{$search}%")->whereor('p.mobile LIKE', "%{$search}%");
  130. return $this;
  131. }
  132. public function searchWithOwnerUid($owner_uid) {
  133. $this->query->where('u.owner_uid', $owner_uid);
  134. return $this;
  135. }
  136. public function userOrderBy($field = 'uid', $order = 'desc') {
  137. $field = !empty($field) ? $field : 'joindate';
  138. $order = !empty($order) ? $order : 'desc';
  139. $this->query->orderby($field, $order);
  140. return $this;
  141. }
  142. }