0 已删除 ]; /** * set password * * @time 2019年12月07日 * @param $value * @return false|string */ public function setPasswordAttr($value) { return password_hash($value, PASSWORD_DEFAULT); } /** * 用户列表 * * @time 2019年12月08日 * @param $search * @throws \think\db\exception\DbException * @return \think\Paginator */ public function getList($search): \think\Paginator { return $this->withoutField(['updated_at'], true) ->catchSearch() ->catchLeftJoin(Department::class, 'id', 'department_id', ['department_name']) ->order('users.id', 'desc') ->paginate($search['limit'] ?? parent::LIMIT); } /** * 获取权限 * * @time 2019年12月12日 * @param $uid * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @return array */ public function getPermissionsBy($uid = 0): array { $roles = $uid ? $this->findBy($uid)->getRoles() : $this->getRoles(); $permissionIds = []; foreach ($roles as $role) { $permissionIds = array_merge($permissionIds, $role->getPermissions()->column('id')); } return array_unique($permissionIds); } }