更新用户权限模块功能
This commit is contained in:
@@ -324,4 +324,40 @@ class DepartmentService
|
||||
}
|
||||
return $this->isDescendant($id, $child->parent_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门及所有子部门的ID列表
|
||||
*
|
||||
* @param int $departmentId 部门ID
|
||||
* @param array $departments 所有部门数据
|
||||
* @return array
|
||||
*/
|
||||
public function getDepartmentAndChildrenIds(int $departmentId, array $departments = null): array
|
||||
{
|
||||
if ($departments === null) {
|
||||
$departments = Department::where('status', 1)->get()->keyBy('id')->toArray();
|
||||
}
|
||||
|
||||
$ids = [$departmentId];
|
||||
$this->collectChildrenIds($departmentId, $departments, $ids);
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归收集子部门ID
|
||||
*
|
||||
* @param int $parentId 父部门ID
|
||||
* @param array $departments 所有部门数据
|
||||
* @param array &$ids ID收集数组
|
||||
*/
|
||||
private function collectChildrenIds(int $parentId, array $departments, array &$ids): void
|
||||
{
|
||||
foreach ($departments as $department) {
|
||||
if ($department['parent_id'] == $parentId) {
|
||||
$ids[] = $department['id'];
|
||||
$this->collectChildrenIds($department['id'], $departments, $ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user