private async Task <ShipmentItemDto> PrepareShipmentItemDto(ShipmentItem item) { var orderItem = await _orderManager.GetOrderItemByIdAsync(item.OrderItemId); var shipmentDto = ObjectMapper.Map <ShipmentItemDto>(item); shipmentDto.ProductName = orderItem.ProductName; shipmentDto.AttributeInfo = orderItem.AttributeDescription; return(shipmentDto); }
/// <summary> /// 创建更新物流条目 /// </summary> /// <param name="input"></param> /// <param name="shipment"></param> private void CreateOrUpdateOrderItem(CreateOrUpdateShipmentInput input, Shipment shipment) { if (input.Id == 0) { shipment.Items = new Collection <ShipmentItem>(); } else { var existItemIds = input.Items.Select(i => i.Id).ToList(); var itemsId2Remove = shipment.Items.Where(i => !existItemIds.Contains(i.Id)).ToList(); //删除不存在的属性 foreach (var item in itemsId2Remove) { item.IsDeleted = true; shipment.Items.Remove(item); } } foreach (var itemDto in input.Items) { ShipmentItem item = null; if (itemDto.Id != 0) { item = shipment.Items.FirstOrDefault(i => i.Id == item.Id); } if (item != null) { ObjectMapper.Map(itemDto, item); } else { item = ObjectMapper.Map <ShipmentItem>(itemDto); shipment.Items.Add(item); } } }
/// <summary> /// 删除租户物流 /// </summary> /// <param name="item"></param> public virtual async Task DeleteShipmentItemAsync(ShipmentItem item) { await ShipmentItemRepository.DeleteAsync(item); }
public async Task QuickDelivery(QuickDeliveryInput input) { var order = await _orderManager.GetByIdAsync(input.OrderId); if (order == null) { throw new UserFriendlyException("无效的订单"); } await _orderManager.OrderRepository.EnsureCollectionLoadedAsync(order, o => o.Items); await _orderManager.OrderRepository.EnsureCollectionLoadedAsync(order, o => o.Shipments); Shipment shipment = null; decimal totalWeight = 0; decimal totalVolume = 0; foreach (var orderItem in order.Items.ToList()) { //是否还有订单项需要发货 var maxQtyToAdd = orderItem.GetTotalNumberOfItemsCanBeAddedToShipment(_shipmentManager); if (maxQtyToAdd <= 0) { continue; } int qtyToAdd = orderItem.Quantity; //默认 //validate quantity if (qtyToAdd <= 0) { continue; } if (qtyToAdd > maxQtyToAdd) { qtyToAdd = maxQtyToAdd; } var orderItemTotalWeight = orderItem.Weight > 0 ? orderItem.Weight * qtyToAdd : 0; totalWeight += orderItemTotalWeight; var orderItemTotalVolume = orderItem.Volume > 0 ? orderItem.Volume * qtyToAdd : 0; totalVolume += orderItemTotalVolume; if (shipment == null) { var logistics = await _logisticsManager.FindTenantLogisticsByIdAsync(input.LogisticsId); shipment = new Shipment() { OrderId = order.Id, OrderNumber = order.OrderNumber, LogisticsName = logistics.Name, LogisticsId = logistics.LogisticsId, LogisticsNumber = input.LogisticsNumber, TotalWeight = orderItemTotalWeight, TotalVolume = orderItemTotalVolume, Status = ShippingStatus.NoTrace, AdminComment = input.AdminComment, Items = new Collection <ShipmentItem>() }; } //create a shipment item var shipmentItem = new ShipmentItem() { OrderItemId = orderItem.Id, Quantity = qtyToAdd, }; shipment.Items.Add(shipmentItem); } //if we have at least one item in the shipment, then save it if (shipment != null && shipment.Items.Count > 0) { shipment.TotalWeight = totalWeight; shipment.TotalVolume = totalVolume; if (shipment.Id == 0) { await _shipmentManager.CreateAsync(shipment); } else { await _shipmentManager.UpdateAsync(shipment); } //修改状态为已发货 await _orderProcessingManager.ShipAsync(shipment, true); } }
/// <summary> /// 添加租户物流 /// </summary> /// <param name="item"></param> public virtual async Task CreateShipmentItemAsync(ShipmentItem item) { await ShipmentItemRepository.InsertAsync(item); }