From 3b991458df80b0fd1deba2d91429aeeab936431a Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Tue, 22 Sep 2020 15:35:46 +0800 Subject: [PATCH] Check whether the inventory has been deducted when creating a payment or completing the order. --- .../EasyAbp/EShop/Orders/Orders/OrderManager.cs | 2 +- .../Payments/BasicPaymentCreationAuthorizationHandler.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs index b368dba0..315aabbf 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs @@ -43,7 +43,7 @@ namespace EasyAbp.EShop.Orders.Orders public virtual async Task CompleteAsync(Order order) { - if (order.CompletionTime.HasValue) + if (order.CompletionTime.HasValue || !order.ReducedInventoryAfterPaymentTime.HasValue) { throw new OrderIsInWrongStageException(order.Id); } diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPaymentCreationAuthorizationHandler.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPaymentCreationAuthorizationHandler.cs index c88ebedd..f6645a8c 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPaymentCreationAuthorizationHandler.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPaymentCreationAuthorizationHandler.cs @@ -14,7 +14,10 @@ namespace EasyAbp.EShop.Payments.Payments protected override Task HandlePaymentCreationAsync(AuthorizationHandlerContext context, PaymentOperationAuthorizationRequirement requirement, PaymentCreationResource resource) { - if (resource.Orders.Any(order => order.PaymentId.HasValue || order.PaidTime.HasValue)) + if (resource.Orders.Any(order => + !order.ReducedInventoryAfterPlacingTime.HasValue || + order.PaymentId.HasValue || + order.PaidTime.HasValue)) { context.Fail(); return Task.CompletedTask;