public async Task <IActionResult> PutOrder(int id, OrderInputDto order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }

            _context.Entry(_mapper.Map <Order>(order)).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }

                throw;
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task CreateOrderAsync(OrderInputDto input)
        {
            if (input.OrderItem.Count == 0)
            {
                throw new UserFriendlyException("请选择商品");
            }

            var carrier = System.Configuration.ConfigurationSettings.AppSettings["Carrier"];
            var ticks   = DateTime.Now.Ticks.ToString();
            var model   = input.MapTo <OrderModel>();

            model.UserID         = Convert.ToInt32(AbpSession.UserId);
            model.TenantID       = AbpSession.TenantId.HasValue ? AbpSession.TenantId.Value : 1;
            model.Carrier        = carrier;
            model.OrderNo        = model.TenantID + ticks.Substring(ticks.Length - 6);
            model.Status         = (int)OrderStatus.Wait;
            model.FreightPoint   = 0;
            model.OrderItemModel = new List <OrderItemModel>();
            foreach (var item in input.OrderItem)
            {
                var Itemmodel = item.MapTo <OrderItemModel>();
                model.OrderItemModel.Add(Itemmodel);
            }
            await _orderAppService.InsertAndGetIdAsync(model);

            //foreach (var item in input.OrderItem)
            //{
            //    var Itemmodel = item.MapTo<OrderItemModel>();
            //    Itemmodel.OrderId = orderId;
            //    await _orderItemAppService.InsertAsync(Itemmodel);
            //}
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 提交订单
        /// </summary>
        /// <returns></returns>
        public async Task <ActionResult> CreateOrder(OrderViewModel orderInfo)
        {
            //做店铺分单处理 就是创建不同的订单dto
            List <OrderInputDto> dtos = new List <OrderInputDto>();

            foreach (OrderShop shop in orderInfo.Shops)
            {
                //获取店铺
                Core.Shop.Models.Shop sp = ShopContract.Shops.SingleOrDefault(s => s.Name == shop.Name);
                if (sp == null)
                {
                    throw new Exception("没有改店铺");
                }
                //订单Dto
                OrderInputDto dto = new OrderInputDto {
                    UserId      = CurrentUser.Id,
                    ShopId      = sp.Id,
                    OrderNumber = DateTime.Now.ToString("yyMMddHHmmss") + new Random().GetRandomNumberString(4),
                    ShopName    = sp.Name,
                    Remark      = shop.Remark,
                    Amount      = shop.Amount,
                    RealAmount  = shop.RealAmount,
                    HPayAmount  = shop.HPayAmount,
                    ExpressFee  = shop.ExpressFee,
                    State       = Core.Order.Models.OrderState.UnPay
                };

                //设置订单的收货信息
                dto.OrderExpress = new OrderExpressInputDto {
                    Name          = orderInfo.OrderExpress.Name,
                    Region        = orderInfo.OrderExpress.Region,
                    DetailAddress = orderInfo.OrderExpress.DetailAddress,
                    Zip           = orderInfo.OrderExpress.Zip,
                    Mobile        = orderInfo.OrderExpress.Mobile
                };

                //遍历商品
                foreach (OrderGoods goods in shop.Items)
                {
                    //订单商品
                    OrderGoodsInputDto orderGoodsInputDto = new OrderGoodsInputDto {
                        Name         = goods.Name,
                        GoodsId      = goods.GoodsId,
                        SkuInfo      = goods.SkuInfo,
                        Pic          = goods.Pic,
                        BuyCount     = goods.BuyCount,
                        Price        = goods.Price,
                        Amount       = goods.Price * goods.BuyCount,
                        ExpressFee   = 0,
                        ServiceState = Core.Order.Models.GoodsServiceState.Normal
                    };
                    dto.OrderGoodses.Add(orderGoodsInputDto);
                }
                dtos.Add(dto);
            }

            OperationResult result = await OrderContract.AddOrders(dtos.ToArray());

            return(Json(result.ToAjaxResult()));
        }
        public async Task <ActionResult <OrderInputDto> > PostOrder(OrderInputDto order)
        {
            _context.Orders.Add(_mapper.Map <Order>(order));
            await _context.SaveChangesAsync();

            await new EmailService().SendMessageAsync(_context.Customers.FirstOrDefault(c => c.Id == order.CustomerId)?.Email, "У вас новая путевка!", "Время путешествий");

            return(CreatedAtAction("GetOrder", new { id = order.Id }, order));
        }
Ejemplo n.º 5
0
        public IActionResult Create([FromBody] OrderInputDto model)
        {
            var buyerId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            _bus.Publish(new OrderCompletedEvent(buyerId)).Wait();
            Task.Delay(3000).Wait();
            _logger.LogInformation("Order Create!");
            return(Ok("Order Created!"));
        }
Ejemplo n.º 6
0
 public bool CreateOrder(OrderInputDto order, IList <Dto.OrderItemsInputDto> orderItems)
 {
     try
     {
         _orderRepository.CreateOrder(order.MapTo <Entitys.Orders>());
         _orderItemsRepository.CreateOrderItems(orderItems.MapTo <IList <Entitys.OrderItems> >());
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 7
0
        public async Task <ActionResult> PutOrder([FromBody] OrderInputDto order)
        {
            var result = await _orderService.AddOrderAsync(order);

            if (!result.Any())
            {
                return(Ok());
            }

            var errors = new ModelStateDictionary();

            foreach (var error in result)
            {
                errors.AddModelError(error.Key, error.Value);
            }
            return(ValidationProblem(errors));
        }
Ejemplo n.º 8
0
        public ResponseOutput CreateNewOrder(OrderInputDto inputDto)
        {
            try
            {
                _logger.LogInformation("进入CreateNewOrder方法");
                if (inputDto == null)
                {
                    return(new ResponseOutput(null, "-1", "传入参数为空", HttpContext.TraceIdentifier));
                }

                if (inputDto.CouponCode == "0")
                {
                    return(new ResponseOutput(null, "-1", "券号不对", HttpContext.TraceIdentifier));
                }
                if (string.IsNullOrWhiteSpace(inputDto.CouponCode) || string.IsNullOrWhiteSpace(inputDto.Contactor) ||
                    string.IsNullOrWhiteSpace(inputDto.MobilePhone) || string.IsNullOrWhiteSpace(inputDto.Province) ||
                    string.IsNullOrWhiteSpace(inputDto.City) || string.IsNullOrWhiteSpace(inputDto.District) ||
                    string.IsNullOrWhiteSpace(inputDto.Address))
                {
                    return(new ResponseOutput(null, "-1", "必填字段缺失", HttpContext.TraceIdentifier));
                }

                var coupon = _couponService.GetCouponByCode(inputDto.CouponCode);
                if (coupon == null)
                {
                    return(new ResponseOutput(null, "-1", "券不存在", HttpContext.TraceIdentifier));
                }
                //判断券的次数,不够的话就不能下订单
                if (coupon.AvaliableCount <= 0)
                {
                    return(new ResponseOutput(null, "-1", "此券次数已用完,不能下单", HttpContext.TraceIdentifier));
                }


                List <OrderDetail> details = new List <OrderDetail>();

                if (inputDto.DetailDtos == null && inputDto.DetailDtos.Count == 0)
                {
                    return(new ResponseOutput(null, "-1", "商品明细为空", HttpContext.TraceIdentifier));
                }

                foreach (var item in inputDto.DetailDtos)
                {
                    ProductInformation productInfo = _productService.GetProductById(item.ProductId);
                    if (productInfo == null)
                    {
                        return(new ResponseOutput(null, "-1", "商品明细为空", HttpContext.TraceIdentifier));
                    }
                    details.Add(new OrderDetail
                    {
                        ProductId    = item.ProductId,
                        ProductCode  = productInfo.ProductCode,
                        ProductName  = productInfo.ProductName,
                        ProductCount = item.Count,
                    });
                }

                long     currentTicks  = DateTime.Now.Ticks;
                DateTime dtFrom        = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                long     currentMillis = (currentTicks - dtFrom.Ticks) / 10000;
                Order    order         = new Order
                {
                    OrderCode   = currentMillis.ToString(),//订单号用随机数
                    CreateTime  = DateTime.Now,
                    CouponCode  = inputDto.CouponCode,
                    Contactor   = inputDto.Contactor,
                    MobilePhone = inputDto.MobilePhone,
                    Province    = inputDto.Province,
                    City        = inputDto.City,
                    District    = inputDto.District,
                    Address     = inputDto.Address,
                    ZipCode     = int.Parse(inputDto.ZipCode ?? "0"),
                    Telephone   = inputDto.Telephone ?? string.Empty,
                    Details     = details
                };

                #region 事务处理

                var ret = _transactionService.CreateNewOrderTransaction(order, coupon);

                #endregion

                //发送手机短信给用户,用消息队列或者单独开个进程试一下
                _mqProducer.SendMessage(inputDto.MobilePhone);

                if (ret)
                {
                    return(new ResponseOutput(null, "0", "创建订单成功", HttpContext.TraceIdentifier));
                }

                return(new ResponseOutput(null, "-1", "创建订单失败", HttpContext.TraceIdentifier));
            }
            catch (Exception ex)
            {
                _logger.LogError($"异常为{ex.ToString()}");
                return(new ResponseOutput(null, "-1", ex.Message, HttpContext.TraceIdentifier));
            }
        }