示例#1
0
        public async Task <ServicerDTO> GetServicer(string id)
        {
            var servicer = _servicerRepository.Get(id);

            if (servicer == null)
            {
                return(null);
            }

            servicer.ResolveAddress();

            var servicerImgs = _servicerImageRepository.GetFiltered(g => g.ServicerId == servicer.Id).ToList();
            var ids          = servicerImgs.Select(i => i.ImageId).ToList();
            var imgs         = await _imageServiceProxy.GetImagesByIds(ids);

            var organization = await _organizationServiceProxy.GetOrganizationById(servicer.OrganizationId);

            var logoImgUrl = "";

            if (organization != null)
            {
                var logoImg = await _imageServiceProxy.GetImageById(organization.LogoImageId);

                logoImgUrl = logoImg?.HttpPath;
            }
            var portrailImageUrl = "";
            var portrailImage    = await _imageServiceProxy.GetImageById(servicer.PortraitImageId);

            if (portrailImage != null)
            {
                portrailImageUrl = portrailImage.HttpPath;
            }

            return(new ServicerDTO
            {
                Category = servicer.Category,
                Id = servicer.Id,
                PersonalIntroduction = servicer.PersonalIntroduction,
                OrganizationId = servicer.OrganizationId,
                Address = servicer.Address,
                BirthDay = servicer.BirthDay,
                Gender = servicer.Gender,
                IsSuspend = servicer.IsSuspend,
                SubCategory = servicer.SubCategory,
                JobNumber = servicer.JobNumber,
                Images = imgs?.Select(img => new ServicerImageDTO {
                    Description = img.Description, HttpPath = img.HttpPath, ImageId = img.Id, ServicerId = servicer.Id, Title = img.Title
                }),
                PortraitImageId = servicer.PortraitImageId,
                PortraitImageUrl = portrailImageUrl,
                Name = servicer.Name,
                SincerityGoldRate = servicer.SincerityGoldRate,
                StartRelevantWorkTime = servicer.StartRelevantWorkTime,
                TechnicalGrade = servicer.TechnicalGrade,
                TechnicalTitle = servicer.TechnicalTitle,
                SincerityGold = servicer.SincerityGold,
                ApplicationId = servicer.ApplicationId,
                UserName = servicer.UserName
            });
        }
示例#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
            });
        }