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\Department; |
13
|
|
|
|
14
|
|
|
use EasyDingTalk\Kernel\BaseClient; |
15
|
|
|
|
16
|
|
|
class Client extends BaseClient |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* 获取子部门 ID 列表 |
20
|
|
|
* |
21
|
|
|
* @param string $id 部门ID |
22
|
|
|
* |
23
|
|
|
* @return mixed |
24
|
|
|
*/ |
25
|
|
|
public function getSubDepartmentIds($id) |
26
|
|
|
{ |
27
|
|
|
return $this->client->get('department/list_ids', compact('id')); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* 获取部门列表 |
32
|
|
|
* |
33
|
|
|
* @param bool $isFetchChild |
34
|
|
|
* @param string $id |
35
|
|
|
* @param string $lang |
36
|
|
|
* |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function list($id = null, bool $isFetchChild = false, $lang = null) |
40
|
|
|
{ |
41
|
|
|
return $this->client->get('department/list', [ |
42
|
|
|
'id' => $id, 'lang' => $lang, 'fetch_child' => $isFetchChild ? 'true' : 'false', |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* 获取部门详情 |
48
|
|
|
* |
49
|
|
|
* @param string $id |
50
|
|
|
* @param string $lang |
51
|
|
|
* |
52
|
|
|
* @return mixed |
53
|
|
|
*/ |
54
|
|
|
public function get($id, $lang = null) |
55
|
|
|
{ |
56
|
|
|
return $this->client->get('department/get', compact('id', 'lang')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* 查询部门的所有上级父部门路径 |
61
|
|
|
* |
62
|
|
|
* @param string $id |
63
|
|
|
* |
64
|
|
|
* @return mixed |
65
|
|
|
*/ |
66
|
|
|
public function getParentsById($id) |
67
|
|
|
{ |
68
|
|
|
return $this->client->get('department/list_parent_depts_by_dept', compact('id')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* 查询指定用户的所有上级父部门路径 |
73
|
|
|
* |
74
|
|
|
* @param string $userId |
75
|
|
|
* |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function getParentsByUserId($userId) |
79
|
|
|
{ |
80
|
|
|
return $this->client->get('department/list_parent_depts', compact('userId')); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* 创建部门 |
85
|
|
|
* |
86
|
|
|
* @param array $params |
87
|
|
|
* |
88
|
|
|
* @return mixed |
89
|
|
|
*/ |
90
|
|
|
public function create(array $params) |
91
|
|
|
{ |
92
|
|
|
return $this->client->postJson('department/create', $params); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* 更新部门 |
97
|
|
|
* |
98
|
|
|
* @param string $id |
99
|
|
|
* @param array $params |
100
|
|
|
* |
101
|
|
|
* @return mixed |
102
|
|
|
*/ |
103
|
|
|
public function update($id, array $params) |
104
|
|
|
{ |
105
|
|
|
return $this->client->postJson('department/update', compact('id') + $params); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* 删除部门 |
110
|
|
|
* |
111
|
|
|
* @param string $id |
112
|
|
|
* |
113
|
|
|
* @return mixed |
114
|
|
|
*/ |
115
|
|
|
public function delete($id) |
116
|
|
|
{ |
117
|
|
|
return $this->client->get('department/delete', compact('id')); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|