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

@@ -46,27 +46,25 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// <param name="userIds"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public async Task GiveUserSetRoleAsync(List<Guid> userIds, List<Guid> roleIds)
public async Task GiveUserSetRoleAsync(List<Guid> userIds, List<Guid>? roleIds)
{
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
//删除用户之前所有的用户角色关系
await _repositoryUserRole.DeleteAsync(u => userIds.Contains(u.UserId));
if (roleIds is not null)
{
//添加新的关系
List<UserRoleEntity> userRoleEntities = new();
//遍历用户
foreach (var userId in userIds)
{
//添加新的关系
List<UserRoleEntity> userRoleEntities = new();
foreach (var roleId in roleIds)
{
userRoleEntities.Add(new UserRoleEntity() { UserId = userId, RoleId = roleId });
}
//一次性批量添加
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
}
//一次性批量添加
await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
}
}
@@ -77,25 +75,24 @@ namespace Yi.Framework.Rbac.Domain.Managers
/// <param name="userIds"></param>
/// <param name="postIds"></param>
/// <returns></returns>
public async Task GiveUserSetPostAsync(List<Guid> userIds, List<Guid> postIds)
public async Task GiveUserSetPostAsync(List<Guid> userIds, List<Guid>? postIds)
{
//删除用户之前所有的用户角色关系(物理删除,没有恢复的必要)
await _repositoryUserPost.DeleteAsync(u => userIds.Contains(u.UserId));
if (postIds is not null)
{
//添加新的关系
List<UserPostEntity> userPostEntities = new();
//遍历用户
foreach (var userId in userIds)
{
//添加新的关系
List<UserPostEntity> userPostEntities = new();
foreach (var post in postIds)
{
userPostEntities.Add(new UserPostEntity() { UserId = userId, PostId = post });
}
//一次性批量添加
await _repositoryUserPost.InsertRangeAsync(userPostEntities);
}
//一次性批量添加
await _repositoryUserPost.InsertRangeAsync(userPostEntities);
}
}
@@ -137,10 +134,7 @@ namespace Yi.Framework.Rbac.Domain.Managers
public async Task SetDefautRoleAsync(Guid userId)
{
var role = await _roleRepository.GetFirstAsync(x => x.RoleCode == UserConst.DefaultRoleCode);
if (role is not null)
{
await GiveUserSetRoleAsync(new List<Guid> { userId }, new List<Guid> { role.Id });
}
await GiveUserSetRoleAsync(new List<Guid> { userId }, new List<Guid> { role.Id });
}
private void ValidateUserName(UserAggregateRoot input)