コード例 #1
0
        public async Task <string> ConfirmBuyGoods(ConfirmBuyGoodsDTO model, string operatorId)
        {
            string orderId = "";

            var user = await _authServiceProxy.GetUser(operatorId);

            if (user == null)
            {
                throw new Exception("Account information exception.");
            }

            var goods = _onlineGoodsRepository.Get(model.GoodsId);

            if (goods == null)
            {
                throw new Exception("Goods information exception.");
            }

            var conditions = _grouponConditionRepository.GetFiltered(o => o.GoodsId == goods.Id).ToList();
            var images     = _onlineGoodsImageRepository.GetFiltered(o => o.GoodsId == goods.Id).ToList();

            var gimg          = images?.FirstOrDefault();
            var previewImgUrl = "";

            if (gimg != null && !string.IsNullOrEmpty(gimg.ImageId))
            {
                var img = await _imageServiceProxy.GetImageById(gimg.ImageId);

                previewImgUrl = img?.HttpPath;
            }

            if (model.Mode == "grouponbuy")
            {
                var activity = await _activityServiceProxy.CreateGrouponActivity(new Proxies.DTOs.GrouponActivityDTO
                {
                    Count              = conditions?.OrderBy(o => o.MoreThanNumber).FirstOrDefault()?.MoreThanNumber ?? 1,
                    CreatedBy          = operatorId,
                    CreatedOn          = DateTime.Now,
                    CreatorName        = user.NickName,
                    CreatorPortraitUrl = user.PortraitUrl,
                    End         = DateTime.Now.AddHours(24),
                    ProductId   = model.GoodsId,
                    ProductMark = "Goods",
                    Start       = DateTime.Now,
                    Status      = Proxies.DTOs.ActivityStatus.InProgress,
                    UnitPrice   = conditions?.OrderBy(o => o.MoreThanNumber).FirstOrDefault()?.Price ?? goods.UnitPrice
                });

                if (activity == null)
                {
                    throw new Exception("create groupon activity failed.");
                }

                var goodsPrice = conditions?.OrderBy(o => o.MoreThanNumber).FirstOrDefault()?.Price ?? goods.UnitPrice;
                var rmk        = "";

                foreach (var item in model.SelectedProperties)
                {
                    rmk += $"  {item.Name}:{item.Value}  ";
                }
                var order = await _orderServiceProxy.CreateOrder(new OrderDTO
                {
                    CreatedBy          = operatorId,
                    CreatedOn          = DateTime.Now,
                    CustomerAddress    = model.CustomerAddress,
                    CustomerMobile     = model.Mobile,
                    CustomerName       = model.CustomerName,
                    Invoiceremark      = "",
                    InvoiceType        = Proxies.DTOs.InvoiceType.None,
                    Mark               = "Goods",
                    OrganizationId     = goods.StoreId,
                    PayAmount          = goodsPrice,
                    PreferentialAmount = 0,
                    Remark             = rmk,
                    ShippingCost       = 0,
                    Tax         = 0,
                    TotalAmount = goodsPrice,
                    UpdatedBy   = operatorId,
                    UpdatedOn   = DateTime.Now,
                    OrderItems  = new List <OrderItemDTO> {
                        new OrderItemDTO {
                            Count              = 1,
                            ObjectId           = goods.Id,
                            ObjectNo           = goods.ItemNumber,
                            PreviewPictureUrl  = previewImgUrl,
                            SelectedProperties = JsonConvert.SerializeObject(model.SelectedProperties),
                            Title              = goods.Title,
                            TradeUnitPrice     = goodsPrice
                        }
                    },
                    ActivityId = activity.Id
                });

                if (order == null)
                {
                    throw new Exception("create order failed.");
                }

                //await _activityServiceProxy.AddGrouponParticipation(new Proxies.DTOs.GrouponParticipationDTO
                //{
                //    BuyCount = 1,
                //    GrouponActivityId = activity.Id,
                //    NickName = user.NickName,
                //    OrderId = order.Id,
                //    UserId = user.Id,
                //    UserPortraitUrl = user.PortraitUrl
                //});

                orderId = order?.Id ?? "";
            }

            if (model.Mode == "attendgroup")
            {
                var activity = await _activityServiceProxy.GetActivityById(model.ActivityId);

                if (activity == null)
                {
                    throw new Exception("活动Id异常.找不到指定的活动信息.");
                }

                var goodsPrice = conditions?.OrderBy(o => o.MoreThanNumber).FirstOrDefault()?.Price ?? goods.UnitPrice;
                var rmk        = "";

                foreach (var item in model.SelectedProperties)
                {
                    rmk += $"  {item.Name}:{item.Value}  ";
                }

                var order = await _orderServiceProxy.CreateOrder(new OrderDTO
                {
                    CreatedBy          = operatorId,
                    CreatedOn          = DateTime.Now,
                    CustomerAddress    = model.CustomerAddress,
                    CustomerMobile     = model.Mobile,
                    CustomerName       = model.CustomerName,
                    Invoiceremark      = "",
                    InvoiceType        = Proxies.DTOs.InvoiceType.None,
                    Mark               = "Goods",
                    OrganizationId     = goods.StoreId,
                    PayAmount          = goodsPrice,
                    PreferentialAmount = 0,
                    Remark             = rmk,
                    ShippingCost       = 0,
                    Tax         = 0,
                    TotalAmount = goodsPrice,
                    UpdatedBy   = operatorId,
                    UpdatedOn   = DateTime.Now,
                    OrderItems  = new List <OrderItemDTO> {
                        new OrderItemDTO {
                            Count              = 1,
                            ObjectId           = goods.Id,
                            ObjectNo           = goods.ItemNumber,
                            PreviewPictureUrl  = previewImgUrl,
                            SelectedProperties = JsonConvert.SerializeObject(model.SelectedProperties),
                            Title              = goods.Title,
                            TradeUnitPrice     = goodsPrice
                        }
                    },
                    ActivityId = activity.Id
                });

                if (order == null)
                {
                    throw new Exception("create order failed.");
                }

                //await _activityServiceProxy.AddGrouponParticipation(new GrouponParticipationDTO
                //{
                //    BuyCount = 1,
                //    GrouponActivityId = model.ActivityId,
                //    NickName = user.NickName,
                //    OrderId = order.Id,
                //    UserId = user.Id,
                //    UserPortraitUrl = user.PortraitUrl
                //});

                orderId = order.Id;
            }

            if (model.Mode == "buy")
            {
                var goodsPrice = goods.UnitPrice;
                var rmk        = "";

                foreach (var item in model.SelectedProperties)
                {
                    rmk += $"  {item.Name}:{item.Value}  ";
                }
                var order = await _orderServiceProxy.CreateOrder(new OrderDTO
                {
                    CreatedBy          = operatorId,
                    CreatedOn          = DateTime.Now,
                    CustomerAddress    = model.CustomerAddress,
                    CustomerMobile     = model.Mobile,
                    CustomerName       = model.CustomerName,
                    Invoiceremark      = "",
                    InvoiceType        = Proxies.DTOs.InvoiceType.None,
                    Mark               = "Goods",
                    OrganizationId     = goods.StoreId,
                    PayAmount          = goodsPrice,
                    PreferentialAmount = 0,
                    Remark             = rmk,
                    ShippingCost       = 0,
                    Tax         = 0,
                    TotalAmount = goodsPrice,
                    UpdatedBy   = operatorId,
                    UpdatedOn   = DateTime.Now,
                    OrderItems  = new List <OrderItemDTO> {
                        new OrderItemDTO {
                            Count              = 1,
                            ObjectId           = goods.Id,
                            ObjectNo           = goods.ItemNumber,
                            PreviewPictureUrl  = previewImgUrl,
                            SelectedProperties = JsonConvert.SerializeObject(model.SelectedProperties),
                            Title              = goods.Title,
                            TradeUnitPrice     = goodsPrice
                        }
                    }
                });

                if (order == null)
                {
                    throw new Exception("create order failed.");
                }

                orderId = order.Id;
            }

            return(orderId);
        }
コード例 #2
0
 public async Task <string> ConfirmBuyGoods([FromBody] ConfirmBuyGoodsDTO model)
 {
     return(await _goodsAppService.ConfirmBuyGoods(model, UserId));
 }