0 已删除 'area_id', // 区域ID 'phone', // 手机号 'wxmp_open_id', 'wx_open_id', 'wx_union_id', 'school_id', 'grade_id', 'class_id', 'passive_rfid', 'realname', 'idcard', 'active_rfid', 'active_rfid_code', 'rfid_expire_date', 'student_no', 'card_status', 'rules_id', 'parents_id', 'sex', 'age', 'online_time', 'alarm_status', 'last_station_mac', 'birthday', 'addr', 'classes', 'manage_classes', 'subjects', 'card_type', 'student_type', 'student_status', 'voice', 'voice_size', 'voice_time', 'imei', 'battery_level', 'accesskey', 'secretkey', 'remark', 'dept_name', 'asset_admin', 'wifi_macs', 'user_no' ]; /** * 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日 * @throws \think\db\exception\DbException * @return \think\Paginator */ public function getList(): \think\Paginator { $no_display_roles = Db::table('roles')->whereIn('identify','personal,group_card_user,group_badge_user')->column('id'); $user = request()->user(); $res = $this->dataRange() ->withoutField(['updated_at'], true) ->catchSearch() ->alias('u') ->join('user_has_roles r','u.id=r.uid') // ->distinct(true) ->group('u.id') ->where('u.id','<>',1) //超级管理员账号不显示 ->where('u.id','<>',$user->id) //不显示自己 ->whereNotIn('r.role_id',$no_display_roles) ->catchLeftJoin(Department::class, 'id', 'department_id', ['department_name']) ->order($this->aliasField('id'), 'desc') ->paginate(); // var_dump($this->getLastSql()); return $res; } /** * 获取权限 * * @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 { // 获取超级管理配置 超级管理员全部权限 if ($uid == config('catch.permissions.super_admin_id')) { return Permissions::select()->column('id'); } $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); } /** * 后台根据权限标识判断用户是否拥有某个权限 * @param string $permission_mark * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * * 用法 request()->user()->can('permission@create'); */ public function can($permission_mark) { // 超级管理员直接返回true if (Utils::isSuperAdmin()){ return true; } // 查询当前用户的权限 return in_array( Permissions::where('permission_mark',$permission_mark)->value('id') ? : 0, $this->getPermissionsBy() ); } /** * 获取用户管理区域 */ public function getAreaIdBy() { return $this->where('id', request()->user()->id)->value('area_id'); } /** * 根据部门获取用户 */ public function getUserByDepart($value) { return $this ->where('department_id', $value) ->field('id as value,username as text') ->select(); } /** * 根据多个部门ID获取用户Ids */ public function getUserByDepartIds($value) { return $this ->whereIn('department_id', $value) ->column('id'); } /** * 获取推送用户(除家长、学生) */ public function getPushUserList() { // 查出非家长、学生角色id $allowed_roles = Db::table('roles')->whereNotIn('identify',['personal','group_card_user','group_badge_user'])->column('id'); $allowed_roles_text = join(',', $allowed_roles); // 查出有这些角色的用户信息 $res = $this->dataRange() ->catchSearch() ->alias('u') ->field('u.*') ->where('u.id','<>',1) //超级管理员账号不显示 ->distinct(true) ->join('user_has_roles uhr', "uhr.role_id in ({$allowed_roles_text}) and uhr.uid = u.id") ->select() ->toArray(); // 非管理员,可能存在是管理员添加的账号,查不到自己,追加自己 // var_dump($this->getLastSql()); if (!Utils::isSuperAdmin()){ $has_self = false; foreach ($res as $user) { if ($user['id'] == request()->user()->id) { $has_self = true; } } if (!$has_self) { array_push($res, request()->user()); } } return $res; } }