update:优化用户的部门搜索,减少SQL

This commit is contained in:
JaguarJack
2020-11-04 10:06:23 +08:00
parent 97b7f73ff2
commit 7c4fa5c516
2 changed files with 20 additions and 15 deletions

View File

@@ -20,12 +20,20 @@ trait UserSearch
return $query->where($this->aliasField('status'), $value);
}
/**
* 查询部门下的用户
*
* @time 2020年11月04日
* @param $query
* @param $value
* @param $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return mixed
*/
public function searchDepartmentIdAttr($query, $value, $data)
{
$departmentIds = Department::getAllChildrenIds([$value]);
$departmentIds[] = intval($value);
return $query->whereIn($this->aliasField('department_id'), $departmentIds);
return $query->whereIn($this->aliasField('department_id'), Department::getChildrenDepartmentIds($value));
}
}