public async Task <Result> PostByProduct([FromBody] OrderCreateByProductParam model) { var user = await _workContext.GetCurrentUserAsync(); var param = new OrderCreateBaseParam() { CustomerId = user.Id, DiscountAmount = 0, OrderNote = model.OrderNote, ShippingUserAddressId = model.ShippingUserAddressId, PaymentType = PaymentType.OnlinePayment, ShippingMethod = ShippingMethod.Free, ShippingFeeAmount = 0, }; param.Items.Add(new OrderCreateBaseItemParam() { ProductId = model.ProductId, Quantity = model.Quantity }); var order = await _orderService.OrderCreate(user.Id, param); var result = new OrderCreateResult() { OrderId = order.Id, OrderNo = order.No.ToString(), OrderTotal = order.OrderTotal }; return(Result.Ok(result)); }
public async Task <HttpMessage <OrderCreateResult> > OrderCreate(QueryWithSettings qs) => await TryCatchResponseAsync(async() => { return(await Task.Run(() => { //string result = "Ok"; Principal principal = Core.Http.HttpContext.Current.User as Principal; int userId = principal == null || principal.User == null ? 0 : principal.User.Id; OrderCreateResult result = OrderCreateSql(userId, qs); if (result.OrderHeaderID > 0 && result.OrderNumber > 0) { ClearBasket(qs); } return CreateResponseOk(result); })); });
public async Task <Result> PostByOrder([FromBody] OrderCreateByOrderParam model) { var user = await _workContext.GetCurrentUserAsync(); var oldOrder = await _orderRepository.Query() .Include(c => c.OrderItems) .FirstOrDefaultAsync(c => c.Id == model.OrderId && c.CustomerId == user.Id); if (oldOrder == null) { throw new Exception("订单不存在"); } var param = new OrderCreateBaseParam() { CustomerId = user.Id, DiscountAmount = 0, OrderNote = model.OrderNote, ShippingUserAddressId = model.ShippingUserAddressId, PaymentType = PaymentType.OnlinePayment, ShippingMethod = ShippingMethod.Free, ShippingFeeAmount = 0, }; param.Items = oldOrder.OrderItems.Select(c => new OrderCreateBaseItemParam() { ProductId = c.ProductId, Quantity = c.Quantity }).ToList(); var order = await _orderService.OrderCreate(user.Id, param); var result = new OrderCreateResult() { OrderId = order.Id, OrderNo = order.No.ToString(), OrderTotal = order.OrderTotal }; return(Result.Ok(result)); }