Ejemplo n.º 1
0
        protected virtual async Task <Logistics> CreateLogisticsAsync(CreateOrUpdateLogisticsInput input)
        {
            var logistics = await _logisticsManager.FindByNameAsync(input.Name);

            if (logistics != null)
            {
                ObjectMapper.Map(input, logistics);
                await _logisticsManager.UpdateAsync(logistics);
            }
            else
            {
                logistics = ObjectMapper.Map <Logistics>(input);
                await _logisticsManager.CreateAsync(logistics);
            }
            return(logistics);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderImport"></param>
        /// <param name="order"></param>
        private async Task <Shipment> AddShipment(OrderImport orderImport, Order order)
        {
            if (orderImport.LogisticsName.IsNullOrEmpty())
            {
                return(null);
            }

            if (orderImport.TrackingNumber.IsNullOrEmpty())
            {
                return(null);
            }

            order.ShippingStatus = ShippingStatus.Taked;
            var trackingNumber = orderImport.TrackingNumber.Replace("'", "");

            var logistics = await _logisticsManager.FindByNameAsync(orderImport.LogisticsName);

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

            Shipment shipment;

            if (order.Shipments.Any())
            {
                shipment             = order.Shipments.FirstOrDefault();
                shipment.LogisticsId = logistics.Id;
                //shipment.TrackingNumber = trackingNumber;
                shipment.CreationTime = orderImport.CreatedOnUtc;
            }
            else
            {
                shipment = new Shipment()
                {
                    LogisticsId  = logistics.Id,
                    OrderId      = order.Id,
                    CreationTime = orderImport.CreatedOnUtc
                };
            }

            shipment.LogisticsNumber = orderImport.TrackingNumber;

            if (orderImport.OrderStatus == OrderStatus.Completed)
            {
                order.OrderStatus    = OrderStatus.Completed;
                order.ShippingStatus = ShippingStatus.Received;
                shipment.ReceivedOn  = orderImport.DeliveriedOnUtc;
            }

            if (orderImport.OrderStatus == OrderStatus.Canceled)
            {
                order.OrderStatus    = OrderStatus.Canceled;
                order.ShippingStatus = ShippingStatus.IssueWithReject;

                shipment.RejectedOn = orderImport.DeliveriedOnUtc;
            }

            if (shipment.Id == 0)
            {
                foreach (var item in order.Items)
                {
                    shipment.Items.Add(new ShipmentItem()
                    {
                        OrderItemId = item.Id,
                        Quantity    = item.Quantity,
                    });
                }

                order.Shipments.Add(shipment);
            }

            return(shipment);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderImport"></param>
        /// <param name="order"></param>
        public async Task <Shipment> AddShipment(OrderImport orderImport, Order order)
        {
            if (orderImport.LogisticsName.IsNullOrWhiteSpace() && orderImport.LogisticsId == 0)
            {
                return(null);
            }

            if (orderImport.TrackingNumber.IsNullOrWhiteSpace())
            {
                return(null);
            }

            order.ShippingStatus = ShippingStatus.Taked;

            // 获取物流
            var logisticsId   = orderImport.LogisticsId;
            var logisticsName = orderImport.LogisticsName;

            if (logisticsId == 0 || logisticsName.IsNullOrWhiteSpace())
            {
                var logistics = await _logisticsManager.FindByNameAsync(orderImport.LogisticsName);

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

                logisticsId   = logistics.Id;
                logisticsName = logistics.Name;
            }

            // 创建shipment
            Shipment shipment;
            decimal  totalVolume = 0;
            decimal  totalWeight = 0;

            if (order.Shipments != null && order.Shipments.Any())
            {
                shipment = order.Shipments.FirstOrDefault();

                await _shipmentManager.ShipmentRepository.EnsureCollectionLoadedAsync(shipment, s => s.Items);

                shipment.LogisticsId = logisticsId;
                //shipment.TrackingNumber = trackingNumber;
                shipment.CreationTime = orderImport.CreatedOnUtc;
            }
            else
            {
                shipment = new Shipment()
                {
                    LogisticsName = orderImport.LogisticsName,
                    OrderNumber   = order.OrderNumber,
                    Status        = order.ShippingStatus,
                    LogisticsId   = logisticsId,
                    OrderId       = order.Id,
                    CreationTime  = orderImport.CreatedOnUtc,
                    Items         = new Collection <ShipmentItem>(),
                };
            }

            shipment.LogisticsNumber = orderImport.TrackingNumber.Replace("'", "");
            if (orderImport.OrderStatus == OrderStatus.Completed)
            {
                order.OrderStatus    = OrderStatus.Completed;
                order.ShippingStatus = ShippingStatus.Received;
                shipment.ReceivedOn  = orderImport.DeliveriedOnUtc;
            }

            if (orderImport.OrderStatus == OrderStatus.Canceled)
            {
                order.OrderStatus    = OrderStatus.Canceled;
                order.ShippingStatus = ShippingStatus.IssueWithReject;

                shipment.RejectedOn = orderImport.DeliveriedOnUtc;
            }

            // 添加Item 并计算重量
            if (shipment.Id == 0)
            {
                foreach (var item in order.Items.ToList())
                {
                    shipment.Items.Add(new ShipmentItem()
                    {
                        OrderItemId = item.Id,
                        Quantity    = item.Quantity,
                    });

                    totalVolume += item.Volume;
                    totalWeight += item.Weight;
                }

                order.Shipments.Add(shipment);
            }

            shipment.TotalVolume = totalVolume;
            shipment.TotalWeight = totalWeight;

            return(shipment);
        }