fix: 移除商户中心商户查询兜底逻辑
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 38s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 38s
This commit is contained in:
@@ -57,7 +57,7 @@ public sealed class GetCurrentMerchantCenterQueryHandler(
|
||||
}
|
||||
|
||||
// 4. 解析当前用户可访问商户
|
||||
var merchantId = await ResolveMerchantIdAsync(currentUser.MerchantId, currentTenantId, cancellationToken);
|
||||
var merchantId = ResolveMerchantId(currentUser.MerchantId);
|
||||
|
||||
// 5. 读取商户主体与租户信息
|
||||
var merchant = await merchantRepository.FindByIdAsync(merchantId, currentTenantId, cancellationToken)
|
||||
@@ -87,29 +87,19 @@ public sealed class GetCurrentMerchantCenterQueryHandler(
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析当前用户对应的商户标识。
|
||||
/// 解析当前用户绑定的商户标识。
|
||||
/// </summary>
|
||||
/// <param name="currentUserMerchantId">当前用户绑定的商户 ID。</param>
|
||||
/// <param name="tenantId">当前租户 ID。</param>
|
||||
/// <param name="cancellationToken">取消标记。</param>
|
||||
/// <returns>商户 ID。</returns>
|
||||
private async Task<long> ResolveMerchantIdAsync(long? currentUserMerchantId, long tenantId, CancellationToken cancellationToken)
|
||||
private static long ResolveMerchantId(long? currentUserMerchantId)
|
||||
{
|
||||
// 1. 优先使用用户显式绑定的商户
|
||||
// 1. 严格使用用户绑定商户
|
||||
if (currentUserMerchantId is > 0)
|
||||
{
|
||||
return currentUserMerchantId.Value;
|
||||
}
|
||||
|
||||
// 2. 兜底读取租户下最新商户
|
||||
var merchants = await merchantRepository.SearchAsync(tenantId, status: null, cancellationToken);
|
||||
var merchantId = merchants.FirstOrDefault()?.Id;
|
||||
if (!merchantId.HasValue || merchantId.Value <= 0)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.NotFound, "当前租户尚未创建商户信息");
|
||||
}
|
||||
|
||||
// 3. 返回商户标识
|
||||
return merchantId.Value;
|
||||
// 2. 未绑定商户直接拒绝访问
|
||||
throw new BusinessException(ErrorCodes.Forbidden, "当前用户未绑定商户,禁止访问商户中心");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user