private void GetAllSaleGift(ref OrderInfo order) { if (order.GiftItemList == null) { order.GiftItemList = new List <OrderGiftItem>(); } //1.基于性能考虑,合并订单中的所有主商品 List <SOItemInfo> soItemList = InternalHelper.ConvertToSOItemList(order, false); List <SaleGiftInfo> saleGiftList = new List <SaleGiftInfo>(); //2.得到订单中所有可能可以使用赠品活动,并进行活动排重(单品,厂商--可以直接用,同时购买和满赠--可能可以用,需要在后面处理)。 foreach (SOItemInfo soItem in soItemList) { List <SaleGiftInfo> productSaleGiftList = PromotionDA.GetSaleGiftListByProductSysNo(soItem.ProductSysNo); if (productSaleGiftList != null && productSaleGiftList.Count > 0) { foreach (SaleGiftInfo saleGift in productSaleGiftList) { if (!saleGiftList.Exists(f => f.SysNo == saleGift.SysNo)) { saleGiftList.Add(saleGift); } } } } //3.遍历所有可能可以使用的赠品活动,再进一步根据order中的每一组商品,结合赠品活动类型进行处理 if (saleGiftList.Count > 0) { foreach (SaleGiftInfo saleGift in saleGiftList) { switch (saleGift.SaleGiftType) { case ECommerce.Enums.SaleGiftType.Single: #region 单品处理 ProcessSingleGift(ref order, saleGift); #endregion break; case ECommerce.Enums.SaleGiftType.Vendor: #region 厂商赠品处理 ProcessSingleGift(ref order, saleGift); #endregion break; } } //同时购买处理 ProcessMultiGift(ref order, saleGiftList); //满赠处理 ProcessFullGift(ref order, saleGiftList); } }
public void Calculate(ref OrderInfo order) { List <SOItemInfo> soItemList = InternalHelper.ConvertToSOItemList(order, false); List <int> soItemSysNoList = soItemList.Select(f => f.ProductSysNo).Distinct().ToList(); List <OrderAttachment> unitAttachmentList = PromotionDA.GetAttachmentListByProductSysNoList(soItemSysNoList); order.AttachmentItemList = new List <OrderAttachment>(); foreach (OrderItemGroup itemGroup in order.OrderItemGroupList) { foreach (OrderProductItem item in itemGroup.ProductItemList) { OrderAttachment unitAttachment = unitAttachmentList.Find(f => f.ParentProductSysNo == item.ProductSysNo); if (unitAttachment != null) { unitAttachment = unitAttachment.Clone() as OrderAttachment; unitAttachment.ParentCount = itemGroup.Quantity * item.UnitQuantity; unitAttachment.ParentPackageNo = itemGroup.PackageNo; order.AttachmentItemList.Add(unitAttachment); } } } }
//处理同时购买 private void ProcessMultiGift(ref OrderInfo order, List <SaleGiftInfo> saleGiftList) { List <SOItemInfo> soItemList = InternalHelper.ConvertToSOItemList(order, false); foreach (SaleGiftInfo saleGift in saleGiftList) { if (saleGift.SaleGiftType != ECommerce.Enums.SaleGiftType.Multiple) { continue; } //先判断订单是否满足这个同时购买的活动 bool isCludeMulti = true; int maxMultiCount = 0; foreach (GiftSaleRule saleruleCheck in saleGift.GiftSaleRuleList) { SOItemInfo soItem = soItemList.Find(f => f.ProductSysNo == saleruleCheck.RelProductSysNo); if (soItem == null) { isCludeMulti = false; break; } int qty = soItem.Quantity / saleruleCheck.RelMinQty; //不满足条件,直接跳出 if (qty <= 0) { isCludeMulti = false; break; } if (maxMultiCount == 0) { maxMultiCount = qty; } if (qty < maxMultiCount) { maxMultiCount = qty; } } //如果满足同时购买 if (isCludeMulti && maxMultiCount > 0) { //先在order中加上赠品 foreach (GiftItem giftItem in saleGift.GiftItemList) { OrderGiftItem orderGiftItem = new OrderGiftItem() { ActivityNo = saleGift.SysNo.Value, ActivityName = saleGift.PromotionName, IsGiftPool = saleGift.IsGiftPool, IsSelect = false, ParentCount = maxMultiCount,//giftItem.UnitQuantity * ParentPackageNo = 0, ParentProductSysNo = 0, ProductID = giftItem.ProductID, ProductName = giftItem.ProductName, DefaultImage = giftItem.DefaultImage, ProductSysNo = giftItem.ProductSysNo, SaleGiftType = saleGift.SaleGiftType, UnitQuantity = saleGift.IsGiftPool ? 1 : giftItem.UnitQuantity, PoolLimitCount = saleGift.IsGiftPool && saleGift.ItemGiftCount.HasValue && saleGift.ItemGiftCount.Value > 0 ? saleGift.ItemGiftCount.Value : 1, UnitSalePrice = giftItem.PlusPrice, UnitCostPrice = giftItem.UnitCost, MerchantSysNo = giftItem.MerchantSysNo, Weight = giftItem.Weight, UnitRewardedPoint = giftItem.UnitRewardedPoint, }; orderGiftItem["Warranty"] = giftItem.Warranty; order.GiftItemList.Add(orderGiftItem); } //移除order中符合当前同时购买的主商品或减数量,这样下一个同时购买的活动就不会重复使用满足上一个同时购买活动的主商品了 foreach (GiftSaleRule saleRule in saleGift.GiftSaleRuleList) { SOItemInfo soItem = soItemList.Find(f => f.ProductSysNo == saleRule.RelProductSysNo); soItem.Quantity = soItem.Quantity - maxMultiCount * saleRule.RelMinQty; if (soItem.Quantity == 0) { soItemList.Remove(soItem); } } } } }
/// <summary> /// 取得满足优惠券条件的商品总金额 /// </summary> /// <param name="order"></param> /// <param name="coupon"></param> /// <returns></returns> private decimal GetCanCalculateAmount(ref OrderInfo order, CouponInfo coupon) { List <SOItemInfo> soItemList = InternalHelper.ConvertToSOItemList(order, false, true); List <int> productSysNoList = new List <int>(); soItemList.ForEach(f => productSysNoList.Add(f.ProductSysNo)); //couponProductList:满足条件的商品列表,使用OrderProductItem这个对象来记录,UnitSalePrice是这个商品的价格,UnitQuantity会作为这个商品的总数量 List <OrderProductItem> couponProductList = new List <OrderProductItem>(); List <SimpleItemEntity> productList = PromotionDA.GetSimpleItemListBySysNumbers(productSysNoList); //主商品 foreach (OrderItemGroup itemGroup in order.OrderItemGroupList) { foreach (OrderProductItem item in itemGroup.ProductItemList) { SimpleItemEntity product = productList.Find(f => f.ProductSysNo == item.ProductSysNo); if (CheckIsCouponProduct(product, coupon)) { OrderProductItem couponProduct = couponProductList.Find(f => f.ProductSysNo == product.ProductSysNo); if (couponProduct == null) { couponProduct = new OrderProductItem(); couponProduct.ProductSysNo = item.ProductSysNo; couponProduct.UnitSalePrice = item.UnitSalePrice; couponProduct.UnitQuantity = item.UnitQuantity * itemGroup.Quantity; couponProductList.Add(couponProduct); } else { couponProduct.UnitQuantity += item.UnitQuantity * itemGroup.Quantity; } } } } //加购商品 if (order.PlusPriceItemList != null) { foreach (OrderGiftItem item in order.PlusPriceItemList) { SimpleItemEntity product = productList.Find(f => f.ProductSysNo == item.ProductSysNo); if (CheckIsCouponProduct(product, coupon)) { OrderProductItem couponProduct = couponProductList.Find(f => f.ProductSysNo == product.ProductSysNo); if (couponProduct == null) { couponProduct = new OrderProductItem(); couponProduct.ProductSysNo = item.ProductSysNo; couponProduct.UnitSalePrice = item.UnitSalePrice; couponProduct.UnitQuantity = item.UnitQuantity; couponProductList.Add(couponProduct); } else { couponProduct.UnitQuantity += item.UnitQuantity; } } } } decimal totalAmount = 0.00m; foreach (OrderProductItem couponProduct in couponProductList) { totalAmount += couponProduct.UnitSalePrice * couponProduct.UnitQuantity; } order.CouponProductList = couponProductList; return(totalAmount); }