From dfa2b3ee521033a8b113c3f677c59834b8054b17 Mon Sep 17 00:00:00 2001 From: MSuMshk <2039814060@qq.com> Date: Wed, 18 Feb 2026 10:03:27 +0800 Subject: [PATCH] feat(store): add quick business toggle endpoint and auto-approve creation --- .../Controllers/StoreController.cs | 21 +++++++++++ .../Handlers/CreateStoreCommandHandler.cs | 35 +++++++++++++++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/Api/TakeoutSaaS.TenantApi/Controllers/StoreController.cs b/src/Api/TakeoutSaaS.TenantApi/Controllers/StoreController.cs index 976fb52..480186d 100644 --- a/src/Api/TakeoutSaaS.TenantApi/Controllers/StoreController.cs +++ b/src/Api/TakeoutSaaS.TenantApi/Controllers/StoreController.cs @@ -108,5 +108,26 @@ public sealed class StoreController(IMediator mediator) : BaseApiController // 2. 返回成功响应 return ApiResponse.Ok(null); } + + /// + /// 快速切换门店经营状态。 + /// + /// 切换命令。 + /// 取消标记。 + /// 切换后的门店信息。 + [HttpPost("toggle-business-status")] + [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status422UnprocessableEntity)] + public async Task> ToggleBusinessStatus( + [FromBody] ToggleBusinessStatusCommand command, + CancellationToken cancellationToken) + { + // 1. 执行状态切换 + var result = await mediator.Send(command, cancellationToken); + + // 2. 返回切换结果 + return ApiResponse.Ok(result); + } } diff --git a/src/Application/TakeoutSaaS.Application/App/Stores/Handlers/CreateStoreCommandHandler.cs b/src/Application/TakeoutSaaS.Application/App/Stores/Handlers/CreateStoreCommandHandler.cs index 8afeb33..e5d7ebd 100644 --- a/src/Application/TakeoutSaaS.Application/App/Stores/Handlers/CreateStoreCommandHandler.cs +++ b/src/Application/TakeoutSaaS.Application/App/Stores/Handlers/CreateStoreCommandHandler.cs @@ -8,6 +8,7 @@ using TakeoutSaaS.Domain.Stores.Enums; using TakeoutSaaS.Domain.Stores.Repositories; using TakeoutSaaS.Shared.Abstractions.Constants; using TakeoutSaaS.Shared.Abstractions.Exceptions; +using TakeoutSaaS.Shared.Abstractions.Security; namespace TakeoutSaaS.Application.App.Stores.Handlers; @@ -16,7 +17,8 @@ namespace TakeoutSaaS.Application.App.Stores.Handlers; /// public sealed class CreateStoreCommandHandler( StoreContextService storeContextService, - IStoreRepository storeRepository) + IStoreRepository storeRepository, + ICurrentUserAccessor currentUserAccessor) : IRequestHandler { /// @@ -24,6 +26,7 @@ public sealed class CreateStoreCommandHandler( { // 1. 解析上下文 var context = storeContextService.GetRequiredContext(); + var now = DateTime.UtcNow; // 2. 生成唯一门店编码 var existingStores = await storeRepository.SearchAsync( @@ -54,15 +57,29 @@ public sealed class CreateStoreCommandHandler( CoverImageUrl = request.CoverImage?.Trim(), SignboardImageUrl = request.CoverImage?.Trim(), OwnershipType = StoreOwnershipType.SameEntity, - AuditStatus = StoreAuditStatus.Draft, + AuditStatus = StoreAuditStatus.Activated, BusinessStatus = StoreBusinessStatus.Resting, + SubmittedAt = now, + ActivatedAt = now, Status = StoreStatus.Operating }; StoreListMapping.ApplyServiceTypes(store, serviceTypes); - // 4. 持久化 + // 4. 持久化门店并记录自动审核通过 await storeRepository.AddStoreAsync(store, cancellationToken); await storeRepository.SaveChangesAsync(cancellationToken); + + await storeRepository.AddAuditRecordAsync(new StoreAuditRecord + { + StoreId = store.Id, + Action = StoreAuditAction.Approve, + PreviousStatus = StoreAuditStatus.Draft, + NewStatus = StoreAuditStatus.Activated, + OperatorId = ResolveOperatorId(currentUserAccessor), + OperatorName = ResolveOperatorName(currentUserAccessor), + Remarks = "系统自动审核通过" + }, cancellationToken); + await storeRepository.SaveChangesAsync(cancellationToken); } /// @@ -87,4 +104,16 @@ public sealed class CreateStoreCommandHandler( throw new BusinessException(ErrorCodes.Conflict, "门店编码生成失败,请稍后重试"); } + + private static long? ResolveOperatorId(ICurrentUserAccessor currentUserAccessor) + { + var id = currentUserAccessor.UserId; + return id == 0 ? null : id; + } + + private static string ResolveOperatorName(ICurrentUserAccessor currentUserAccessor) + { + var id = currentUserAccessor.UserId; + return id == 0 ? "system" : $"user:{id}"; + } }