feat: 新增VIP充值接口并支持通过角色代码为用户分配角色
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user