0 已删除 ]; public function getList() { $where = array(); if (!Utils::isSuperAdmin()) { $user = request()->user(); /* $role_id=Db::table("user_has_roles")->where('uid',$user->id)->value('role_id'); $parentiIds = $this->getParentRoleIds($role_id); $childIds = $this->getChildrenRoleIds($role_id); $roleIds = array_merge($parentiIds,$childIds); $where[] = ['id','in',$roleIds]; */ $role_ids = Db::table("user_has_roles")->where('uid',$user->id)->column('role_id'); $childIds = $this->getChildrenRoleIds($role_ids); $roleIds = array_merge($role_ids,$childIds); if (!empty($roleIds)) { $where[] = ['id','in',$roleIds]; } } // $no_display_roles = $this->whereIn('identify','student,teacher,parents,schoolmaster')->column('id'); // var_dump($this->getLastSql()); return $this->where($where) // ->whereNotIn('id',$no_display_roles) ->catchSearch() ->order('id', 'desc') ->where('id','<>',1) //超级管理员账号不显示 ->select() ->toTree(); } /** * 判断是否是全部数据权限 * @time 2021年09月17日 * @return datarange */ public function isAllDataRange(){ $user = request()->user(); if (empty($roles)) { $roles = $user->getRoles(); } //判断是否 foreach ($roles as $role) { // 如果有全部数据 直接跳出 if ($role->data_range == Roles::ALL_DATA) { return true; } } return false; } //用户管理获取角色(除了家长、学生、教师、班主任、校长等) public function getPartList() { $where = array(); if (!Utils::isSuperAdmin()) { $user = request()->user(); $roleIds = Db::table("user_has_roles")->where('uid',$user->id)->column('role_id'); if (!empty($roleIds)) { $where[] = ['id','in',$roleIds]; } } // 获取学校角色 $no_display_roles = static::getDeviceUserRoleids(); return $this->where($where) ->whereNotIn('id',$no_display_roles) ->catchSearch() ->order('id', 'desc') ->select() ->toTree(); } /** * * @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'); } /** * 获取子角色IDS * * @time 2020年11月04日 * @param $id * @throws DbException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @return mixed */ public static function getChildrenRoleIds($roleIds) { $roleIds = Roles::field(['id', 'parent_id'])->select()->getAllChildrenIds($roleIds); // $roleIds[] = $id; return $roleIds; } /** * 获取上级至顶级角色ids */ public function getParentRoleIds($id) { $ids = []; $pid = Roles::where('id', $id)->value('parent_id'); if ($pid > 0) { $ids[] = $pid; $parentId = $this->getParentRoleIds($pid); $ids = array_merge($ids, $parentId); } return $ids; } /** * 获取设备用户角色id */ public static function getDeviceUserRoleids() { return static::whereIn('identify','personal,group_card_user,group_badge_user')->column('id'); } /** * 根据角色得标识获取所有用户得id */ public static function getUserIdByRoleIdentify($Identify) { $role_id = Roles::where('identify',$Identify)->value('id'); $users_id = Db::name('user_has_roles')->where('role_id',$role_id)->field('uid')->select(); return $users_id; } }