示例#1
0
        public void Calculate(ref OrderInfo order)
        {
            if (order.DiscountDetailList == null)
            {
                order.DiscountDetailList = new List <OrderItemDiscountInfo>();
            }

            foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
            {
                if (itemGroup.PackageNo > 0 && itemGroup.PackageType == 1)
                {
                    ComboInfo combo = PromotionDA.GetComboByComboSysNo(itemGroup.PackageNo);
                    if (combo != null && combo.Items != null && combo.Items.Count > 0)
                    {
                        foreach (ComboItem comboItem in combo.Items)
                        {
                            OrderItemDiscountInfo itemDiscount = new OrderItemDiscountInfo();
                            itemDiscount.DiscountActivityName   = combo.SaleRuleName;
                            itemDiscount.DiscountActivityNo     = itemGroup.PackageNo;
                            itemDiscount.DiscountType           = 1;
                            itemDiscount.PackageNo              = itemGroup.PackageNo;
                            itemDiscount.ProductSysNo           = comboItem.ProductSysNo;
                            itemDiscount.Quantity               = itemGroup.Quantity * comboItem.Quantity;
                            itemDiscount.UnitDiscount           = Math.Abs(comboItem.Discount);
                            itemDiscount.UnitRewardedBalance    = 0;
                            itemDiscount.UnitRewardedPoint      = 0;
                            itemDiscount.UnitShipFeeDiscountAmt = 0;

                            order.DiscountDetailList.Add(itemDiscount);
                        }
                    }
                }
            }
        }
        /// <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);
        }
示例#3
0
        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);
            }
        }
示例#4
0
 public void Calculate(ref OrderInfo order)
 {
     foreach (OrderItemGroup orderItemGroup in order.OrderItemGroupList)
     {
         foreach (OrderProductItem orderItem in orderItemGroup.ProductItemList)
         {
             //团购
             int groupBuySysNo = PromotionDA.ProductIsGroupBuying(orderItem.ProductSysNo);
             if (groupBuySysNo > 0)
             {
                 if (PromotionDA.ProductIsVirualGroupBuying(orderItem.ProductSysNo) > 0)
                 {
                     orderItem.SpecialActivityType  = 3;
                     orderItem.SpecialActivitySysNo = groupBuySysNo;
                 }
                 else
                 {
                     orderItem.SpecialActivityType  = 1;
                     orderItem.SpecialActivitySysNo = groupBuySysNo;
                 }
                 break;
             }
             //限时和秒杀
             CountdownInfo countdown = PromotionDA.GetProductCountdownByProductSysNo(orderItem.ProductSysNo);
             if (countdown != null)
             {
                 orderItem.SpecialActivityType  = 2;
                 orderItem.SpecialActivitySysNo = countdown.SysNo.Value;
                 break;
             }
         }
     }
     if (order.SubOrderList != null)
     {
         foreach (var subOrder in order.SubOrderList)
         {
             if (subOrder.Value.SOType == (int)SOType.VirualGroupBuy)
             {
                 subOrder.Value.ShipTypeID = "101";
             }
         }
     }
 }
示例#5
0
        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);
                    }
                }
            }
        }
        /// <summary>
        /// 检查优惠券是否可用
        /// </summary>
        /// <param name="couponCode"></param>
        /// <param name="customer"></param>
        /// <returns></returns>
        private bool CheckCouponCodeCanUse(string couponCode, CustomerInfo customer)
        {
            #region 1、初次筛选该优惠券号码对于前用户是否能用
            CustomerCouponInfo customerCoupon = PromotionDA.GetCouponSaleRules(customer.SysNo, couponCode);
            if (customerCoupon == null)
            {
                return(false);
            }
            if (customerCoupon.IsExpired)
            {
                return(false);
            }
            if (customerCoupon.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= customerCoupon.CustomerMaxFrequency.Value)
            {
                return(false);
            }

            int totalUsedCount = 0;
            if (customerCoupon.CodeType.Trim().ToUpper() == "C")
            {
                totalUsedCount = PromotionDA.GetCouponCodeTotalUsedCount(couponCode);
            }
            else
            {
                totalUsedCount = PromotionDA.GetCouponTotalUsedCount(customerCoupon.CouponSysNo);
            }
            if (customerCoupon.WebsiteMaxFrequency.HasValue && totalUsedCount >= customerCoupon.WebsiteMaxFrequency)
            {
                return(false);
            }
            #endregion

            #region 2、获取该优惠券号码对应的优惠券活动所有信息
            CouponInfo coupon = PromotionDA.GetComboInfoByCouponCode(couponCode);
            if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= coupon.SaleRulesEx.CustomerMaxFrequency.Value)
            {
                return(false);
            }
            if (coupon.SaleRulesEx.MaxFrequency.HasValue && totalUsedCount >= coupon.SaleRulesEx.MaxFrequency.Value)
            {
                return(false);
            }

            if (coupon == null)
            {
                return(false);
            }
            #endregion

            #region 3、详细检查该优惠券号码是否可用
            if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedEmailVerification) && coupon.SaleRulesEx.NeedEmailVerification.ToUpper().Trim() == "Y")
            {
                if (customer.IsEmailConfirmed != 1)
                {
                    return(false);
                }
            }
            if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedMobileVerification) && coupon.SaleRulesEx.NeedMobileVerification.ToUpper().Trim() == "Y")
            {
                if (customer.IsPhoneValided != 1)
                {
                    return(false);
                }
            }
            if (coupon.SaleRulesList.Count > 0 && coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelCustomerRank))
            {
                //-1表示不限制
                if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == -1))
                {
                    int customerRank = customer.CustomerRank;
                    if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == customerRank))
                    {
                        return(false);
                    }
                }
            }

            #endregion

            return(true);
        }
        public void Calculate(ref OrderInfo order)
        {
            CalculateDiscountAmount(order);

            Dictionary <int, List <OrderInfo> > merchantOrderList = new Dictionary <int, List <OrderInfo> >();

            #region 1、分拆商家订单

            if (order.SubOrderList != null)
            {
                foreach (var subOrder in order.SubOrderList)
                {
                    int merchantSysNo = Convert.ToInt32(subOrder.Key.Split('|')[0]);
                    if (!merchantOrderList.ContainsKey(merchantSysNo))
                    {
                        merchantOrderList[merchantSysNo] = new List <OrderInfo>();
                    }
                    merchantOrderList[merchantSysNo].Add(subOrder.Value);
                }
            }

            #endregion

            #region 2、计算商家优惠券

            List <CustomerCouponInfo> merchantCouponList = PromotionDA.GetMerchantCouponCodeList(order.Customer.SysNo);
            if (merchantCouponList != null)
            {
                foreach (var merchantOrder in merchantOrderList)
                {
                    List <CustomerCouponInfo> currMerchantCouponList = merchantCouponList.FindAll(m => m.MerchantSysNo == merchantOrder.Key);
                    if (currMerchantCouponList == null || currMerchantCouponList.Count == 0)
                    {
                        continue;
                    }
                    foreach (var coupon in currMerchantCouponList)
                    {
                        bool canUse = false;
                        #region 检查商品限制,是否可用
                        List <int> productSysNoList = new List <int>();
                        foreach (var itemOrder in merchantOrder.Value)
                        {
                            foreach (var itemGroup in itemOrder.OrderItemGroupList)
                            {
                                itemGroup.ProductItemList.ForEach(product =>
                                {
                                    productSysNoList.Add(product.ProductSysNo);
                                });
                            }
                        }
                        List <CouponSaleRules> couponSaleRulesList = PromotionDA.GetCouponSaleRulesList(coupon.CouponCode);
                        if (couponSaleRulesList == null || couponSaleRulesList.Count == 0)
                        {
                            //不存在排除或指定商品,全网通用
                            canUse = true;
                        }
                        else
                        {
                            foreach (int productSysNo in productSysNoList)
                            {
                                if (couponSaleRulesList.Exists(m => m.ProductSysNo == productSysNo))
                                {
                                    if (couponSaleRulesList[0].RelationType == "N")
                                    {
                                        //存在排除的商品,不可用
                                        canUse = false;
                                        break;
                                    }
                                    else
                                    {
                                        //存在指定的商品,可用
                                        canUse = true;
                                        break;
                                    }
                                }
                            }
                        }
                        #endregion
                        if (canUse)
                        {
                            if (CheckCouponCodeCanUse(coupon.CouponCode, order.Customer))
                            {
                                foreach (var itemOrder in merchantOrder.Value)
                                {
                                    if (itemOrder.MerchantCouponList == null)
                                    {
                                        itemOrder.MerchantCouponList = new List <CustomerCouponInfo>();
                                    }
                                    itemOrder.MerchantCouponList.Add(coupon);
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            #region 3、商家订单使用优惠券

            foreach (var merchantOrder in merchantOrderList)
            {
                MerchantCoupon merchantCoupon = null;
                if (order.MerchantCouponCodeList != null)
                {
                    merchantCoupon = order.MerchantCouponCodeList.Find(m => m.MerchantSysNo == merchantOrder.Key);
                }
                if (merchantCoupon == null)
                {
                    continue;
                }
                string couponCode = merchantCoupon.CouponCode.ToUpper().Trim();

                #region 1、初次筛选该优惠券号码对于前用户是否能用
                CustomerCouponInfo customerCoupon = PromotionDA.GetCouponSaleRules(order.Customer.SysNo, couponCode);
                if (customerCoupon == null)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("您没有此优惠券{0}", order.LanguageCode), merchantCoupon.CouponName);
                    continue;
                }
                if (customerCoupon.IsExpired)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券{0}已过期", order.LanguageCode), merchantCoupon.CouponName);
                    continue;
                }
                if (customerCoupon.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= customerCoupon.CustomerMaxFrequency.Value)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("您已达到使用优惠券{0}的次数上限", order.LanguageCode), merchantCoupon.CouponName);
                    continue;
                }

                int totalUsedCount = 0;
                if (customerCoupon.CodeType.Trim().ToUpper() == "C")
                {
                    totalUsedCount = PromotionDA.GetCouponCodeTotalUsedCount(couponCode);
                }
                else
                {
                    totalUsedCount = PromotionDA.GetCouponTotalUsedCount(customerCoupon.CouponSysNo);
                }
                if (customerCoupon.WebsiteMaxFrequency.HasValue && totalUsedCount >= customerCoupon.WebsiteMaxFrequency)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券{0}的已达到全网使用次数上限", order.LanguageCode), merchantCoupon.CouponName);
                    continue;
                }
                #endregion

                #region 2、获取该优惠券号码对应的优惠券活动所有信息
                CouponInfo coupon = PromotionDA.GetComboInfoByCouponCode(couponCode);
                if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= coupon.SaleRulesEx.CustomerMaxFrequency.Value)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("您已达到使用此优惠券活动的次数上限", order.LanguageCode));
                    continue;
                }
                if (coupon.SaleRulesEx.MaxFrequency.HasValue && totalUsedCount >= coupon.SaleRulesEx.MaxFrequency.Value)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券活动已达到全网使用次数上限", order.LanguageCode));
                    continue;
                }


                if (coupon == null)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券{0}不存在", order.LanguageCode), merchantCoupon.CouponName);
                    continue;
                }
                #endregion

                #region 3、详细检查该优惠券号码是否可用
                if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedEmailVerification) && coupon.SaleRulesEx.NeedEmailVerification.ToUpper().Trim() == "Y")
                {
                    if (order.Customer.IsEmailConfirmed != 1)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("此优惠券要求客户验证了电子邮箱才可使用!", order.LanguageCode));
                        continue;
                    }
                }
                if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedMobileVerification) && coupon.SaleRulesEx.NeedMobileVerification.ToUpper().Trim() == "Y")
                {
                    if (order.Customer.IsPhoneValided != 1)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("此优惠券要求客户验证了手机才可使用!", order.LanguageCode));
                        continue;
                    }
                }
                if (coupon.SaleRulesList.Count > 0 && coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelCustomerRank))
                {
                    //-1表示不限制
                    if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == -1))
                    {
                        int customerRank = order.Customer.CustomerRank;
                        if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == customerRank))
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("当前客户不满足此优惠券要求的客户等级!", order.LanguageCode));
                            continue;
                        }
                    }
                }
                if (coupon.SaleRulesList.Count > 0 && coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelArea))
                {
                    int  areaID     = order.Contact.AddressAreaID;
                    Area area       = PromotionDA.GetAreaBySysNo(areaID);
                    int  provinceId = area.ProvinceSysNo.Value;

                    if (!coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelArea && f.AreaSysNo == provinceId))
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("当前客户不满足此优惠券要求的客户地区!", order.LanguageCode));
                        continue;
                    }
                }


                #endregion

                #region 4、计算该优惠券可以抵扣多少,填充到OrderInfo中
                if (coupon.DiscountRuleList != null && coupon.DiscountRuleList.Count > 0)
                {
                    //取得满足优惠券条件的商品总金额
                    decimal canCalculateAmount = GetCanCalculateAmount(merchantOrder.Value, coupon);
                    if (canCalculateAmount == 0)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的商品,无法抵扣", order.LanguageCode));
                        continue;
                    }

                    canCalculateAmount = canCalculateAmount - Math.Abs(order.TotalDiscountAmount);

                    if (canCalculateAmount < coupon.SaleRulesEx.OrderAmountLimit)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券要求的商品总金额下限{0},无法抵扣", order.LanguageCode), coupon.SaleRulesEx.OrderAmountLimit);
                        continue;
                    }

                    decimal totalPriceAmount = (merchantOrder.Value.Sum(m => m.TotalProductAmount) - merchantOrder.Value.Sum(m => m.TotalDiscountAmount));

                    #region 处理订单 折扣金额模式 和 百分比模式
                    if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.OrderAmountDiscount || coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.OrderAmountPercentage)
                    {
                        //获取适合的折扣规则
                        Coupon_DiscountRules curDiscountRule = GetMatchDiscountRule(coupon, canCalculateAmount);
                        if (curDiscountRule == null)
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("订单总金额未达到优惠券要求的最小购买金额,无法抵扣", order.LanguageCode));
                            return;
                        }

                        decimal discount = 0m;
                        if (curDiscountRule.DiscountType == CouponDiscountType.OrderAmountDiscount)
                        {
                            discount = Math.Abs(Math.Round(curDiscountRule.Value, 2));
                        }
                        else
                        {
                            discount = Math.Abs(Math.Round(canCalculateAmount * curDiscountRule.Value, 2));
                        }



                        if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                        {
                            if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                            {
                                discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                            }
                        }

                        foreach (var subOrder in merchantOrder.Value)
                        {
                            subOrder.MerchantCouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                            subOrder.MerchantCouponCode      = customerCoupon.CouponCode;
                            subOrder.MerchantCouponSysNo     = customerCoupon.CouponSysNo;
                            subOrder.MerchantCouponName      = customerCoupon.CouponName;
                            subOrder.MerchantCouponAmount    = discount * ((subOrder.TotalProductAmount - subOrder.TotalDiscountAmount) / totalPriceAmount);
                            subOrder.MerchantCouponErrorDesc = string.Empty;
                            foreach (var itemGroup in subOrder.OrderItemGroupList)
                            {
                                foreach (var item in itemGroup.ProductItemList)
                                {
                                    item["UnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m :(decimal)item["UnitDiscountAmt"])))
                                                            / totalPriceAmount;
                                    item["MerchantUnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m : (decimal)item["UnitDiscountAmt"])))
                                                                    / totalPriceAmount;
                                }
                            }
                        }
                    }
                    #endregion

                    #region 处理 一个商品直减模式
                    if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.ProductPriceDiscount)
                    {
                        if (coupon.SaleRulesList == null || coupon.SaleRulesList.Count == 0)
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                            return;
                        }
                        Coupon_SaleRules productSaleRule = coupon.SaleRulesList.Find(f => f.SaleRuleType == CouponSaleRuleType.RelProduct);


                        int discountProductSysNo = productSaleRule.ProductSysNo;

                        int     discountProductCount = 0;
                        decimal productReduce        = 0m;
                        decimal productPrice         = 0.00m;
                        foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
                        {
                            OrderProductItem item = itemGroup.ProductItemList.Find(f => f.ProductSysNo == discountProductSysNo);
                            if (item != null)
                            {
                                discountProductCount += item.UnitQuantity * itemGroup.Quantity;

                                productPrice = item.UnitSalePrice;
                            }
                        }
                        if (discountProductCount == 0)
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                            return;
                        }

                        if (discountProductCount > coupon.DiscountRuleList[0].Quantity)
                        {
                            discountProductCount = coupon.DiscountRuleList[0].Quantity;
                        }

                        productReduce = coupon.DiscountRuleList[0].Value;
                        if (coupon.DiscountRuleList[0].Value > productPrice)
                        {
                            productReduce = productPrice;
                        }

                        decimal discount = Math.Abs(Math.Round(productReduce * discountProductCount, 2));



                        if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                        {
                            if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                            {
                                discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                            }
                        }
                        foreach (var subOrder in merchantOrder.Value)
                        {
                            subOrder.MerchantCouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                            subOrder.MerchantCouponCode      = customerCoupon.CouponCode;
                            subOrder.MerchantCouponSysNo     = customerCoupon.CouponSysNo;
                            subOrder.MerchantCouponName      = customerCoupon.CouponName;
                            subOrder.MerchantCouponAmount    = discount * ((subOrder.TotalProductAmount - subOrder.TotalDiscountAmount) / totalPriceAmount);
                            subOrder.MerchantCouponErrorDesc = string.Empty;

                            subOrder["MerchantCoupon_DiscountProductSysNo"] = discountProductSysNo;
                            subOrder["MerchantCoupon_DiscountProductCount"] = discountProductCount;
                            foreach (var itemGroup in subOrder.OrderItemGroupList)
                            {
                                foreach (var item in itemGroup.ProductItemList)
                                {
                                    item["UnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m : (decimal)item["UnitDiscountAmt"])))
                                                            / totalPriceAmount;
                                    item["MerchantUnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m : (decimal)item["UnitDiscountAmt"])))
                                                                    / totalPriceAmount;
                                }
                            }
                        }
                    }
                    #endregion

                    #region 处理 一个商品最终售价模式
                    if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.ProductPriceFinal)
                    {
                        if (coupon.SaleRulesList == null || coupon.SaleRulesList.Count == 0)
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                            return;
                        }
                        Coupon_SaleRules productSaleRule = coupon.SaleRulesList.Find(f => f.SaleRuleType == CouponSaleRuleType.RelProduct);


                        int discountProductSysNo = productSaleRule.ProductSysNo;

                        decimal discountProductPrice = 0.00m;
                        int     discountProductCount = 0;
                        foreach (var currOrder in merchantOrder.Value)
                        {
                            foreach (OrderItemGroup itemGroup in currOrder.OrderItemGroupList)
                            {
                                OrderProductItem item = itemGroup.ProductItemList.Find(f => f.ProductSysNo == discountProductSysNo);
                                if (item != null)
                                {
                                    discountProductCount += item.UnitQuantity * itemGroup.Quantity;
                                    discountProductPrice  = item.UnitSalePrice;
                                }
                            }
                        }
                        if (discountProductCount == 0)
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                            return;
                        }
                        if (discountProductCount > coupon.DiscountRuleList[0].Quantity)
                        {
                            discountProductCount = coupon.DiscountRuleList[0].Quantity;
                        }

                        decimal discount = 0m;
                        if (discountProductPrice > coupon.DiscountRuleList[0].Value)
                        {
                            discount = Math.Abs(Math.Round((discountProductPrice - coupon.DiscountRuleList[0].Value) * discountProductCount, 2));
                        }
                        else
                        {
                            SetCouponError(ref order, LanguageHelper.GetText("该优惠券的指定商品已经是优惠券设定的最低价格,无法抵扣", order.LanguageCode));
                            return;
                        }
                        if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                        {
                            if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                            {
                                discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                            }
                        }
                        foreach (var subOrder in merchantOrder.Value)
                        {
                            subOrder.MerchantCouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                            subOrder.MerchantCouponCode      = customerCoupon.CouponCode;
                            subOrder.MerchantCouponSysNo     = customerCoupon.CouponSysNo;
                            subOrder.MerchantCouponName      = customerCoupon.CouponName;
                            subOrder.MerchantCouponAmount    = discount * ((subOrder.TotalProductAmount - subOrder.TotalDiscountAmount) / totalPriceAmount);
                            subOrder.MerchantCouponErrorDesc = string.Empty;

                            subOrder["MerchantCoupon_DiscountProductSysNo"] = discountProductSysNo;
                            subOrder["MerchantCoupon_DiscountProductCount"] = discountProductCount;
                            foreach (var itemGroup in subOrder.OrderItemGroupList)
                            {
                                foreach (var item in itemGroup.ProductItemList)
                                {
                                    item["UnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m : (decimal)item["UnitDiscountAmt"])))
                                                            / totalPriceAmount;
                                    item["MerchantUnitCouponAmt"] = (discount * (item.UnitSalePrice - (item["UnitDiscountAmt"] == null ? 0m : (decimal)item["UnitDiscountAmt"])))
                                                                    / totalPriceAmount;
                                }
                            }
                        }
                    }
                    #endregion

                    foreach (var subOrder in merchantOrder.Value)
                    {
                        subOrder["MerchantCoupon_DiscountType"] = coupon.DiscountRuleList[0].DiscountType;
                    }
                }

                #endregion
            }

            #endregion
        }
示例#8
0
        /// <summary>
        /// 获取用户平台优惠券
        /// </summary>
        /// 一张优惠券是否能被用户使用的条件
        /// 1:优惠券为面向所有用户的通用型优惠券
        /// 2: 优惠券为指定当前用户可使用通用型优惠券
        /// 3: 优惠券本身在有效期内
        /// 4:通用型优惠券所属活动在运行期间
        /// 5: 指向当前用户的投放型优惠券
        /// 6: 优惠券使用次数未尽
        /// 7:用户使用该优惠券次数未尽
        /// 8:活动全网次数未尽
        /// 9:用户参与活动次数未尽
        /// John.E.Kang 2015.11.18修改
        /// <param name="customerSysNo">用户ID</param>
        /// <param name="merchantSysNo">平台ID</param>
        /// <returns>用户可用的当前平台优惠券列表</returns>
        public static List <CustomerCouponInfo> GetCustomerPlatformCouponCode(int customerSysNo, int merchantSysNo)
        {
            //用户可用的优惠券列表
            List <CustomerCouponInfo> merchantCouponList = PromotionDA.GetMerchantCouponCodeList(customerSysNo);
            //用户当前平台可用优惠券
            List <CustomerCouponInfo> currMerchantCouponList = merchantCouponList.FindAll(m => m.MerchantSysNo == merchantSysNo || m.MerchantSysNo == 1);

            List <string> needRemoves = new List <string>();

            foreach (CustomerCouponInfo cc in currMerchantCouponList)
            {
                CouponInfo coupon = PromotionDA.GetComboInfoByCouponCode(cc.CouponCode);
                //不属于某一优惠券活动的优惠券吗无效
                if (coupon == null)
                {
                    needRemoves.Add(cc.CouponCode);
                    continue;
                }
                //获取优惠券在全网使用次数
                int totalUsedCount = 0;
                totalUsedCount = PromotionDA.GetCouponCodeTotalUsedCount(cc.CouponCode);

                int CouponTotalUsedCount = 0;
                CouponTotalUsedCount = PromotionDA.GetCouponTotalUsedCount(cc.CouponSysNo);
                //if (cc.CodeType.Trim().ToUpper() == "C")
                //{
                //    totalUsedCount = PromotionDA.GetCouponCodeTotalUsedCount(cc.CouponCode);
                //}
                //else
                //{
                //    totalUsedCount = PromotionDA.GetCouponTotalUsedCount(cc.CouponSysNo);
                //}
                //获取当前用户使用该优惠券的次数
                int customerUsedCount = PromotionDA.GetCustomerTotalUsedCount(cc.CouponCode, customerSysNo);
                //获取当前用户参与活动次数
                int customerJoinCouponCount = PromotionDA.GetCustomerCouponNumber(coupon.SysNo, customerSysNo);

                if (cc.CustomerMaxFrequency.HasValue && customerUsedCount >= cc.CustomerMaxFrequency.Value)
                {
                    needRemoves.Add(cc.CouponCode);
                    continue;
                }
                if (cc.WebsiteMaxFrequency.HasValue && totalUsedCount >= cc.WebsiteMaxFrequency.Value)
                {
                    needRemoves.Add(cc.CouponCode);
                    continue;
                }

                if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && customerJoinCouponCount >= coupon.SaleRulesEx.CustomerMaxFrequency.Value)
                {
                    needRemoves.Add(cc.CouponCode);
                    continue;
                }

                if (coupon.SaleRulesEx.MaxFrequency.HasValue && CouponTotalUsedCount >= coupon.SaleRulesEx.MaxFrequency.Value)
                {
                    needRemoves.Add(cc.CouponCode);
                    continue;
                }

                //过滤掉全网次数已用尽的优惠券活动相关的优惠券
            }

            needRemoves.ForEach(f => currMerchantCouponList.RemoveAll(c => c.CouponCode.Trim().ToUpper() == f.ToUpper().Trim()));

            return(currMerchantCouponList);
        }
示例#9
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);
        }
示例#10
0
        public void Calculate(ref OrderInfo order)
        {
            order.CouponErrorDesc = string.Empty;
            if (string.IsNullOrWhiteSpace(order.CouponCode))
            {
                return;
            }
            string couponCode = order.CouponCode.ToUpper().Trim();

            #region 1、初次筛选该优惠券号码对于前用户是否能用
            List <CustomerCouponInfo> customerCouponList = PromotionDA.GetCanUsingCouponCodeList(order.Customer.SysNo, order.Customer.CustomerRank);
            CustomerCouponInfo        customerCoupon     = customerCouponList.Find(f => f.CouponCode.ToUpper().Trim() == couponCode);
            if (customerCoupon == null)
            {
                SetCouponError(ref order, LanguageHelper.GetText("您没有此优惠券号码{0}", order.LanguageCode), couponCode);
                return;
            }
            if (customerCoupon.IsExpired)
            {
                SetCouponError(ref order, LanguageHelper.GetText("此优惠券号码{0}已过期", order.LanguageCode), couponCode);
                return;
            }
            if (customerCoupon.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= customerCoupon.CustomerMaxFrequency.Value)
            {
                SetCouponError(ref order, LanguageHelper.GetText("您已达到使用优惠券号码{0}的次数上限", order.LanguageCode), couponCode);
                return;
            }

            int totalUsedCount     = 0;
            int CodeTotalUsedCount = 0;
            //用户参与活动的次数
            int CustomerUsedCount = 0;
            //if (customerCoupon.CodeType.Trim().ToUpper() == "C")
            //{
            CodeTotalUsedCount = PromotionDA.GetCouponCodeTotalUsedCount(couponCode);
            //}
            //else
            //{
            //这个是活动的已使用次数
            totalUsedCount    = PromotionDA.GetCouponTotalUsedCount(customerCoupon.CouponSysNo);
            CustomerUsedCount = PromotionDA.GetCustomerCouponNumber(customerCoupon.CouponSysNo, order.Customer.SysNo);
            //}
            if (customerCoupon.WebsiteMaxFrequency.HasValue && CodeTotalUsedCount >= customerCoupon.WebsiteMaxFrequency)
            {
                SetCouponError(ref order, LanguageHelper.GetText("此优惠券号码{0}在全网使用次数已用尽,请使用其他优惠券号码。", order.LanguageCode), couponCode);
                return;
            }
            //if (customerCoupon.WebsiteMaxFrequency.HasValue && totalUsedCount >= customerCoupon.WebsiteMaxFrequency)
            //{
            //    SetCouponError(ref order, LanguageHelper.GetText("此优惠券号码{0}的已达到全网使用次数上限", order.LanguageCode), couponCode);
            //    return;
            //}
            #endregion

            #region 2、获取该优惠券号码对应的优惠券活动所有信息
            CouponInfo coupon        = PromotionDA.GetComboInfoByCouponCode(order.CouponCode);
            var        orderItem     = order.OrderItemGroupList.FirstOrDefault();
            int        merchantSysNo = orderItem == null ? 1 : orderItem.MerchantSysNo;
            string     merchantName  = orderItem == null ? "泰隆" : orderItem.MerchantName;
            if (coupon.MerchantSysNo != merchantSysNo && coupon.MerchantSysNo != 1)
            {
                SetCouponError(ref order, LanguageHelper.GetText(string.Format("该优惠券不是{0}优惠券", merchantName), order.LanguageCode));
                return;
            }
            if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && CustomerUsedCount >= coupon.SaleRulesEx.CustomerMaxFrequency.Value)
            //if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && customerCoupon.UsedCount >= coupon.SaleRulesEx.CustomerMaxFrequency.Value)
            {
                SetCouponError(ref order, LanguageHelper.GetText("您已达到使用此优惠券活动的次数上限", order.LanguageCode));
                return;
            }
            if (coupon.SaleRulesEx.MaxFrequency.HasValue && totalUsedCount >= coupon.SaleRulesEx.MaxFrequency.Value)
            {
                SetCouponError(ref order, LanguageHelper.GetText("此优惠券活动已达到全网使用次数上限", order.LanguageCode));
                return;
            }


            if (coupon == null)
            {
                SetCouponError(ref order, LanguageHelper.GetText("此优惠券{0}不存在", order.LanguageCode), couponCode);
                return;
            }
            #endregion

            #region 3、详细检查该优惠券号码是否可用
            if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedEmailVerification) && coupon.SaleRulesEx.NeedEmailVerification.ToUpper().Trim() == "Y")
            {
                if (order.Customer.IsEmailConfirmed != 1)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券要求客户验证了电子邮箱才可使用!", order.LanguageCode));
                    return;
                }
            }
            if (!string.IsNullOrWhiteSpace(coupon.SaleRulesEx.NeedMobileVerification) && coupon.SaleRulesEx.NeedMobileVerification.ToUpper().Trim() == "Y")
            {
                if (order.Customer.IsPhoneValided != 1)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("此优惠券要求客户验证了手机才可使用!", order.LanguageCode));
                    return;
                }
            }
            if (coupon.SaleRulesList.Count > 0 && coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelCustomerRank))
            {
                //-1表示不限制
                if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == -1))
                {
                    int customerRank = order.Customer.CustomerRank;
                    if (!coupon.SaleRulesList.Exists(f => f.CustomerRank == customerRank))
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("当前客户不满足此优惠券要求的客户等级!", order.LanguageCode));
                        return;
                    }
                }
            }
            if (coupon.SaleRulesList.Count > 0 && coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelArea))
            {
                int  areaID     = order.Contact.AddressAreaID;
                Area area       = PromotionDA.GetAreaBySysNo(areaID);
                int  provinceId = area.ProvinceSysNo.Value;

                if (!coupon.SaleRulesList.Exists(f => f.SaleRuleType == CouponSaleRuleType.RelArea && f.AreaSysNo == provinceId))
                {
                    SetCouponError(ref order, LanguageHelper.GetText("当前客户不满足此优惠券要求的客户地区!", order.LanguageCode));
                    return;
                }
            }


            #endregion

            #region 4、计算该优惠券可以抵扣多少,填充到OrderInfo中
            if (coupon.DiscountRuleList != null && coupon.DiscountRuleList.Count > 0)
            {
                //取得满足优惠券条件的商品总金额
                decimal canCalculateAmount = GetCanCalculateAmount(ref order, coupon);
                if (canCalculateAmount == 0)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的商品,无法抵扣", order.LanguageCode));
                    return;
                }

                canCalculateAmount = canCalculateAmount - Math.Abs(order.TotalDiscountAmount);

                if (canCalculateAmount < coupon.SaleRulesEx.OrderAmountLimit)
                {
                    SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券要求的商品总金额下限{0},无法抵扣", order.LanguageCode), coupon.SaleRulesEx.OrderAmountLimit);
                    return;
                }


                #region 处理订单 折扣金额模式 和 百分比模式
                if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.OrderAmountDiscount || coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.OrderAmountPercentage)
                {
                    //获取适合的折扣规则
                    Coupon_DiscountRules curDiscountRule = GetMatchDiscountRule(coupon, canCalculateAmount);
                    if (curDiscountRule == null)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("订单总金额未达到优惠券要求的最小购买金额,无法抵扣", order.LanguageCode));
                        return;
                    }

                    decimal discount = 0m;
                    if (curDiscountRule.DiscountType == CouponDiscountType.OrderAmountDiscount)
                    {
                        discount = Math.Abs(Math.Round(curDiscountRule.Value, 2));
                    }
                    else
                    {
                        discount = Math.Abs(Math.Round(canCalculateAmount * curDiscountRule.Value, 2));
                    }



                    if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                    {
                        if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                        {
                            discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                        }
                    }

                    order.CouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                    order.CouponSysNo     = customerCoupon.CouponSysNo;
                    order.CouponName      = customerCoupon.CouponName;
                    order.CouponAmount    = discount;
                    order.CouponErrorDesc = string.Empty;
                }
                #endregion



                #region 处理 一个商品直减模式
                if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.ProductPriceDiscount)
                {
                    if (coupon.SaleRulesList == null || coupon.SaleRulesList.Count == 0)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                        return;
                    }
                    Coupon_SaleRules productSaleRule = coupon.SaleRulesList.Find(f => f.SaleRuleType == CouponSaleRuleType.RelProduct);


                    int discountProductSysNo = productSaleRule.ProductSysNo;

                    int     discountProductCount = 0;
                    decimal productReduce        = 0m;
                    decimal productPrice         = 0.00m;
                    foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
                    {
                        OrderProductItem item = itemGroup.ProductItemList.Find(f => f.ProductSysNo == discountProductSysNo);
                        if (item != null)
                        {
                            discountProductCount += item.UnitQuantity * itemGroup.Quantity;

                            productPrice = item.UnitSalePrice;
                        }
                    }
                    if (discountProductCount == 0)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                        return;
                    }

                    if (discountProductCount > coupon.DiscountRuleList[0].Quantity)
                    {
                        discountProductCount = coupon.DiscountRuleList[0].Quantity;
                    }

                    productReduce = coupon.DiscountRuleList[0].Value;
                    if (coupon.DiscountRuleList[0].Value > productPrice)
                    {
                        productReduce = productPrice;
                    }

                    decimal discount = Math.Abs(Math.Round(productReduce * discountProductCount, 2));



                    if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                    {
                        if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                        {
                            discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                        }
                    }
                    order.CouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                    order.CouponSysNo     = customerCoupon.CouponSysNo;
                    order.CouponName      = customerCoupon.CouponName;
                    order.CouponAmount    = discount;
                    order.CouponErrorDesc = string.Empty;

                    order["Coupon_DiscountProductSysNo"] = discountProductSysNo;
                    order["Coupon_DiscountProductCount"] = discountProductCount;
                }
                #endregion

                #region 处理 一个商品最终售价模式
                if (coupon.DiscountRuleList[0].DiscountType == CouponDiscountType.ProductPriceFinal)
                {
                    if (coupon.SaleRulesList == null || coupon.SaleRulesList.Count == 0)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                        return;
                    }
                    Coupon_SaleRules productSaleRule = coupon.SaleRulesList.Find(f => f.SaleRuleType == CouponSaleRuleType.RelProduct);


                    int discountProductSysNo = productSaleRule.ProductSysNo;

                    decimal discountProductPrice = 0.00m;
                    int     discountProductCount = 0;
                    foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
                    {
                        OrderProductItem item = itemGroup.ProductItemList.Find(f => f.ProductSysNo == discountProductSysNo);
                        if (item != null)
                        {
                            discountProductCount += item.UnitQuantity * itemGroup.Quantity;
                            discountProductPrice  = item.UnitSalePrice;
                        }
                    }
                    if (discountProductCount == 0)
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("没有满足该优惠券的指定商品,无法抵扣", order.LanguageCode));
                        return;
                    }
                    if (discountProductCount > coupon.DiscountRuleList[0].Quantity)
                    {
                        discountProductCount = coupon.DiscountRuleList[0].Quantity;
                    }

                    decimal discount = 0m;
                    if (discountProductPrice > coupon.DiscountRuleList[0].Value)
                    {
                        discount = Math.Abs(Math.Round((discountProductPrice - coupon.DiscountRuleList[0].Value) * discountProductCount, 2));
                    }
                    else
                    {
                        SetCouponError(ref order, LanguageHelper.GetText("该优惠券的指定商品已经是优惠券设定的最低价格,无法抵扣", order.LanguageCode));
                        return;
                    }
                    if (coupon.SaleRulesEx.OrderMaxDiscount.HasValue && coupon.SaleRulesEx.OrderMaxDiscount.Value > 0m)
                    {
                        if (discount > coupon.SaleRulesEx.OrderMaxDiscount.Value)
                        {
                            discount = coupon.SaleRulesEx.OrderMaxDiscount.Value;
                        }
                    }
                    order.CouponCodeSysNo = customerCoupon.CouponCodeSysNo;
                    order.CouponSysNo     = customerCoupon.CouponSysNo;
                    order.CouponName      = customerCoupon.CouponName;
                    order.CouponAmount    = discount;
                    order.CouponErrorDesc = string.Empty;

                    order["Coupon_DiscountProductSysNo"] = discountProductSysNo;
                    order["Coupon_DiscountProductCount"] = discountProductCount;
                }
                #endregion

                order["Coupon_DiscountType"] = coupon.DiscountRuleList[0].DiscountType;
            }

            #endregion
        }
示例#11
0
        public void Initialize(ref OrderInfo order)
        {
            int currencySysno;

            int.TryParse(ConstValue.CurrencySysNo, out currencySysno);
            decimal exchangeRate = PipelineDA.GetCurrencyExchangeRate(currencySysno);

            order["CurrencySysNo"] = currencySysno;
            order["ExchangeRate"]  = exchangeRate;

            foreach (OrderItemGroup itemGroup in order.OrderItemGroupList)
            {
                int minCountPerOrder = 0;
                int maxCountPerOrder = 0;
                foreach (OrderProductItem item in itemGroup.ProductItemList)
                {
                    //商品基础信息
                    ProductBasicInfo basicInfo = PipelineDA.GetProductBasicInfoBySysNo(item.ProductSysNo);
                    //商品备案信息
                    //ProductEntryInfo entryInfo = PipelineDA.GetProductEntryInfoBySysNo(item.ProductSysNo);
                    //basicInfo.ProductEntryInfo = entryInfo;
                    //item["ProductStoreType"] = (int)entryInfo.ProductStoreType;
                    //商品备货时间
                    //item["LeadTimeDays"] = basicInfo.ProductEntryInfo.LeadTimeDays;

                    //会员价格信息
                    ProductCustomerRankPrice rankPrice = null;
                    if (order.Customer != null && order.Customer.SysNo > 0)
                    {
                        rankPrice = ECommerce.DataAccess.Product.ProductDA.GetProductCustomerRankPrice(order.Customer.SysNo, item.ProductSysNo);
                    }
                    //商品销售信息
                    ProductSalesInfo salesInfo = PipelineDA.GetProductSalesInfoBySysNo(item.ProductSysNo);
                    item.ProductID       = basicInfo.Code;
                    item.ProductName     = basicInfo.ProductName;
                    item.Weight          = basicInfo.Weight;
                    item["ProductTitle"] = basicInfo.ProductTitle;
                    item.DefaultImage    = basicInfo.DefaultImage;
                    item.UnitMarketPrice = salesInfo.MarketPrice;
                    item.UnitCostPrice   = salesInfo.UnitCostPrice;
                    //套餐不享受会员价格
                    if (itemGroup.PackageNo > 0 && itemGroup.PackageType == 1)
                    {
                        item.UnitSalePrice = salesInfo.CurrentPrice;
                    }
                    else
                    {
                        item.UnitSalePrice = rankPrice != null && rankPrice.RankPrice < salesInfo.CurrentPrice ? rankPrice.RankPrice : salesInfo.CurrentPrice;
                    }
                    item.UnitRewardedPoint = salesInfo.Point;
                    //由calculators计算
                    //item.UnitTaxFee = salesInfo.EntryTax.HasValue ? salesInfo.EntryTax.Value : 0m;
                    //item["TariffRate"] = basicInfo.ProductEntryInfo.TariffRate;
                    item.TotalInventory     = salesInfo.OnlineQty;
                    item.MerchantSysNo      = basicInfo.VendorSysno;
                    item.MerchantName       = basicInfo.VendorInfo.VendorName;
                    itemGroup.MerchantSysNo = basicInfo.VendorSysno;
                    itemGroup.MerchantName  = basicInfo.VendorInfo.VendorName;
                    item["ProductStatus"]   = (int)basicInfo.ProductStatus;
                    item["Warranty"]        = basicInfo.Warranty;

                    salesInfo.MinCountPerOrder = salesInfo.OnlineQty < salesInfo.MinCountPerOrder ? salesInfo.OnlineQty : salesInfo.MinCountPerOrder;
                    salesInfo.MaxCountPerOrder = salesInfo.OnlineQty < salesInfo.MaxCountPerOrder ? salesInfo.OnlineQty : salesInfo.MaxCountPerOrder;

                    item["MinCountPerOrder"] = salesInfo.MinCountPerOrder;
                    item["MaxCountPerOrder"] = salesInfo.MaxCountPerOrder;

                    //每单限购计算,套餐则以套餐内商品最小限购数量为准
                    if (minCountPerOrder < salesInfo.MinCountPerOrder / item.UnitQuantity)
                    {
                        minCountPerOrder = salesInfo.MinCountPerOrder / item.UnitQuantity;
                    }
                    if (maxCountPerOrder.Equals(0) || maxCountPerOrder > salesInfo.MaxCountPerOrder / item.UnitQuantity)
                    {
                        maxCountPerOrder = salesInfo.MaxCountPerOrder / item.UnitQuantity;
                    }


                    decimal price = GetProductStepPrice(item.UnitSalePrice, item.ProductSysNo, itemGroup.Quantity);
                    item.UnitSalePrice = price;

                    //商品分组属性
                    List <ProductSplitGroupProperty> splitGroupProperty = PipelineDA.GetProductSplitGroupPropertyList(item.ProductSysNo);
                    if (splitGroupProperty != null && splitGroupProperty.Count > 0)
                    {
                        item.SplitGroupPropertyDescList = new List <KeyValuePair <string, string> >();
                        foreach (ProductSplitGroupProperty property in splitGroupProperty)
                        {
                            item.SplitGroupPropertyDescList.Add(new KeyValuePair <string, string>(property.PropertyDescription, property.ValueDescription));
                        }
                    }
                }
                itemGroup.MinCountPerSO = minCountPerOrder;
                itemGroup.MaxCountPerSO = maxCountPerOrder;
                //套餐名称
                if (itemGroup.PackageType.Equals(1))
                {
                    var combo = PromotionDA.GetComboByComboSysNo(itemGroup.PackageNo);
                    if (combo != null)
                    {
                        itemGroup["PackageName"] = combo.SaleRuleName;
                    }
                }
            }
        }