Blame view

framework/table/users.table.php 5.37 KB
4d84a934   曹明   初始代码提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
/**
 * [WeEngine System] Copyright (c) 2014 WE7.CC
 * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
 */

defined('IN_IA') or exit('Access Denied');

class UsersTable extends We7Table {
	protected $tableName = 'users';
	protected $field = array('uid');

	public function searchUsersList() {
		global $_W;
		$this->query->from('users', 'u')
				->select('u.*, p.avatar as avatar, p.mobile as mobile, p.uid as puid, p.mobile as mobile')
				->leftjoin('users_profile', 'p')
				->on(array('u.uid' => 'p.uid'))
				->orderby('u.uid', 'DESC');
		if (user_is_vice_founder()) {
			$this->query->where('u.owner_uid', $_W['uid']);
		}
		return $this->query->getall('uid');
	}

	
	public function userOwnedAccount($uid) {
		$uniacid_list = $this->query->from('uni_account_users')->where('uid', $uid)->getall('uniacid');
		return array_keys($uniacid_list);
	}

	public function userOwnedAccountRole($uid, $uniacid = 0) {
		if (empty($uniacid)) {
			$role = $this->query->from('uni_account_users')->where('uid', $uid)->getall('role');
			return array_keys($role);
		} else {
			$role = $this->query->from('uni_account_users')->where(array('uid' => $uid, 'uniacid' => $uniacid))->get();
			return $role['role'];
		}
	}


	public function searchWithStatus($status) {
		$this->query->where('u.status', $status);
		return $this;
	}

	public function searchWithType($type) {
		$this->query->where('u.type', $type);
		return $this;
	}

	public function searchWithFounder($founder_groupids) {
		$this->query->where('u.founder_groupid', $founder_groupids);
		return $this;
	}

	public function searchWithEndtime($day) {
		$this->query->where('u.endtime !=', 0)->where('u.endtime <', TIMESTAMP + 86400 * $day);
		return $this;
	}

	public function searchWithMobile() {
		$this->query->where('p.mobile !=', '');;
		return $this;
	}

	public function searchWithGroupId($group_id) {
		$this->query->where('u.groupid', $group_id);
		return $this;
	}

	public function searchWithSendStatus() {
		$this->query->where('p.send_expire_status', 0);;
		return $this;
	}

	public function searchWithNameOrMobile($search) {
		$this->query->where(function($query) use ($search){
			$query->where('u.username LIKE', "%{$search}%")->whereor('p.mobile LIKE', "%{$search}%");
		});
		return $this;
	}

	public function searchWithOwnerUid($owner_uid) {
		$this->query->where('u.owner_uid', $owner_uid);
		return $this;
	}

	public function accountUsersNum($uid) {
		return $this->query->from('uni_account_users')->where('uid', $uid)->count();
	}

	public function usersGroup() {
		return $this->query->from('users_group')->getall('id');
	}

	public function usersGroupInfo($groupid) {
		return $this->query->from('users_group')->where('id', $groupid)->get();
	}

	public function usersInfo($uid) {
		return $this->query->from('users')->where('uid', $uid)->get();
	}

	public function usersFounderGroup() {
		return $this->query->from('users_founder_group')->getall('id');
	}

	public function userFounderGroupInfo($groupid) {
		return $this->query->from('users_founder_group')->where('id', $groupid)->get();
	}

	public function userProfileMobile($mobile) {
		return $this->query->from('users_profile')->where('mobile', $mobile)->get();
	}

	public function userVerifyCode($receiver, $verifycode) {
		return $this->query->from('uni_verifycode')->where('receiver', $receiver)->where('verifycode', $verifycode)->where('uniacid', 0)->get();
	}

	public function userBindInfo($bind_sign, $third_type) {
		return $this->query->from('users_bind')->where('bind_sign', $bind_sign)->where('third_type', $third_type)->get();
	}

	public function userProfileFields() {
		return $this->query->from('profile_fields')->where('available', 1)->where('showinregister', 1)->orderby('displayorder', 'desc')->getall('field');
	}

	public function userBind() {
		return $this->query->from('users_bind')->getall('bind_sign');
	}

	public function bindSearchWithUser($uid) {
		$this->query->where('uid', $uid);
		return $this;
	}

	public function bindSearchWithType($type) {
		$this->query->where('third_type', $type);
		return $this;
	}

	public function bindInfo() {
		return $this->query->from('users_bind')->get();
	}
	public function userProfile($uid) {
		return $this->query->from('users_profile')->where('uid', $uid)->get();
	}

	public function userAccountRole($role) {
		$this->query->where('role', $role);
		return $this;
	}

	public function userOrderBy($field = 'uid', $order = 'desc') {
		$field = !empty($field) ? $field : 'joindate';
		$order = !empty($order) ? $order : 'desc';
		$this->query->orderby($field, $order);
		return $this;
	}

	public function userAccountDelete($uid, $is_recycle = false) {
		if (!empty($is_recycle)) {
			pdo_update('users', array('status' => USER_STATUS_BAN) , array('uid' => $uid));
			return true;
		}
		$user_info = $this->usersInfo($uid);
		if ($user_info['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
			pdo_update('users', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
			pdo_update('users_group', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
			pdo_update('uni_group', array('owner_uid' => ACCOUNT_NO_OWNER_UID), array('owner_uid' => $uid));
		}
		pdo_delete('users', array('uid' => $uid));
		pdo_delete('uni_account_users', array('uid' => $uid));
		pdo_delete('users_profile', array('uid' => $uid));
		pdo_delete('users_bind', array('uid' => $uid));
		return true;
	}
}