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. 解析当前用户可访问商户
|
// 4. 解析当前用户可访问商户
|
||||||
var merchantId = await ResolveMerchantIdAsync(currentUser.MerchantId, currentTenantId, cancellationToken);
|
var merchantId = ResolveMerchantId(currentUser.MerchantId);
|
||||||
|
|
||||||
// 5. 读取商户主体与租户信息
|
// 5. 读取商户主体与租户信息
|
||||||
var merchant = await merchantRepository.FindByIdAsync(merchantId, currentTenantId, cancellationToken)
|
var merchant = await merchantRepository.FindByIdAsync(merchantId, currentTenantId, cancellationToken)
|
||||||
@@ -87,29 +87,19 @@ public sealed class GetCurrentMerchantCenterQueryHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 解析当前用户对应的商户标识。
|
/// 解析当前用户绑定的商户标识。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="currentUserMerchantId">当前用户绑定的商户 ID。</param>
|
/// <param name="currentUserMerchantId">当前用户绑定的商户 ID。</param>
|
||||||
/// <param name="tenantId">当前租户 ID。</param>
|
|
||||||
/// <param name="cancellationToken">取消标记。</param>
|
|
||||||
/// <returns>商户 ID。</returns>
|
/// <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)
|
if (currentUserMerchantId is > 0)
|
||||||
{
|
{
|
||||||
return currentUserMerchantId.Value;
|
return currentUserMerchantId.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 兜底读取租户下最新商户
|
// 2. 未绑定商户直接拒绝访问
|
||||||
var merchants = await merchantRepository.SearchAsync(tenantId, status: null, cancellationToken);
|
throw new BusinessException(ErrorCodes.Forbidden, "当前用户未绑定商户,禁止访问商户中心");
|
||||||
var merchantId = merchants.FirstOrDefault()?.Id;
|
|
||||||
if (!merchantId.HasValue || merchantId.Value <= 0)
|
|
||||||
{
|
|
||||||
throw new BusinessException(ErrorCodes.NotFound, "当前租户尚未创建商户信息");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 返回商户标识
|
|
||||||
return merchantId.Value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user