chore: update store delivery zone handlers

This commit is contained in:
2026-01-21 11:27:13 +08:00
parent 8bde1a6440
commit 36abd83e83
6 changed files with 60 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Application.App.Stores;
using TakeoutSaaS.Application.App.Stores.Commands;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Domain.Stores.Entities;
@@ -17,6 +19,7 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers;
public sealed class UpdateStoreFeeCommandHandler(
IStoreRepository storeRepository,
ITenantProvider tenantProvider,
IHttpContextAccessor httpContextAccessor,
ILogger<UpdateStoreFeeCommandHandler> logger)
: IRequestHandler<UpdateStoreFeeCommand, StoreFeeDto>
{
@@ -24,12 +27,14 @@ public sealed class UpdateStoreFeeCommandHandler(
public async Task<StoreFeeDto> Handle(UpdateStoreFeeCommand request, CancellationToken cancellationToken)
{
// 1. 校验门店状态
var tenantId = tenantProvider.GetCurrentTenantId();
var ignoreTenantFilter = StoreTenantAccess.ShouldIgnoreTenantFilter(httpContextAccessor);
var tenantId = ignoreTenantFilter ? 0 : tenantProvider.GetCurrentTenantId();
var store = await storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
if (store is null)
{
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
}
var storeTenantId = store.TenantId;
if (store.AuditStatus != StoreAuditStatus.Activated)
{
throw new BusinessException(ErrorCodes.Conflict, "门店未激活,无法配置费用");
@@ -42,7 +47,11 @@ public sealed class UpdateStoreFeeCommandHandler(
// 2. (空行后) 获取或创建费用配置
var fee = await storeRepository.GetStoreFeeAsync(request.StoreId, tenantId, cancellationToken);
var isNew = fee is null;
fee ??= new StoreFee { StoreId = request.StoreId };
fee ??= new StoreFee
{
StoreId = request.StoreId,
TenantId = storeTenantId
};
// 3. (空行后) 应用更新字段
fee.MinimumOrderAmount = request.MinimumOrderAmount;