feat: 新增VIP充值接口并支持通过角色代码为用户分配角色

This commit is contained in:
ccnetcore
2025-08-10 11:53:28 +08:00
parent a9c3a1bcec
commit 7038d31c53
8 changed files with 181 additions and 58 deletions

View File

@@ -241,5 +241,29 @@ namespace Yi.Framework.Rbac.Application.Services.System
{
return base.PostImportExcelAsync(input);
}
/// <summary>
/// 通过角色代码给用户添加角色
/// </summary>
/// <param name="userId">用户ID</param>
/// <param name="roleCodes"></param>
/// <returns></returns>
public async Task AddUserRoleByRoleCodeAsync(Guid userId, List<string> roleCodes)
{
// 根据角色代码查找角色ID
var roleRepository = LazyServiceProvider.LazyGetRequiredService<ISqlSugarRepository<RoleAggregateRoot>>();
var roleIds = await roleRepository._DbQueryable
.Where(r => roleCodes.Contains(r.RoleCode) && r.State == true)
.Select(r=>r.Id)
.ToListAsync();
if (!roleIds.Any())
{
return;
}
// 使用UserManager给用户设置角色
await _userManager.GiveUserSetRoleAsync(new List<Guid> { userId }, roleIds);
}
}
}