update:支持无限级部门搜索
This commit is contained in:
parent
a9671b6227
commit
0b5c883012
@ -39,4 +39,26 @@ class Department extends CatchModel
|
||||
->catchOrder()
|
||||
->select()->toTree();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门
|
||||
*
|
||||
* @time 2020年11月04日
|
||||
* @param array $departmentIds
|
||||
* @throws DbException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllChildrenIds(array $departmentIds)
|
||||
{
|
||||
$childDepartmentIds = self::whereIn('parent_id', $departmentIds)->column('id');
|
||||
|
||||
if (!empty($childDepartmentIds)) {
|
||||
$childDepartmentIds = array_merge($childDepartmentIds, self::getAllChildrenIds($childDepartmentIds));
|
||||
}
|
||||
|
||||
return $childDepartmentIds;
|
||||
}
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ trait UserSearch
|
||||
|
||||
public function searchDepartmentIdAttr($query, $value, $data)
|
||||
{
|
||||
$departmentIds = Department::where('parent_id', $value)->column('id');
|
||||
$departmentIds[] = $value;
|
||||
$departmentIds = Department::getAllChildrenIds([$value]);
|
||||
|
||||
$departmentIds[] = intval($value);
|
||||
|
||||
return $query->whereIn($this->aliasField('department_id'), $departmentIds);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user