diff --git a/backend/app/Model/Role.php b/backend/app/Model/Role.php index 9cd4be9..04539b7 100644 --- a/backend/app/Model/Role.php +++ b/backend/app/Model/Role.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Model; +use Hyperf\Database\Model\Relations\BelongsToMany; use Hyperf\Database\Model\Relations\HasMany; use Hyperf\DbConnection\Model\Model; @@ -38,4 +39,20 @@ class Role extends Model { return $this->hasMany(User::class, 'role_id'); } + + /** + * 角色授权的路由分组 + */ + public function routeGroups(): BelongsToMany + { + return $this->belongsToMany(RouteGroup::class, 'role_route_groups', 'role_id', 'group_id'); + } + + /** + * 角色的路由覆盖规则 + */ + public function routeOverrides(): HasMany + { + return $this->hasMany(RoleRouteOverride::class, 'role_id'); + } } diff --git a/backend/app/Model/User.php b/backend/app/Model/User.php index 40db58e..87a5fee 100644 --- a/backend/app/Model/User.php +++ b/backend/app/Model/User.php @@ -152,6 +152,14 @@ class User extends Model implements Authenticatable return $this->hasMany(Platform::class, 'developer_id'); } + /** + * 用户的数据访问范围 + */ + public function dataScopes(): HasMany + { + return $this->hasMany(UserDataScope::class, 'user_id'); + } + // @TODO 重新实现删除用户时平台归属转移逻辑(Hyperf 不支持 static::deleting 事件绑定) /**