云库增加 AI识图,缓存,我的云库收藏增加安全标志
调用外部API 扣费
This commit is contained in:
1 parent
7c29e57623
commit
150e8644b7
49 files changed
+1069
-28
No files matched your search
@@ -1,23 +1,23 @@
|
||||
using MAX.Framework.Conventions;
|
||||
using MAX.Framework.Dtos;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Store.Framework.Base;
|
||||
using Store.Users.Commands;
|
||||
using Store.Users.Contracts.Dtos;
|
||||
using Store.Users.Dtos;
|
||||
using Store.Users.Entities;
|
||||
using Store.Users.Services;
|
||||
using MAX.Framework.Dtos;
|
||||
using MAX.Framework.Conventions;
|
||||
|
||||
namespace Store.Users.Controllers;
|
||||
|
||||
/// <summary>用户模块接口;所有管理操作均以当前登录身份对应的数据库账户进行授权。</summary>
|
||||
[ApiController]
|
||||
[DefaultHttpPost]
|
||||
[Authorize]
|
||||
[Route("v{version:apiVersion}/user/[action]")]
|
||||
public class UserController(UserManagementService users, UserFundsService funds, IMediator mediator) : ControllerBase
|
||||
[Route("[controller]/[action]")]
|
||||
public class UserController(UserManagementService users, UserFundsService funds, IMediator mediator) : AppControllerBase
|
||||
{
|
||||
/// <summary>获取本人或授权范围内的用户信息,响应不包含密码。</summary>
|
||||
[EndpointSummary("获取用户信息")]
|
||||
|
||||
@@ -5,22 +5,28 @@ namespace Store.Users.Repositories;
|
||||
|
||||
public interface IUserRepository : IBaseRepository<UserEntity>
|
||||
{
|
||||
/// <summary>获取用户及从主账号继承的有效配置;用户不存在时返回空。</summary>
|
||||
Task<UserEntity?> GetUser(string userName);
|
||||
|
||||
/// <summary>获取用户所属主账号(主账号返回自身);用户不存在时返回空,主账号无效时抛出业务异常。</summary>
|
||||
Task<UserEntity?> GetMainUser(string userName);
|
||||
}
|
||||
|
||||
/// <summary>集中处理旧系统主子账号的有效计费配置和积分权限继承。</summary>
|
||||
internal class UserRepository(IFreeSql freeSql) : BaseRepository<UserEntity>(freeSql), IUserRepository, ITransientDependency
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public async Task<UserEntity?> GetUser(string userName)
|
||||
{
|
||||
var user = await Where(u => u.UserName == userName).FirstAsync();
|
||||
if (user == null || user.IsMainUser) return user;
|
||||
var parent = await Where(u => u.UserName == user.ParentUserName).FirstAsync();
|
||||
if (parent == null) throw new MAX.Framework.Commons.AppException("主账号不存在,请联系管理员");
|
||||
var parent = await GetMainUser(user);
|
||||
user.OemId = parent.OemId;
|
||||
user.PostagePerOrder = Math.Max(2.2m, parent.PostagePerOrder ?? 0);
|
||||
user.RefundPostagePerOrder = Math.Max(2.5m, parent.RefundPostagePerOrder ?? 0);
|
||||
user.GiftOemAmountPerOrder = Math.Max(0, parent.GiftOemAmountPerOrder ?? 0);
|
||||
// 子账号的计费配置完全跟随主账号,包括未配置的费用。
|
||||
user.ShopPointsPerMonth = parent.ShopPointsPerMonth;
|
||||
user.PostagePerOrder = parent.PostagePerOrder;
|
||||
user.RefundPostagePerOrder = parent.RefundPostagePerOrder;
|
||||
user.GiftOemAmountPerOrder = parent.GiftOemAmountPerOrder;
|
||||
user.SyncLogisticsPerOrder = parent.SyncLogisticsPerOrder;
|
||||
var authority = (user.Authority ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToHashSet();
|
||||
var parentAuthority = (parent.Authority ?? "").Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
@@ -28,4 +34,20 @@ internal class UserRepository(IFreeSql freeSql) : BaseRepository<UserEntity>(fre
|
||||
user.Authority = string.Join(",", authority);
|
||||
return user;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public async Task<UserEntity?> GetMainUser(string userName)
|
||||
{
|
||||
var user = await Where(u => u.UserName == userName).FirstAsync();
|
||||
return user == null ? null : await GetMainUser(user);
|
||||
}
|
||||
|
||||
/// <summary>统一校验主子账号关系,禁止从其他子账号继承配置。</summary>
|
||||
private async Task<UserEntity> GetMainUser(UserEntity user)
|
||||
{
|
||||
if (user.IsMainUser) return user;
|
||||
var parent = await Where(u => u.UserName == user.ParentUserName).FirstAsync();
|
||||
if (parent == null || !parent.IsMainUser)
|
||||
throw new MAX.Framework.Commons.AppException("主账号不存在或账号关系无效,请联系管理员");
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,17 @@ internal sealed class UserQueryService(IUserRepository repository) : IUserQueryS
|
||||
var user = await repository.GetUser(userName.Trim()) ?? throw new AppException("用户不存在");
|
||||
return new UserMapper().ToInfo(user);
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取主账号
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<UserInfo> GetMainUser(string userName)
|
||||
{
|
||||
RequestValidator.Validate(new UserNameRequest { UserName = userName?.Trim()! });
|
||||
var user = await repository.GetMainUser(userName.Trim()) ?? throw new AppException("用户不存在");
|
||||
return new UserMapper().ToInfo(user);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class UserAuthenticationService(IFreeSql orm, IUserQueryService query)
|
||||
|
||||
Reference in new issue
Block a user