Ejemplo n.º 1
0
        public virtual async Task <OrderDto> CompleteAsync(CompleteOrderInput input)
        {
            var order = await GetEntityByIdAsync(input.OrderId);

            if (order.CustomerUserId != CurrentUser.GetId())
            {
                await AuthorizationService.CheckAsync(OrdersPermissions.Orders.Manage);

                // Todo: Check if current user is an admin of the store.
            }

            order = await _orderManager.CompleteAsync(order);

            return(MapToGetOutputDto(order));
        }
        /// <summary>
        /// 完成订单
        /// </summary>
        /// <returns></returns>
        public async Task CompleteOrder(CompleteOrderInput input)
        {
            var customer = await _customerRepository.FirstOrDefaultAsync(c => c.Id == input.CustomerId);

            if (customer == null)
            {
                throw new UserFriendlyException("该账户不存在");
            }
            var order = await _ordeRepository.FirstOrDefaultAsync(c => c.OrderNum.Equals(input.OrderNum) && !c.State.HasValue);

            if (order == null)
            {
                throw new UserFriendlyException("该订单不存在");
            }
            order.State = input.State;
            if (input.State)
            {
                if (customer.Balance < order.TotalPrice)
                {
                    throw new UserFriendlyException("账户下余额不足,请充值后再试");
                }
                var cost = new CustomerCost()
                {
                    Balance    = customer.Balance,
                    CustomerId = customer.Id
                };
                customer.Balance   -= order.TotalPrice;
                cost.Cost           = order.TotalPrice;
                cost.CurrentBalance = customer.Balance;

                await _costRepository.InsertAsync(cost);
            }
            else
            {
                order.CancelReason = input.CancelReason;
            }
        }
Ejemplo n.º 3
0
 public Task <OrderDto> CompleteAsync(CompleteOrderInput input)
 {
     return(_service.CompleteAsync(input));
 }