예제 #1
0
        /// <summary>
        /// 取得满足优惠券条件的商品总金额
        /// </summary>
        /// <param name="orderList"></param>
        /// <param name="coupon"></param>
        /// <returns></returns>
        private decimal GetCanCalculateAmount(List <OrderInfo> orderList, CouponInfo coupon)
        {
            List <int> productSysNoList = new List <int>();

            foreach (var order in orderList)
            {
                foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
                {
                    foreach (OrderProductItem item in itemGroup.ProductItemList)
                    {
                        productSysNoList.Add(item.ProductSysNo);
                    }
                }
            }
            List <SimpleItemEntity> productList = PromotionDA.GetSimpleItemListBySysNumbers(productSysNoList);
            //couponProductList:满足条件的商品列表,使用OrderProductItem这个对象来记录,UnitSalePrice是这个商品的价格,UnitQuantity会作为这个商品的总数量
            List <OrderProductItem> couponProductList = new List <OrderProductItem>();

            foreach (var order in orderList)
            {
                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;
                            }
                        }
                    }
                }
            }

            decimal totalAmount = 0.00m;

            foreach (OrderProductItem couponProduct in couponProductList)
            {
                totalAmount += couponProduct.UnitSalePrice * couponProduct.UnitQuantity;
            }

            return(totalAmount);
        }
예제 #2
0
        /// <summary>
        /// 判断商品是否满足优惠券条件,true=满足条件
        /// </summary>
        /// <param name="product"></param>
        /// <param name="coupon"></param>
        /// <returns></returns>
        private bool CheckIsCouponProduct(SimpleItemEntity product, CouponInfo coupon)
        {
            //无商品限制
            if (coupon.RulesType.Trim().ToUpper() == "A")
            {
                return(true);
            }

            //限定类别、品牌、商家
            if (coupon.RulesType.Trim().ToUpper() == "X")
            {
                //采用排除法:如果设置了某项条件,但是商品不满足该项条件,那么返回false;
                //如果没有设置某项条件,那么我们认为这项条件是不做任何限制的;
                //逐一Check,如果所有检查项都没有被排除,那么返回true
                List <Coupon_SaleRules> sellerList = coupon.SaleRulesList.FindAll(f => f.SaleRuleType == CouponSaleRuleType.RelSeller);
                if (sellerList != null && sellerList.Count > 0 && !sellerList.Exists(f => f.SellerSysNo == product.MerchantSysNo))
                {
                    return(false);
                }

                List <Coupon_SaleRules> categoryList = coupon.SaleRulesList.FindAll(f => f.SaleRuleType == CouponSaleRuleType.RelCategory);
                if (categoryList != null && categoryList.Count > 0)
                {
                    if (categoryList[0].RelationType.Trim().ToUpper() == "Y")
                    {
                        if (!categoryList.Exists(f => f.C3SysNo == product.C3SysNo))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (categoryList.Exists(f => f.C3SysNo == product.C3SysNo))
                        {
                            return(false);
                        }
                    }
                }

                List <Coupon_SaleRules> brandList = coupon.SaleRulesList.FindAll(f => f.SaleRuleType == CouponSaleRuleType.RelBrand);
                if (brandList != null && brandList.Count > 0)
                {
                    if (brandList[0].RelationType.Trim().ToUpper() == "Y")
                    {
                        if (!brandList.Exists(f => f.BrandSysNo == product.BrandSysNo))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (brandList.Exists(f => f.BrandSysNo == product.BrandSysNo))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }

            //限定商品
            if (coupon.RulesType.Trim().ToUpper() == "I")
            {
                if (coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelProduct &&
                                                f.ProductSysNo == product.ProductSysNo))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <summary>
        /// 获取商品所有参与的赠品活动, For 商品详细页
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <returns></returns>
        public static List <SaleGiftInfo> GetSaleGiftListByProductSysNo(int productSysNo)
        {
            List <SaleGiftInfo> listResult = new List <SaleGiftInfo>();

            #region 获取指定商品的当前赠品活动:单品,同时购买,厂商赠品
            DataCommand cmd = DataCommandManager.GetDataCommand("Promotion_GetSaleGiftByProductSysNo_AssignProduct");
            cmd.SetParameterValue("@ProductSysNo", productSysNo);
            DataSet ds1 = cmd.ExecuteDataSet();
            if (ds1 != null && ds1.Tables[0] != null && ds1.Tables[0].Rows.Count > 0)
            {
                List <SaleGiftInfo> list1 = DataMapper.GetEntityList <SaleGiftInfo, List <SaleGiftInfo> >(ds1.Tables[0].Rows, (row, entity) =>
                {
                    switch (row["SaleGiftTypeChar"].ToString().Trim().ToUpper())
                    {
                    case "S":
                        entity.SaleGiftType = ECommerce.Enums.SaleGiftType.Single;
                        break;

                    case "M":
                        entity.SaleGiftType = ECommerce.Enums.SaleGiftType.Multiple;
                        break;

                    case "V":
                        entity.SaleGiftType = ECommerce.Enums.SaleGiftType.Vendor;
                        break;

                    default:
                        entity.SaleGiftType = ECommerce.Enums.SaleGiftType.Single;
                        break;
                    }
                    ;
                    entity.IsGiftPool = row["IsGiftPoolChar"].ToString().Trim().ToUpper() == "O" ? true : false;
                    entity.IsGlobal   = row["IsGlobalChar"].ToString().Trim().ToUpper() == "Y" ? true : false;
                });

                //获取上面所有赠品活动的赠品规则,并一一赋给对应的赠品活动
                List <GiftSaleRule> saleruleList1 = DataMapper.GetEntityList <GiftSaleRule, List <GiftSaleRule> >(ds1.Tables[1].Rows);
                foreach (SaleGiftInfo curSaleRule in list1)
                {
                    List <GiftSaleRule> curSaleRuleList = saleruleList1.FindAll(f => f.PromotionSysNo == curSaleRule.SysNo.Value);
                    curSaleRule.GiftSaleRuleList = curSaleRuleList;
                }

                if (list1 != null)
                {
                    listResult.AddRange(list1);
                }
            }

            #endregion

            #region 获取当前有效的赠品活动: 满赠,然后看哪些满足当前商品
            cmd = DataCommandManager.GetDataCommand("Promotion_GetSaleGift_ProductRange");
            cmd.SetParameterValue("@ProductSysNo", productSysNo);
            DataSet ds = cmd.ExecuteDataSet();
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                List <SaleGiftInfo> listRange = DataMapper.GetEntityList <SaleGiftInfo, List <SaleGiftInfo> >(ds.Tables[0].Rows, (row, entity) =>
                {
                    entity.SaleGiftType = ECommerce.Enums.SaleGiftType.Full;
                    entity.IsGiftPool   = row["IsGiftPoolChar"].ToString().Trim().ToUpper() == "O" ? true : false;
                    entity.IsGlobal     = row["IsGlobalChar"].ToString().Trim().ToUpper() == "Y" ? true : false;
                });

                List <GiftSaleRule> saleruleList = DataMapper.GetEntityList <GiftSaleRule, List <GiftSaleRule> >(ds.Tables[1].Rows);

                SimpleItemEntity item = GetSimpleItemBySysNo(productSysNo);
                //根据设置的条件规则来判定:全网模式,只要不在排除范围内,则参加活动;
                //非全网模式:首先必须不在排除范围内,然后并且至少有一项属性在包含范围内,则参加活动
                foreach (SaleGiftInfo saleGift in listRange)
                {
                    if (saleGift.IsGlobal)  //全场范围
                    {
                        List <GiftSaleRule> curSaleRuleList = saleruleList.FindAll(f => f.PromotionSysNo == saleGift.SysNo.Value);
                        saleGift.GiftSaleRuleList = curSaleRuleList;

                        if (!curSaleRuleList.Exists(f => f.RelProductSysNo == item.ProductSysNo ||
                                                    f.RelC3SysNo == item.C3SysNo || f.RelBrandSysNo == item.BrandSysNo))
                        {
                            if (saleGift.VendorSysNo.Value == 1)
                            {
                                listResult.Add(saleGift);
                            }
                            else if (saleGift.VendorSysNo.Value == item.MerchantSysNo)
                            {
                                listResult.Add(saleGift);
                            }
                        }
                    }
                    else
                    {
                        bool include = false;
                        List <GiftSaleRule> curSaleRuleList = saleruleList.FindAll(f => f.PromotionSysNo == saleGift.SysNo.Value);
                        saleGift.GiftSaleRuleList = curSaleRuleList;

                        if (curSaleRuleList != null && curSaleRuleList.Count > 0)
                        {
                            foreach (GiftSaleRule curSaleRule in curSaleRuleList)
                            {
                                if (curSaleRule.ComboType.Trim().ToUpper() == "O" &&
                                    (curSaleRule.RelProductSysNo == item.ProductSysNo ||
                                     curSaleRule.RelC3SysNo == item.C3SysNo ||
                                     curSaleRule.RelBrandSysNo == item.BrandSysNo))
                                {
                                    include = true;
                                    continue;
                                }

                                if (curSaleRule.ComboType.Trim().ToUpper() == "N" &&
                                    (curSaleRule.RelProductSysNo == item.ProductSysNo ||
                                     curSaleRule.RelC3SysNo == item.C3SysNo ||
                                     curSaleRule.RelBrandSysNo == item.BrandSysNo))
                                {
                                    include = false;
                                    break;
                                }
                            }

                            if (include == true)
                            {
                                listResult.Add(saleGift);
                            }
                        }
                    }
                }
            }
            #endregion

            #region 给每个活动填充指定类型的赠品
            if (listResult.Count > 0)
            {
                string strPromotionSysNoes = string.Empty;
                listResult.ForEach(f => strPromotionSysNoes += f.SysNo.Value.ToString() + ",");
                strPromotionSysNoes = strPromotionSysNoes.TrimEnd(",".ToCharArray());
                strPromotionSysNoes = "(" + strPromotionSysNoes + ")";

                CustomDataCommand cucmd = DataCommandManager.CreateCustomDataCommandFromConfig("Promotion_GetSaleGiftItemByPromotionSysNoList");
                cucmd.CommandText = cucmd.CommandText.Replace("#PromotionSysNoes#", strPromotionSysNoes);
                List <GiftItem> allGiftItemList = cucmd.ExecuteEntityList <GiftItem>();

                List <SaleGiftInfo> needRemoveSaleGiftList = new List <SaleGiftInfo>();
                foreach (SaleGiftInfo saleGift in listResult)
                {
                    List <GiftItem> curGiftItemList = allGiftItemList.FindAll(f => f.PromotionSysNo == saleGift.SysNo.Value);
                    if (curGiftItemList != null && curGiftItemList.Count > 0)
                    {
                        curGiftItemList.ForEach(f => f.IsGiftPool = saleGift.IsGiftPool);
                        saleGift.GiftItemList = curGiftItemList;
                    }
                    else
                    {
                        saleGift.GiftItemList = new List <GiftItem>();
                        needRemoveSaleGiftList.Add(saleGift);
                    }
                }
                if (needRemoveSaleGiftList.Count > 0)
                {
                    needRemoveSaleGiftList.ForEach(f => listResult.Remove(f));
                }
            }
            #endregion

            return(listResult);
        }