public bool IsMatched(OrderInfo preOrderInfo, FreeShippingItemConfig rule) { return((preOrderInfo.TotalProductAmount + preOrderInfo.TaxAmount - preOrderInfo.TotalDiscountAmount - preOrderInfo.CouponAmount) >= decimal.Parse(rule.AmountSettingValue)); }
internal static OrderAmtMatchedContext GetContext(FreeShippingItemConfig rule) { switch (rule.AmountSettingType.Trim()) { case "1": return(ProductAmtMatchedContext); case "2": return(ProductReduceDisAmtMatchedContext); case "3": return(ProductAddTariffAmtMatchedContext); case "4": return(ProductAddTariffReduceDisAmtMatchedContext); case "5": return(ShippingAmtMatchedContext); default: throw new ArgumentException(string.Format("无效的免运费规则类型:【{0}】", rule.AmountSettingType)); } }
public bool IsMatched(OrderInfo preOrderInfo, FreeShippingItemConfig rule) { return(preOrderInfo.ShippingAmount >= decimal.Parse(rule.AmountSettingValue)); }
public bool IsMatched(OrderInfo preOrderInfo, FreeShippingItemConfig rule) { return(_strategy.IsMatched(preOrderInfo, rule)); }
private void CalcShippingAmount(KeyValuePair <string, OrderInfo> preSubOrderKVS, FreeShippingItemConfig matchedRule) { OrderInfo preSubOrderInfo = preSubOrderKVS.Value; OrderInfo clonedPreSubOrderInfo = (OrderInfo)preSubOrderInfo.Clone(); //主商品免运费数量 int ProductFreeNumber = 0; //全网模式,免本单运费 if (matchedRule.IsGlobal) { preSubOrderInfo.ShippingAmount = 0m; } else { //非全网模式,排除免运费的商品,计算剩下商品的运费 if (matchedRule.ProductSettingValue != null && matchedRule.ProductSettingValue.Count > 0) { #region 排除免运费的商品 if (clonedPreSubOrderInfo.OrderItemGroupList != null) { foreach (var itemGroup in clonedPreSubOrderInfo.OrderItemGroupList) { if (itemGroup.ProductItemList != null) { for (int i = itemGroup.ProductItemList.Count - 1; i >= 0; i--) { if (matchedRule.ProductSettingValue.Exists(productSysNo => itemGroup.ProductItemList[i].ProductSysNo == productSysNo)) { itemGroup.ProductItemList.RemoveAt(i); ProductFreeNumber++; } } } } } if (clonedPreSubOrderInfo.GiftItemList != null) { for (int i = clonedPreSubOrderInfo.GiftItemList.Count - 1; i >= 0; i--) { if (matchedRule.ProductSettingValue.Exists(productSysNo => clonedPreSubOrderInfo.GiftItemList[i].ProductSysNo == productSysNo)) { clonedPreSubOrderInfo.GiftItemList.RemoveAt(i); } } } if (clonedPreSubOrderInfo.AttachmentItemList != null) { for (int i = clonedPreSubOrderInfo.AttachmentItemList.Count - 1; i >= 0; i--) { if (matchedRule.ProductSettingValue.Exists(productSysNo => clonedPreSubOrderInfo.AttachmentItemList[i].ProductSysNo == productSysNo)) { clonedPreSubOrderInfo.AttachmentItemList.RemoveAt(i); } } } #endregion //排除免运费商品后,子单中还剩下部分商品,计算这部分商品的运费作为本单运费 //fixbug: 在没有收货地址的情况下,如果订单满足免运费条件,此时ShippingFeeQueryInfo对象的AreaId=0,计算运费的sp进入某个特定分支后会报错 if (clonedPreSubOrderInfo.TotalItemCount > 0 && preSubOrderInfo.Contact.AddressAreaID > 0) //if (ProductFreeNumber <= 0 && preSubOrderInfo.Contact.AddressAreaID > 0 && clonedPreSubOrderInfo.TotalItemCount > 0) { List <ShippingFeeQueryInfo> qryList = new List <ShippingFeeQueryInfo>(); ShippingFeeQueryInfo qry = new ShippingFeeQueryInfo(); qry.TransID = preSubOrderKVS.Key; qry.SoAmount = clonedPreSubOrderInfo.TotalProductAmount; qry.SoTotalWeight = clonedPreSubOrderInfo.TotalWeight; qry.SOSingleMaxWeight = clonedPreSubOrderInfo.MaxWeight; qry.AreaId = preSubOrderInfo.Contact.AddressAreaID; qry.CustomerSysNo = preSubOrderInfo.Customer.SysNo; qry.IsUseDiscount = 0; qry.SubShipTypeList = preSubOrderInfo.ShipTypeID.ToString(); qry.SellType = Convert.ToInt32(preSubOrderInfo["SellerType"]); qry.MerchantSysNo = Convert.ToInt32(preSubOrderKVS.Key.Split('|')[0]); qry.ShipTypeId = 0; qryList.Add(qry); List <ShippingInfo> shipFeeList = PipelineDA.GetAllShippingFee(qryList); ShippingInfo curShippingInfo = shipFeeList.Find(x => x.TransID == preSubOrderKVS.Key && x.ShippingTypeID.ToString() == preSubOrderInfo.ShipTypeID); if (curShippingInfo != null) { preSubOrderInfo.ShippingAmount = curShippingInfo.ShippingPrice; //+curShippingInfo.ShippingPackageFee; } } else { //排除免运费商品后,子单中商品数量为0,免本单运费 preSubOrderInfo.ShippingAmount = 0m; } } } preSubOrderInfo["FreeShippingChargeLog"] = string.Format("符合免运费规则:{0}\r\n,原运费为:{1:F2}元,减免后运费为:{2:F2}元", matchedRule.ToXmlString(), clonedPreSubOrderInfo.ShippingAmount, preSubOrderInfo.ShippingAmount); }