update user and roles model

This commit is contained in:
2026-03-09 14:11:38 +08:00
parent f95eff3963
commit 9022bc131a
2 changed files with 25 additions and 0 deletions
+17
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Model; namespace App\Model;
use Hyperf\Database\Model\Relations\BelongsToMany;
use Hyperf\Database\Model\Relations\HasMany; use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\DbConnection\Model\Model; use Hyperf\DbConnection\Model\Model;
@@ -38,4 +39,20 @@ class Role extends Model
{ {
return $this->hasMany(User::class, 'role_id'); 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');
}
} }
+8
View File
@@ -152,6 +152,14 @@ class User extends Model implements Authenticatable
return $this->hasMany(Platform::class, 'developer_id'); return $this->hasMany(Platform::class, 'developer_id');
} }
/**
* 用户的数据访问范围
*/
public function dataScopes(): HasMany
{
return $this->hasMany(UserDataScope::class, 'user_id');
}
// @TODO 重新实现删除用户时平台归属转移逻辑(Hyperf 不支持 static::deleting 事件绑定) // @TODO 重新实现删除用户时平台归属转移逻辑(Hyperf 不支持 static::deleting 事件绑定)
/** /**