Passed
Push — master ( f7e515...09c178 )
by mingyoung
01:34
created

Client::getUserByCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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->app['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->app['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->app['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->app['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->app['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->app['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->app['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->app['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->app['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->app['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->app['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