Exemple #1
0
        public async Task <Result> Cancel(int id, [FromBody] OrderCancelParam reason)
        {
            var user = await _workContext.GetCurrentOrThrowAsync();

            var order = await _orderRepository.Query()
                        .FirstOrDefaultAsync(c => c.CustomerId == user.Id && c.Id == id);

            if (order == null)
            {
                return(Result.Fail("订单不存在"));
            }
            else if (order.OrderStatus == OrderStatus.Canceled)
            {
                return(Result.Fail("订单已取消"));
            }
            var orderSs = new OrderStatus[] { OrderStatus.New, OrderStatus.PendingPayment, OrderStatus.PaymentFailed };

            if (!orderSs.Contains(order.OrderStatus))
            {
                return(Result.Fail("当前订单无法取消"));;
            }
            await _orderService.Cancel(id, user.Id, reason?.Reason);

            return(Result.Ok());
        }
Exemple #2
0
        public async Task <Result> Cancel(int id, [FromBody] OrderCancelParam reason)
        {
            var currentUser = await _workContext.GetCurrentUserAsync();

            await _orderService.Cancel(id, currentUser.Id, reason?.Reason);

            return(Result.Ok());
        }