chore: update store delivery zone handlers
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user