From 76ba5a47482baa30255e3fc276fbd043694320ab Mon Sep 17 00:00:00 2001 From: MSuMshk <2039814060@qq.com> Date: Fri, 6 Feb 2026 13:59:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E5=95=86=E6=88=B7?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E5=95=86=E6=88=B7=E6=9F=A5=E8=AF=A2=E5=85=9C?= =?UTF-8?q?=E5=BA=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetCurrentMerchantCenterQueryHandler.cs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/Application/TakeoutSaaS.Application/App/Merchants/Handlers/GetCurrentMerchantCenterQueryHandler.cs b/src/Application/TakeoutSaaS.Application/App/Merchants/Handlers/GetCurrentMerchantCenterQueryHandler.cs index af8db2a..c285672 100644 --- a/src/Application/TakeoutSaaS.Application/App/Merchants/Handlers/GetCurrentMerchantCenterQueryHandler.cs +++ b/src/Application/TakeoutSaaS.Application/App/Merchants/Handlers/GetCurrentMerchantCenterQueryHandler.cs @@ -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( } /// - /// 解析当前用户对应的商户标识。 + /// 解析当前用户绑定的商户标识。 /// /// 当前用户绑定的商户 ID。 - /// 当前租户 ID。 - /// 取消标记。 /// 商户 ID。 - private async Task 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, "当前用户未绑定商户,禁止访问商户中心"); } }