public ShippingDetails(ShippingMethod method, ShipmentPackage package, decimal cost = 0M, bool isSuccess = false, string reason = "None") { if (method == null || package == null) { Weight = 0M; MethodId = 0; Method = string.Empty; Discount = 0M; Cost = cost; IsSuccess = isSuccess; Reason = reason; } else { ShippingMethodCountry country = method.RestrictedCountries.First(p => p.CountryCode == package.CountryCode); Weight = package.TotalWeight; MethodId = method.ShippingMethodId; Method = method.DisplayName; Discount = method.Discount; Cost = cost; IsSuccess = isSuccess; Reason = reason; ShippingTime = country.ShippingTimeFrom + "~" + country.ShippingTimeTo + " Working days"; } }
/// <summary> /// Gets the shipping details. /// </summary> /// <param name="shipmentPackage">The shipment package.</param> /// <returns></returns> public virtual ShippingDetails GetShippingDetails(ShipmentPackage shipmentPackage) { string strErrorMsg; if (!IsActive(shipmentPackage, out strErrorMsg)) { return(new ShippingDetails(strErrorMsg)); } else { decimal dcmCost = GetFixedRate(shipmentPackage, out strErrorMsg); return(new ShippingDetails(ShippingMethod, shipmentPackage, dcmCost, true)); } }
/// <summary> /// 计算最终的运输费用 /// </summary> /// <param name="shipmentPackage">The shipment package.</param> /// <param name="errorMessage">The error message.</param> /// <remarks>(重量*单价+挂号费)*折扣</remarks> /// <returns></returns> public virtual decimal GetFixedRate(ShipmentPackage shipmentPackage, out string errorMessage) { errorMessage = string.Empty; decimal dcmUnitPrice = _shippingMethod.RestrictedCountries.First(p => p.CountryCode == shipmentPackage.CountryCode).UnitPrice; decimal dcmWeight = shipmentPackage.TotalWeight; decimal dcmFee = ShippingMethod.RegistrationFee; decimal dcmDiscount = ShippingMethod.Discount; if (dcmDiscount == decimal.Zero) { dcmDiscount = 1M; } //以千克计算价钱 return((dcmWeight * dcmUnitPrice + dcmFee) * dcmDiscount); }
/// <summary> /// 包裹是否可以走这种运输方式 /// </summary> /// <param name="shipmentPackage">The shipment package.</param> /// <param name="errorMessage">The error message.</param> /// <returns> /// <c>true</c> if the specified shipment package is active; otherwise, <c>false</c>. /// </returns> public virtual bool IsActive(ShipmentPackage shipmentPackage, out string errorMessage) { errorMessage = string.Empty; return(ShippingMethod.RestrictedCountries.Count(p => p.CountryCode.Equals(shipmentPackage.CountryCode)) > 0); }