Browse Source

Check order status before cancellation

Close #61
pull/96/head
gdlcf88 6 years ago
parent
commit
998bc2206c
  1. 7
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/Order.cs
  2. 12
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs
  3. 2
      samples/EShopSample/aspnet-core/src/EShopSample.DbMigrator/appsettings.json

7
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/Order.cs

@ -125,7 +125,7 @@ namespace EasyAbp.EShop.Orders.Orders
CompletionTime = completionTime;
}
public void Cancel(DateTime canceledTime, [CanBeNull] string cancellationReason)
public void SetCanceled(DateTime canceledTime, [CanBeNull] string cancellationReason)
{
CanceledTime = canceledTime;
CancellationReason = cancellationReason;
@ -154,5 +154,10 @@ namespace EasyAbp.EShop.Orders.Orders
RefundAmount += amount;
}
public bool IsInPayment()
{
return !(!PaymentId.HasValue || PaidTime.HasValue);
}
}
}

12
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderManager.cs

@ -51,7 +51,17 @@ namespace EasyAbp.EShop.Orders.Orders
public virtual async Task<Order> CancelAsync(Order order, string cancellationReason)
{
order.Cancel(_clock.Now, cancellationReason);
if (order.CanceledTime.HasValue)
{
throw new OrderIsInWrongStageException(order.Id);
}
if (order.IsInPayment())
{
throw new OrderIsInWrongStageException(order.Id);
}
order.SetCanceled(_clock.Now, cancellationReason);
order.SetOrderStatus(OrderStatus.Canceled);
return await _orderRepository.UpdateAsync(order, true);

2
samples/EShopSample/aspnet-core/src/EShopSample.DbMigrator/appsettings.json

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"Default": "Server=60.208.32.153;Database=fenghui01test;User Id=fenghui01test;Password=WYSytJdMORYnhTYmvf;Trusted_Connection=True;Integrated Security=false"
"Default": "Server=(LocalDb)\\MSSQLLocalDB;Database=EShopSample;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"IdentityServer": {
"Clients": {

Loading…
Cancel
Save