0 已删除 ]; public function getList() { return $this->catchSearch() ->order('id', 'desc') ->select() ->toArray(); } /** * * @time 2019年12月08日 * @return \think\model\relation\BelongsToMany */ public function users(): \think\model\relation\BelongsToMany { return $this->belongsToMany(Users::class, 'user_has_roles', 'uid', 'role_id'); } public static function getDepartmentUserIdsBy($roles) { $uids = []; $isAll = false; $user = request()->user(); foreach ($roles as $role) { switch ($role->data_range) { case self::ALL_DATA: $isAll = true; break; case self::SELF_CHOOSE: $departmentIds = array_merge(array_column($role->getDepartments()->toArray(), 'id')); $uids = array_merge($uids, Users::getUserIdsByDepartmentIds($departmentIds)); break; case self::SELF_DATA: $uids[] = $user->id; break; case self::DEPARTMENT_DOWN_DATA: case self::DEPARTMENT_DATA: $uids = array_merge($uids, Users::getUserIdsByDepartmentIds([$user->department_id])); break; default: break; } // 如果有全部数据 直接跳出 if ($isAll) { break; } } return $uids; } }