Esempio n. 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);
        }
Esempio n. 2
0
        public async Task <ReservationDTO> AddReservation(ReservationDTO model, string operatorId)
        {
            ReservationDTO result = null;

            var service  = _serviceRepository.Get(model.ServiceId);
            var servicer = _servicerRepository.Get(model.ServicerId);

            if (service == null && servicer == null)
            {
                throw new Exception("异常预约!");
            }

            if (service.ServeScope > 0)
            {
                var res = await _amapProxy.Geo(model?.ServiceDestination?.StreetAddress);

                if (res == null)
                {
                    throw new Exception("地址异常!");
                }

                var sres = await _amapProxy.Geo(service.StreetAddress);

                if (sres != null)
                {
                    var distance = GetDistance(res.Longitude, res.Latitude, sres.Longitude, sres.Latitude);
                    if (distance > service.ServeScope)
                    {
                        throw new Exception("超出范围!");
                    }
                }
            }

            var reservation = ReservationFactory.CreateInstance(
                service,
                servicer,
                model.ServiceDestination,
                model.CustomerName,
                model.CustomerMobile,
                model.AppointTime,
                service.SincerityGold,
                operatorId);

            _reservationRepository.Add(reservation);
            _dbUnitOfWork.Commit();

            #region create order
            var orderItems = new List <OrderItemDTO>();

            orderItems.Add(new OrderItemDTO
            {
                Count              = 1,
                ObjectId           = reservation.Id,
                ObjectNo           = reservation.ReservationNo,
                Title              = reservation.Service?.Title ?? "",
                TradeUnitPrice     = reservation.SincerityGoldNeedToPay,
                SelectedProperties = string.Empty,
                PreviewPictureUrl  = string.Empty
            });

            await _orderServiceProxy.CreateOrder(new Proxies.DTOs.OrderDTO
            {
                CreatedBy          = reservation.CreatedBy,
                CustomerAddress    = reservation.ServiceDestination,
                CustomerMobile     = reservation.CustomerMobile,
                CustomerName       = reservation.CustomerName,
                InvoiceType        = InvoiceType.None,
                PayAmount          = orderItems.Sum(o => o.TradeUnitPrice *o.Count),
                PreferentialAmount = 0,
                ShippingCost       = 0,
                Tax            = 0,
                TotalAmount    = reservation.SincerityGoldNeedToPay,
                OrderItems     = orderItems,
                Mark           = "Reservation",
                Invoiceremark  = "",
                Remark         = $"预约时间:{reservation?.AppointTime},预约服务:{reservation?.Service?.Title},服务者:{reservation?.Servicer?.Name ?? "未指定"}",
                OrganizationId = reservation.OrganizationId
            });

            #endregion

            reservation.ConfirmAppoint();
            _eventBus.Commit();

            return(new ReservationDTO
            {
                AppointTime = reservation.AppointTime,
                CustomerMobile = reservation.CustomerMobile,
                CustomerName = reservation.CustomerName,
                Id = reservation.Id,
                ReservationNo = reservation.ReservationNo,
                ServiceDestination = reservation.ServiceDestination,
                ServiceId = reservation.ServiceId,
                ServicerId = reservation.ServicerId,
                SincerityGoldNeedToPay = reservation.SincerityGoldNeedToPay,
                Status = reservation.Status,
                OrganizationId = reservation.OrganizationId,
                OrderId = reservation.OrderId
            });
        }