Completed
Push — master ( e39fed...4b4c12 )
by mingyoung
18s queued 11s
created

Client::getInactiveUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the mingyoung/dingtalk.
5
 *
6
 * (c) 张铭阳 <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyDingTalk\User;
13
14
use EasyDingTalk\Kernel\BaseClient;
15
16
class Client extends BaseClient
17
{
18
    /**
19
     * 获取用户详情
20
     *
21
     * @param string $userid
22
     * @param string|null $lang
23
     *
24
     * @return mixed
25
     */
26
    public function get($userid, $lang = null)
27
    {
28
        return $this->client->get('user/get', compact('userid', 'lang'));
29
    }
30
31
    /**
32
     * 获取部门用户 Userid 列表
33
     *
34
     * @param int $departmentId
35
     *
36
     * @return mixed
37
     */
38
    public function getUserIds($departmentId)
39
    {
40
        return $this->client->get('user/getDeptMember', ['deptId' => $departmentId]);
41
    }
42
43
    /**
44
     * 获取部门用户
45
     *
46
     * @param int $departmentId
47
     * @param int $offset
48
     * @param int $size
49
     * @param string $order
50
     * @param string $lang
51
     *
52
     * @return mixed
53
     */
54
    public function getUsers($departmentId, $offset, $size, $order = null, $lang = null)
55
    {
56
        return $this->client->get('user/simplelist', [
57
            'department_id' => $departmentId, 'offset' => $offset, 'size' => $size, 'order' => $order, 'lang' => $lang,
58
        ]);
59
    }
60
61
    /**
62
     * 获取部门用户详情
63
     *
64
     * @param int $departmentId
65
     * @param int $offset
66
     * @param int $size
67
     * @param string $order
68
     * @param string $lang
69
     *
70
     * @return mixed
71
     */
72
    public function getDetailedUsers($departmentId, $offset, $size, $order = null, $lang = null)
73
    {
74
        return $this->client->get('user/listbypage', [
75
            'department_id' => $departmentId, 'offset' => $offset, 'size' => $size, 'order' => $order, 'lang' => $lang,
76
        ]);
77
    }
78
79
    /**
80
     * 获取管理员列表
81
     *
82
     * @return mixed
83
     */
84
    public function administrators()
85
    {
86
        return $this->client->get('user/get_admin');
87
    }
88
89
    /**
90
     * 获取管理员通讯录权限范围
91
     *
92
     * @param string $userid
93
     *
94
     * @return mixed
95
     */
96
    public function administratorScope($userid)
97
    {
98
        return $this->client->get('topapi/user/get_admin_scope', compact('userid'));
99
    }
100
101
    /**
102
     * 根据 Unionid 获取 Userid
103
     *
104
     * @param string $unionid
105
     *
106
     * @return mixed
107
     */
108
    public function getUseridByUnionid($unionid)
109
    {
110
        return $this->client->get('user/getUseridByUnionid', compact('unionid'));
111
    }
112
113
    /**
114
     * 创建用户
115
     *
116
     * @param array $params
117
     *
118
     * @return mixed
119
     */
120
    public function create(array $params)
121
    {
122
        return $this->client->postJson('user/create', $params);
123
    }
124
125
    /**
126
     * 更新用户
127
     *
128
     * @param string $userid
129
     * @param array $params
130
     *
131
     * @return mixed
132
     */
133
    public function update($userid, array $params)
134
    {
135
        return $this->client->postJson('user/update', compact('userid') + $params);
136
    }
137
138
    /**
139
     * 删除用户
140
     *
141
     * @param $userid
142
     *
143
     * @return mixed
144
     */
145
    public function delete($userid)
146
    {
147
        return $this->client->get('user/delete', compact('userid'));
148
    }
149
150
    /**
151
     * 企业内部应用免登获取用户 Userid
152
     *
153
     * @param string $code
154
     *
155
     * @return mixed
156
     */
157
    public function getUserByCode($code)
158
    {
159
        return $this->client->get('user/getuserinfo', compact('code'));
160
    }
161
162
    /**
163
     * 批量增加员工角色
164
     *
165
     * @param array|string $userIds
166
     * @param array|string $roleIds
167
     *
168
     * @return mixed
169
     */
170
    public function addRoles($userIds, $roleIds)
171
    {
172
        $userIds = is_array($userIds) ? implode(',', $userIds) : $userIds;
173
        $roleIds = is_array($roleIds) ? implode(',', $roleIds) : $roleIds;
174
175
        return $this->client->postJson('topapi/role/addrolesforemps', compact('userIds', 'roleIds'));
176
    }
177
178
    /**
179
     * 批量删除员工角色
180
     *
181
     * @param array|string $userIds
182
     * @param array|string $roleIds
183
     *
184
     * @return mixed
185
     */
186
    public function removeRoles($userIds, $roleIds)
187
    {
188
        $userIds = is_array($userIds) ? implode(',', $userIds) : $userIds;
189
        $roleIds = is_array($roleIds) ? implode(',', $roleIds) : $roleIds;
190
191
        return $this->client->postJson('topapi/role/removerolesforemps', compact('userIds', 'roleIds'));
192
    }
193
194
    /**
195
     * 获取企业员工人数
196
     *
197
     * @param int $onlyActive
198
     *
199
     * @return mixed
200
     */
201
    public function getCount($onlyActive = 0)
202
    {
203
        return $this->client->get('user/get_org_user_count', compact('onlyActive'));
204
    }
205
206
    /**
207
     * 获取企业已激活的员工人数
208
     *
209
     * @return mixed
210
     */
211
    public function getActivatedCount()
212
    {
213
        return $this->getCount(1);
214
    }
215
216
    /**
217
     * 根据员工手机号获取 Userid
218
     *
219
     * @param string $phone
220
     *
221
     * @return mixed
222
     */
223
    public function getUserIdByPhone($phone = '')
224
    {
225
        return $this->client->get('user/get_by_mobile', compact('phone'));
226
    }
227
228
    /**
229
     * 未登录钉钉的员工列表
230
     *
231
     * @param string $query_date
232
     * @param int $offset
233
     * @param int $size
234
     *
235
     * @return mixed
236
     */
237
    public function getInactiveUsers($query_date, $offset, $size)
238
    {
239
        return $this->client->postJson('topapi/inactive/user/get', [
240
            'query_date' => $query_date, 'offset' => $offset, 'size' => $size
241
        ]);
242
    }
243
}
244