Ejemplo n.º 1
0
        public static bool Copy(CouponsInfo entity)
        {
            CouponsInfo entity2 = new CouponsInfo
            {
                Title         = entity.Title,
                SN            = Coupons.CreateSN(),
                Notes         = entity.Notes,
                Touch         = entity.Touch,
                StartTime     = entity.StartTime,
                EndTime       = entity.EndTime,
                UserName      = string.Empty,
                IsUsed        = false,
                Sort          = 999,
                Lang          = JObject.cultureLang,
                AutoTimeStamp = DateTime.Now
            };
            bool flag;

            if (Coupons.ExistsSN(entity.SN))
            {
                do
                {
                    entity.SN = Coupons.CreateSN();
                }while (Coupons.ExistsSN(entity.SN));
                flag = true;
            }
            else
            {
                flag = true;
            }
            return(flag && Coupons.Add(entity2) > 0);
        }
Ejemplo n.º 2
0
        public void SaveMaster(EventHandler <RestClientEventArgs <CouponsInfoViewModel> > callback)
        {
            if (!_viewModel.SysNo.HasValue)
            {
                string relativeUrl = "/MKTService/Coupons/CreateMaster";
                _viewModel.CompanyCode = CPApplication.Current.CompanyCode;
                restClient.Create <int?>(relativeUrl, VtoE(_viewModel), (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    _viewModel.SysNo  = args.Result;
                    _viewModel.Status = CouponsStatus.Init;
                    callback(obj, new RestClientEventArgs <CouponsInfoViewModel>(_viewModel, restClient.Page));
                });
            }
            else
            {
                string relativeUrl = "/MKTService/Coupons/UpdateMaster";

                restClient.Update <CouponsInfo>(relativeUrl, VtoE(_viewModel), (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }
                    CouponsInfo entity = args.Result;
                    _viewModel         = new CouponsInfoViewModel();
                    _viewModel         = EtoV(entity);
                    callback(obj, new RestClientEventArgs <CouponsInfoViewModel>(_viewModel, restClient.Page));
                });
            }
        }
Ejemplo n.º 3
0
 protected void lnk_Delete_Click(object sender, System.EventArgs e)
 {
     if (!base.IsAuthorizedOp(ActionType.Delete.ToString()))
     {
         base.ShowAjaxMsg(this.UpdatePanel1, "Không có thẩm quyền");
     }
     else
     {
         int         @int     = WebUtils.GetInt((sender as LinkButton).CommandArgument);
         CouponsInfo dataById = SinGooCMS.BLL.Coupons.GetDataById(@int);
         if (dataById == null)
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Những thông tin này không được tìm thấy, các dữ liệu không tồn tại hoặc đã bị xóa");
         }
         else if (SinGooCMS.BLL.Coupons.Delete(@int))
         {
             this.BindData();
             PageBase.log.AddEvent(base.LoginAccount.AccountName, "删除优惠券[" + dataById.Title + "] thành công");
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thành công");
         }
         else
         {
             base.ShowAjaxMsg(this.UpdatePanel1, "Thao tác thất bại");
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新主信息
        /// </summary>
        /// <param name="info"></param>
        public virtual CouponsInfo UpdateMaster(CouponsInfo info)
        {
            _processor.UpdateMaster(info);
            CouponsInfo result = Load(info.SysNo);

            return(result);
        }
 void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     t.Stop();
     try
     {
         DateTime nowDT = SeatManage.Bll.ServiceDateTime.Now;
         List <SeatManage.ClassModel.AMS_Advertisement> modelList = SeatManage.Bll.AdvertisementOperation.GetAdList(false, SeatManage.EnumType.AdType.SlipCustomerAd);
         foreach (AMS_Advertisement item in modelList)
         {
             CouponsInfo coupons = CouponsInfo.ToModel(item.AdContent);
             for (int i = 0; i < coupons.PopItemList.Count; i++)
             {
                 if (coupons.PopItemList[i].EffectDate > nowDT || coupons.PopItemList[i].EndDate < nowDT)
                 {
                     coupons.PopItemList.Remove(coupons.PopItemList[i]);
                     i--;
                 }
             }
             coupons.ID = item.ID;
             CouponsList[coupons.Station].Add(coupons);
         }
         SeatManage.Bll.FileOperate getImage = new SeatManage.Bll.FileOperate();
         foreach (KeyValuePair <int, ObservableCollection <CouponsInfo> > item in _CouponsList)
         {
             for (int i = 0; i < item.Value.Count; i++)
             {
                 for (int j = 0; j < item.Value[i].ImageFilePath.Count; j++)
                 {
                     string imageName = string.Format("{0}{1}", PlayerSetting.SysPath + "\\CouponsImage\\", item.Value[i].ImageFilePath[j]);
                     getImage.FileDownLoad(imageName, item.Value[i].ImageFilePath[j], SeatManage.EnumType.SeatManageSubsystem.SlipCustomerAd);
                 }
             }
             if (item.Value.Count == 0)
             {
                 CouponsInfo coupons = new CouponsInfo();
                 coupons.Num       = "";
                 coupons.LogoImage = PlayerSetting.DefaultVideosPath + PlayerSetting.DefaultVideo;
                 item.Value.Add(coupons);
             }
         }
         t1.Stop();
         if (ScrollStart != null)
         {
             ScrollStart(this, new EventArgs());
         }
     }
     catch (Exception ex)
     {
         if (looptime > 300)
         {
             t1.Stop();
         }
         else
         {
             t.Start();
         }
     }
 }
Ejemplo n.º 6
0
        public virtual decimal GetCouponAmountForPM(ProductInfo product, int couponSysNo)
        {
            decimal     result = 0.00m;
            CouponsInfo coupon = ObjectFactory <CouponsProcessor> .Instance.Load(couponSysNo);

            if (coupon.CouponChannelType.Value == CouponsMKTType.MKTPM && coupon.ProductRangeType.Value == CouponsProductRangeType.LimitProduct)
            {
                decimal maxDiscount = 0.00m;
                if (coupon.OrderAmountDiscountRule != null && coupon.OrderAmountDiscountRule.OrderAmountDiscountRank != null && coupon.OrderAmountDiscountRule.OrderAmountDiscountRank.Count > 0)
                {
                    foreach (OrderAmountDiscountRank rank in coupon.OrderAmountDiscountRule.OrderAmountDiscountRank)
                    {
                        decimal tempDiscount = 0.00m;
                        if (rank.DiscountType.Value == PSDiscountTypeForOrderAmount.OrderAmountPercentage) //百分比:优惠券金额=商品当前价*百分比
                        {
                            tempDiscount = Math.Round(product.ProductPriceInfo.CurrentPrice.Value * rank.DiscountValue.Value, 2);
                        }
                        else //折扣金额:优惠券金额=折扣金额
                        {
                            tempDiscount = Convert.ToDecimal(rank.DiscountValue);
                        }
                        if (tempDiscount > maxDiscount)
                        {
                            maxDiscount = tempDiscount;
                        }
                    }
                }

                if (coupon.PriceDiscountRule != null && coupon.PriceDiscountRule.Count > 0)
                {
                    foreach (PSPriceDiscountRule rule in coupon.PriceDiscountRule)
                    {
                        decimal tempDiscount = 0.00m;
                        if (rule.DiscountType.Value == PSDiscountTypeForProductPrice.ProductPriceDiscount)
                        {
                            tempDiscount = rule.DiscountValue.Value;
                        }
                        if (rule.DiscountType.Value == PSDiscountTypeForProductPrice.ProductPriceFinal)
                        {
                            tempDiscount = product.ProductPriceInfo.CurrentPrice.Value - rule.DiscountValue.Value;
                        }

                        if (tempDiscount > maxDiscount)
                        {
                            maxDiscount = tempDiscount;
                        }
                    }
                }

                result = maxDiscount;
            }



            return(result);
        }
Ejemplo n.º 7
0
        private void InitForModify()
        {
            CouponsInfo dataById = SinGooCMS.BLL.Coupons.GetDataById(base.OpID);

            this.TextBox1.Text      = dataById.Title;
            this.TextBox2.Text      = dataById.Notes.ToString("f2");
            this.TextBox3.Text      = dataById.Touch.ToString("f2");
            this.TextBox4.Text      = dataById.StartTime.ToString("yyyy-MM-dd");
            this.TextBox5.Text      = dataById.EndTime.ToString("yyyy-MM-dd");
            this.TextBox6.Text      = dataById.UserName;
            this.chkhasused.Checked = dataById.IsUsed;
        }
Ejemplo n.º 8
0
 protected void btnok_Click(object sender, System.EventArgs e)
 {
     if (!base.IsAuthorizedOp("Copy"))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else
     {
         CouponsInfo dataById = SinGooCMS.BLL.Coupons.GetDataById(base.OpID);
         int         @int     = WebUtils.GetInt(this.TextBox1.Text);
         if (dataById == null)
         {
             base.ShowMsg("找不到原始优惠券信息!");
         }
         else if (@int <= 0)
         {
             base.ShowMsg("无效的复制张数!");
         }
         else if (@int > 10000)
         {
             base.ShowMsg("最大不能超过10000张!");
         }
         else
         {
             string text = string.Empty;
             for (int i = 0; i < @int; i++)
             {
                 if (!SinGooCMS.BLL.Coupons.Copy(dataById))
                 {
                     text = text + "复制第" + i.ToString() + "条优惠券时发生错误";
                     break;
                 }
                 System.Threading.Thread.Sleep(50);
             }
             if (string.IsNullOrEmpty(text))
             {
                 PageBase.log.AddEvent(base.LoginAccount.AccountName, string.Concat(new string[]
                 {
                     "批量复制",
                     @int.ToString(),
                     "张优惠券[",
                     dataById.Title,
                     "] thành công"
                 }));
                 MessageUtils.DialogCloseAndParentReload(this);
             }
             else
             {
                 base.ShowMsg(text);
             }
         }
     }
 }
Ejemplo n.º 9
0
        public static int Add(CouponsInfo entity)
        {
            int result;

            if (entity == null)
            {
                result = 0;
            }
            else
            {
                result = BizBase.dbo.InsertModel <CouponsInfo>(entity);
            }
            return(result);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 计算优惠券code有效期
        /// </summary>
        /// <param name="master"></param>
        /// <param name="codeEntity"></param>
        public static void GetCodeExpireDate(CouponsInfo master, CouponCodeSetting codeEntity)
        {
            #region beginDate,EndDate
            switch (master.ValidPeriod.Value)
            {
            case CouponsValidPeriodType.All:
                codeEntity.StartTime = master.StartTime;
                codeEntity.EndTime   = master.EndTime;
                break;

            case CouponsValidPeriodType.PublishDayToOneWeek:
                codeEntity.StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                codeEntity.EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddDays(7);
                break;

            case CouponsValidPeriodType.PublishDayToOneMonth:
                codeEntity.StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                codeEntity.EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddMonths(1);
                break;

            case CouponsValidPeriodType.PublishDayToTwoMonths:
                codeEntity.StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                codeEntity.EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddMonths(2);
                break;

            case CouponsValidPeriodType.PublishDayToThreeMonths:
                codeEntity.StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                codeEntity.EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddMonths(3);
                break;

            case CouponsValidPeriodType.PublishDayToSixMonths:
                codeEntity.StartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                codeEntity.EndTime   = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")).AddMonths(6);
                break;

            case CouponsValidPeriodType.CustomPeriod:
                codeEntity.StartTime = master.CustomBindBeginDate;
                codeEntity.EndTime   = master.CustomBindEndDate;
                break;

            default:
                codeEntity.StartTime = master.StartTime;
                codeEntity.EndTime   = master.EndTime;
                break;
            }
            #endregion
        }
Ejemplo n.º 11
0
        private void AddCoupons()
        {
            string      formString = WebUtils.GetFormString("code");
            CouponsInfo dataBySN   = Coupons.GetDataBySN(formString);

            if (dataBySN == null)
            {
                base.WriteJsonTip(false, "优惠券编码无效", "");
            }
            else if (base.UserID == -1)
            {
                base.WriteJsonTip(false, "会员没有登录", "");
            }
            else if (dataBySN.EndTime > System.DateTime.Now)
            {
                base.WriteJsonTip(false, "优惠券已过期", "");
            }
            else if (!string.IsNullOrEmpty(dataBySN.UserName))
            {
                base.WriteJsonTip(false, "优惠券已经绑定了会员", "");
            }
            else if (dataBySN.IsUsed)
            {
                base.WriteJsonTip(false, "优惠券已经使用过了", "");
            }
            else if (dataBySN.UserName == base.UserName)
            {
                base.WriteJsonTip(false, "已经绑定了这张优惠券", "");
            }
            else
            {
                dataBySN.UserName = base.UserName;
                if (Coupons.Update(dataBySN))
                {
                    base.WriteJsonTip(true, "优惠券绑定成功!", "");
                }
                else
                {
                    base.WriteJsonTip(false, "Thao tác thất bại!", "");
                }
            }
        }
Ejemplo n.º 12
0
        public void Load(int?couponsSysNo, EventHandler <RestClientEventArgs <CouponsInfoViewModel> > callback)
        {
            if (couponsSysNo.HasValue)
            {
                string relativeUrl = string.Format("/MKTService/Coupons/{0}", couponsSysNo.Value);
                restClient.Query <CouponsInfo>(relativeUrl, (obj, args) =>
                {
                    if (args.FaultsHandle())
                    {
                        return;
                    }

                    CouponsInfo entity = args.Result;
                    _viewModel         = EtoV(entity);

                    callback(obj, new RestClientEventArgs <CouponsInfoViewModel>(_viewModel, restClient.Page));
                });
            }
            else
            {
                callback(new Object(), new RestClientEventArgs <CouponsInfoViewModel>(_viewModel, restClient.Page));
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// 创建优惠券主信息,因为优惠券是分步进行创建的
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public virtual int?CreateMaster(CouponsInfo info)
 {
     return(_processor.CreateMaster(info).Value);
 }
Ejemplo n.º 14
0
        private CouponsInfo VtoE(CouponsInfoViewModel viewmodel)
        {
            if (viewmodel.PayTypeSysNo.HasValue)
            {
                viewmodel.OrderCondition.PayTypeSysNoList = new System.Collections.Generic.List <int>();
                viewmodel.OrderCondition.PayTypeSysNoList.Add(viewmodel.PayTypeSysNo.Value);
            }
            else
            {
                viewmodel.OrderCondition.PayTypeSysNoList = new System.Collections.Generic.List <int>();
            }

            if (viewmodel.ShipTypeSysNo.HasValue)
            {
                viewmodel.OrderCondition.ShippingTypeSysNoList = new System.Collections.Generic.List <int>();
                viewmodel.OrderCondition.ShippingTypeSysNoList.Add(viewmodel.ShipTypeSysNo.Value);
            }
            else
            {
                viewmodel.OrderCondition.ShippingTypeSysNoList = new System.Collections.Generic.List <int>();
            }

            if (viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank != null &&
                viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank.Count > 0)
            {
                foreach (OrderAmountDiscountRankViewModel rank in viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank)
                {
                    if (rank.DiscountType.Value == PSDiscountTypeForOrderAmount.OrderAmountPercentage)
                    {
                        rank.DiscountValue = rank.DiscountValue.Value;
                    }
                }
            }


            CouponsInfo entity = viewmodel.ConvertVM <CouponsInfoViewModel, CouponsInfo>();

            entity.Title = new BizEntity.LanguageContent(viewmodel.Title);
            if (viewmodel.IsCustomerNoLimit.Value)
            {
                entity.CustomerCondition.RelCustomerRanks = new RelCustomerRank();
                entity.CustomerCondition.RelCustomerRanks.CustomerRankList  = new List <BizEntity.Common.SimpleObject> ();
                entity.CustomerCondition.RelCustomerRanks.IsIncludeRelation = true;
                entity.CustomerCondition.RelCustomerRanks.CustomerRankList.Add(new SimpleObject {
                    SysNo = -1
                });
            }
            //商家限定条件
            if (viewmodel.ProductCondition != null)
            {
                if (viewmodel.ProductCondition.ListRelVendorViewModel != null)
                {
                    if (entity.ProductCondition == null)
                    {
                        entity.ProductCondition = new PSProductCondition();
                    }
                    if (entity.ProductCondition.ListRelVendor == null)
                    {
                        entity.ProductCondition.ListRelVendor = new List <RelVendor>();
                    }

                    foreach (var item in viewmodel.ProductCondition.ListRelVendorViewModel)
                    {
                        entity.ProductCondition.ListRelVendor.Add(new RelVendor()
                        {
                            VendorName = item.VendorName, VendorSysNo = item.VendorSysNo
                        });
                    }
                }
            }
            if (entity.BindRule == null)
            {
                entity.BindRule = new CouponBindRule();
            }
            if (entity.BindRule.RelProducts == null)
            {
                entity.BindRule.RelProducts = new RelProduct();
            }
            //entity.BindRule = new CouponBindRule();
            //entity.BindRule.RelProducts = new RelProduct();
            //if (viewmodel.BindCondition == CouponsBindConditionType.SO)
            //{
            //    if (viewmodel.BindRule != null)
            //    {
            //        entity.BindRule.AmountLimit = viewmodel.BindRule.AmountLimit;
            //        if (viewmodel.BindRule.RelProducts != null)
            //        {
            //            entity.BindRule.RelProducts.IsIncludeRelation = viewmodel.BindRule.RelProducts.IsIncludeRelation;
            //            if (viewmodel.BindRule.RelProducts.ProductList != null && viewmodel.BindRule.RelProducts.ProductList.Count > 0)
            //            {
            //                entity.BindRule.RelProducts.ProductList = new List<RelProductAndQty>();
            //                foreach (var itemViewModel in viewmodel.BindRule.RelProducts.ProductList)
            //                {
            //                    RelProductAndQty item=new RelProductAndQty();
            //                    item.ProductSysNo=itemViewModel.ProductSysNo;
            //                    item.MinQty = itemViewModel.MinQty;

            //                    item.ProductID = itemViewModel.ProductID;
            //                    item.ProductName = itemViewModel.ProductName;
            //                    item.AvailableQty = itemViewModel.AvailableQty;
            //                    item.ConsignQty = itemViewModel.ConsignQty;
            //                    item.VirtualQty = itemViewModel.VirtualQty;
            //                    item.UnitCost = itemViewModel.UnitCost;
            //                    item.CurrentPrice = itemViewModel.CurrentPrice;
            //                    item.GrossMarginRate = itemViewModel.GrossMarginRate;
            //                    item.Priority = itemViewModel.Priority;
            //                    item.PromotionSysNo = viewmodel.SysNo;
            //                    item.ProductRangeType = viewmodel.ProductRangeType;

            //                    entity.BindRule.RelProducts.ProductList.Add(item);
            //                }
            //            }
            //        }
            //    }

            //}

            return(entity);
        }
Ejemplo n.º 15
0
 public static bool Update(CouponsInfo entity)
 {
     return(entity != null && BizBase.dbo.UpdateModel <CouponsInfo>(entity));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 金额方面的折扣处理:目前价格方面的折扣与总金额方面的折扣不可并存
        /// </summary>
        /// <param name="promotionInfo"></param>
        /// <param name="soInfo"></param>
        /// <param name="canPromotionSOItemList"></param>
        protected void CalcAmountRule(SOPromotionInfo promotionInfo, SOInfo soInfo,
                                      List <SOItemInfo> canPromotionSOItemList, CouponsInfo couponsInfo)
        {
            PSOrderAmountDiscountRule  ruleAmount    = couponsInfo.OrderAmountDiscountRule;
            List <PSPriceDiscountRule> rulePriceList = couponsInfo.PriceDiscountRule;
            decimal sumAllItemPriceAmount            = 0.00m;            //能够参与活动的商品总金额,所有商品原价乘以数量的总金额
            decimal sumAllOrderItemAmount            = 0.00m;            //所有订单商品的商品总金额,用于计算优惠券平摊金额
            decimal saleRulePromotionAmount          = 0.00m;            //除去优惠券后,其它优惠金额总额
            decimal soItemAmount       = soInfo.BaseInfo.SOAmount.Value; //订单商品实际总金额,已经扣去了Combo等折扣
            decimal?orderMaxDiscount   = null;                           //本活动中设置的每单折扣上限
            decimal calcDiscountAmount = 0.00m;                          //计算出来的折扣

            foreach (SOItemInfo item in canPromotionSOItemList)
            {
                sumAllItemPriceAmount += Math.Round(item.OriginalPrice.Value * ((decimal)item.Quantity.Value), 2);
            }

            foreach (var item in soInfo.Items)
            {
                if (item.ProductType.Value == SOProductType.Product || item.ProductType.Value == SOProductType.ExtendWarranty)
                {
                    sumAllOrderItemAmount   += item.OriginalPrice.Value * ((decimal)item.Quantity.Value);
                    saleRulePromotionAmount += item.PromotionAmount ?? 0.00M;
                }
            }

            #region 计算总金额方面的折扣
            if (ruleAmount != null && ruleAmount.OrderAmountDiscountRank != null && ruleAmount.OrderAmountDiscountRank.Count > 0)
            {
                calcDiscountAmount = 0.00m;

                orderMaxDiscount = ruleAmount.OrderMaxDiscount;
                if (ruleAmount.OrderAmountDiscountRank != null && ruleAmount.OrderAmountDiscountRank.Count > 0)
                {
                    //首先确认取折扣信息时,根据限定金额Amount倒序
                    var ruleAmountDiscountRankNew = from p in ruleAmount.OrderAmountDiscountRank
                                                    orderby p.OrderMinAmount descending
                                                    select p;
                    foreach (OrderAmountDiscountRank rank in ruleAmountDiscountRankNew)
                    {
                        decimal minAmount = rank.OrderMinAmount.HasValue ? rank.OrderMinAmount.Value : 0.00m;

                        if (couponsInfo.ProductRangeType == CouponsProductRangeType.AllProducts && sumAllItemPriceAmount < minAmount)
                        {
                            //普通订单商品(SOItemInfo.ProductType==SOProductType.Product的商品)的总金额与限定金额值比较,跳过不满足条件价格条件。
                            continue;
                        }
                        if (soItemAmount >= minAmount)
                        {
                            if (rank.DiscountType.Value == PSDiscountTypeForOrderAmount.OrderAmountPercentage)
                            {
                                calcDiscountAmount = Math.Round(soItemAmount * rank.DiscountValue.Value, 2);
                            }
                            if (rank.DiscountType.Value == PSDiscountTypeForOrderAmount.OrderAmountDiscount)
                            {
                                calcDiscountAmount = Math.Round(rank.DiscountValue.Value, 2);
                            }
                            break;
                        }
                    }
                }
            }
            #endregion

            #region 计算商品价格方面的折扣
            if (rulePriceList != null && rulePriceList.Count > 0)
            {
                calcDiscountAmount = 0.00m;

                List <PSPriceDiscountRule> discountList = rulePriceList.FindAll(f => f.DiscountType == PSDiscountTypeForProductPrice.ProductPriceDiscount);
                List <PSPriceDiscountRule> finalList    = rulePriceList.FindAll(f => f.DiscountType == PSDiscountTypeForProductPrice.ProductPriceFinal);
                //如果商品价格是直接折扣
                if (discountList != null && discountList.Count > 0)
                {
                    var discountListNew = from p in discountList
                                          orderby p.MinQty descending
                                          select p;
                    foreach (SOItemInfo item in canPromotionSOItemList)
                    {
                        foreach (PSPriceDiscountRule prule in discountListNew)
                        {
                            int minQty = prule.MinQty.HasValue ? prule.MinQty.Value : 1;
                            if (item.Quantity >= minQty)
                            {
                                calcDiscountAmount += Math.Round(prule.DiscountValue.Value * item.Quantity.Value, 2);
                                break;
                            }
                        }
                    }
                }

                //如果是最终售价
                if (finalList != null && finalList.Count > 0)
                {
                    var finalListNew = from p in finalList
                                       orderby p.MinQty descending
                                       select p;
                    foreach (SOItemInfo item in canPromotionSOItemList)
                    {
                        foreach (PSPriceDiscountRule prule in finalListNew)
                        {
                            int minQty = prule.MinQty.HasValue ? prule.MinQty.Value : 1;
                            if (item.Quantity >= minQty)
                            {
                                //当单个商品 最终售价大于商品售价时
                                if (prule.DiscountValue.Value >= item.Price.Value)
                                {
                                    calcDiscountAmount += 0.00m;
                                }
                                else
                                {
                                    calcDiscountAmount += Math.Round((item.Price.Value - prule.DiscountValue.Value) * item.Quantity.Value, 2);
                                }
                                break;
                            }
                        }
                    }
                }
            }
            #endregion

            #region 得到真正最终可以折扣的金额
            decimal canDiscountAmount = calcDiscountAmount;
            if (orderMaxDiscount.HasValue)
            {
                if (calcDiscountAmount <= orderMaxDiscount.Value)
                {
                    canDiscountAmount = calcDiscountAmount;
                }
                else
                {
                    canDiscountAmount = Math.Round(orderMaxDiscount.Value, 2);
                }
            }

            promotionInfo.DiscountAmount = Math.Abs(canDiscountAmount);
            #endregion

            #region 开始分摊折扣金额
            if (promotionInfo.DiscountAmount == 0.00m)
            {
                return;
            }
            //最后一个Item要特殊处理,要用总折扣减去前边所有item的折扣合
            decimal allocatedDiscount        = 0.00m;
            decimal actualAllItemPriceAmount = sumAllOrderItemAmount + saleRulePromotionAmount;
            if (actualAllItemPriceAmount != 0)
            {
                for (int i = 0; i < promotionInfo.SOPromotionDetails.Count; i++)
                {
                    SOPromotionDetailInfo detail = promotionInfo.SOPromotionDetails[i];
                    SOItemInfo            item   = soInfo.Items.Find(f => f.ProductSysNo == detail.MasterProductSysNo);
                    //除去套餐优惠金额
                    decimal pTotal = item.OriginalPrice.Value * item.Quantity.Value + item.PromotionAmount ?? 0;
                    if (i < promotionInfo.SOPromotionDetails.Count - 1)
                    {
                        //decimal currentDiscount=decimal.Floor((canDiscountAmount * (pTotal / sumAllItemPriceAmount)) * 100) / 100;
                        decimal currentDiscount = canDiscountAmount * (pTotal / actualAllItemPriceAmount); //只保留小数点后两位,Bug:89610
                        currentDiscount       = Math.Abs(currentDiscount);
                        currentDiscount       = Math.Min(currentDiscount, pTotal);
                        detail.DiscountAmount = currentDiscount;
                        allocatedDiscount    += currentDiscount;
                    }
                    else
                    {
                        detail.DiscountAmount = Math.Abs(canDiscountAmount - allocatedDiscount);
                        detail.DiscountAmount = Math.Min(detail.DiscountAmount.Value, pTotal);
                    }
                }
            }
            #endregion
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取优惠券所有信息,包含了组装好的其它Domain的描述、计算类信息,但是不Load优惠券代码信息
        /// </summary>
        /// <param name="sysNo"></param>
        /// <returns></returns>
        public virtual CouponsInfo Load(int?sysNo)
        {
            CouponsInfo info = _processor.Load(sysNo);

            //在APPService中,Load 是为了Restful所调用,所以需要组装CouponsInfo中其它Domain中的描述类信息


            #region 商品范围条件
            if (info.ProductCondition != null)
            {
                //组装品牌的名称信息在UI上显示
                if (info.ProductCondition.RelBrands != null &&
                    info.ProductCondition.RelBrands.BrandList != null &&
                    info.ProductCondition.RelBrands.BrandList.Count > 0)
                {
                    foreach (SimpleObject obj in info.ProductCondition.RelBrands.BrandList)
                    {
                        obj.Name = ExternalDomainBroker.GetBrandInfoBySysNo(obj.SysNo.Value).BrandNameLocal.Content;
                    }
                }
                //组装商品类别的名称信息在UI上显示
                if (info.ProductCondition.RelCategories != null &&
                    info.ProductCondition.RelCategories.CategoryList != null &&
                    info.ProductCondition.RelCategories.CategoryList.Count > 0)
                {
                    foreach (SimpleObject obj in info.ProductCondition.RelCategories.CategoryList)
                    {
                        obj.Name = ExternalDomainBroker.GetCategory3Info(obj.SysNo.Value).CategoryName.Content;
                    }
                }

                //组装商品的ID、名称、毛利率在UI上显示
                if (info.ProductCondition.RelProducts != null &&
                    info.ProductCondition.RelProducts.ProductList != null &&
                    info.ProductCondition.RelProducts.ProductList.Count > 0)
                {
                    foreach (RelProductAndQty prd in info.ProductCondition.RelProducts.ProductList)
                    {
                        ProductInfo product = ExternalDomainBroker.GetProductInfo(prd.ProductSysNo.Value);
                        prd.ProductName = product.ProductBasicInfo.ProductTitle.Content;
                        prd.ProductID   = product.ProductID;
                        if (info.CouponChannelType == CouponsMKTType.MKTPM)
                        {
                            prd.GrossMarginRate = ObjectFactory <GrossMarginProcessor> .Instance.GetCouponGrossMarginRateForPM(product, sysNo.Value);
                        }
                        else
                        {
                            prd.GrossMarginRate = ObjectFactory <GrossMarginProcessor> .Instance.GetCouponGrossMarginRate(product);
                        }
                    }
                }
            }
            #endregion

            #region 客户范围条件
            if (info.CustomerCondition != null)
            {
                //地区信息的名称在Portal端组装(因为客户端本身也要加载所有地区信息)
                //客户等级的名称在Portal端组装(因为客户端本身也要加载所有等级信息)

                //服务端组装Customer的基础信息
                if (info.CustomerCondition.RelCustomers != null &&
                    info.CustomerCondition.RelCustomers.CustomerIDList != null &&
                    info.CustomerCondition.RelCustomers.CustomerIDList.Count > 0)
                {
                    foreach (CustomerAndSend cas in info.CustomerCondition.RelCustomers.CustomerIDList)
                    {
                    }
                }
            }
            #endregion


            info.IsExistThrowInTypeCouponCode = _processor.CheckExistThisTypeCouponCode(info.SysNo, CouponCodeType.ThrowIn);

            return(info);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 设置客户范围
 /// </summary>
 /// <param name="info"></param>
 public virtual void SetCustomerCondition(CouponsInfo info)
 {
     _processor.SetCustomerCondition(info);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 设置优惠券活动规则,包含:订单条件,使用频率条件和每单折扣上限;设置客户发放规则
 /// </summary>
 /// <param name="info"></param>
 public virtual void SetSaleRuleEx(CouponsInfo info)
 {
     _processor.SetSaleRuleEx(info);
 }
Ejemplo n.º 20
0
 public virtual void SetCouponsSaleRuleEx(CouponsInfo info)
 {
     ObjectFactory <CouponsAppService> .Instance.SetSaleRuleEx(info);
 }
Ejemplo n.º 21
0
 public virtual CouponsInfo UpdateCouponsMaster(CouponsInfo info)
 {
     return(ObjectFactory <CouponsAppService> .Instance.UpdateMaster(info));
 }
Ejemplo n.º 22
0
 public virtual void SetCouponsDiscountRule(CouponsInfo info)
 {
     ObjectFactory <CouponsAppService> .Instance.SetDiscountRule(info);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// 设置商品范围
 /// </summary>
 /// <param name="info"></param>
 public virtual void SetProductCondition(CouponsInfo info)
 {
     _processor.SetProductCondition(info);
 }
Ejemplo n.º 24
0
 public virtual void SetCouponsCustomerCondition(CouponsInfo info)
 {
     ObjectFactory <CouponsAppService> .Instance.SetCustomerCondition(info);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// 设置折扣规则
 /// </summary>
 /// <param name="info"></param>
 public virtual void SetDiscountRule(CouponsInfo info)
 {
     _processor.SetDiscountRule(info);
 }
Ejemplo n.º 26
0
 protected void btnok_Click(object sender, System.EventArgs e)
 {
     if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else
     {
         CouponsInfo couponsInfo = new CouponsInfo();
         if (base.IsEdit)
         {
             couponsInfo = SinGooCMS.BLL.Coupons.GetDataById(base.OpID);
         }
         couponsInfo.Title     = WebUtils.GetString(this.TextBox1.Text);
         couponsInfo.Notes     = WebUtils.GetDecimal(this.TextBox2.Text);
         couponsInfo.Touch     = WebUtils.GetDecimal(this.TextBox3.Text);
         couponsInfo.StartTime = WebUtils.GetDateTime(this.TextBox4.Text);
         couponsInfo.EndTime   = WebUtils.GetDateTime(this.TextBox5.Text);
         couponsInfo.UserName  = WebUtils.GetString(this.TextBox6.Text);
         couponsInfo.IsUsed    = this.chkhasused.Checked;
         if (string.IsNullOrEmpty(couponsInfo.Title))
         {
             base.ShowMsg("优惠券标题不能为空!");
         }
         else if (couponsInfo.Notes <= 0m)
         {
             base.ShowMsg("优惠券面值不正确!");
         }
         else if (couponsInfo.EndTime < couponsInfo.StartTime)
         {
             base.ShowMsg("截止日期不应该在开始日期前面!");
         }
         else
         {
             if (base.Action.Equals(ActionType.Add.ToString()))
             {
                 couponsInfo.SN            = SinGooCMS.BLL.Coupons.CreateSN();
                 couponsInfo.Sort          = 999;
                 couponsInfo.AutoTimeStamp = System.DateTime.Now;
                 if (SinGooCMS.BLL.Coupons.Add(couponsInfo) > 0)
                 {
                     PageBase.log.AddEvent(base.LoginAccount.AccountName, "添加优惠券[" + couponsInfo.Title + "] thành công");
                     base.Response.Redirect(string.Concat(new object[]
                     {
                         "Coupons.aspx?CatalogID=",
                         base.CurrentCatalogID,
                         "&Module=",
                         base.CurrentModuleCode,
                         "&action=View"
                     }));
                 }
                 else
                 {
                     base.ShowMsg("添加优惠券失败");
                 }
             }
             if (base.Action.Equals(ActionType.Modify.ToString()))
             {
                 if (SinGooCMS.BLL.Coupons.Update(couponsInfo))
                 {
                     PageBase.log.AddEvent(base.LoginAccount.AccountName, "修改优惠券[" + couponsInfo.Title + "] thành công");
                     base.Response.Redirect(string.Concat(new object[]
                     {
                         "Coupons.aspx?CatalogID=",
                         base.CurrentCatalogID,
                         "&Module=",
                         base.CurrentModuleCode,
                         "&action=View"
                     }));
                 }
                 else
                 {
                     base.ShowMsg("修改优惠券失败");
                 }
             }
         }
     }
 }
Ejemplo n.º 27
0
        private CouponsInfoViewModel EtoV(CouponsInfo entity)
        {
            CouponsInfoViewModel viewmodel = entity.Convert <CouponsInfo, CouponsInfoViewModel>((en, vm) =>
            {
                vm.Title = entity.Title.Content;
            });

            if (entity.WebChannel != null)
            {
                viewmodel.WebChannel = new Basic.Components.Models.WebChannelVM()
                {
                    ChannelID = entity.WebChannel.ChannelID, ChannelName = entity.WebChannel.ChannelName
                };
            }
            else
            {
                viewmodel.WebChannel = viewmodel.WebChennelList[0];
            }

            #region 商品条件处理
            if (viewmodel.ProductCondition != null)
            {
                if (viewmodel.ProductCondition.RelBrands != null && viewmodel.ProductCondition.RelBrands.BrandList != null)
                {
                    viewmodel.ProductCondition.RelBrands.IsExcludeRelation = !viewmodel.ProductCondition.RelBrands.IsIncludeRelation;
                    foreach (SimpleObjectViewModel sim in viewmodel.ProductCondition.RelBrands.BrandList)
                    {
                        sim.Relation  = viewmodel.ProductCondition.RelBrands.IsIncludeRelation.Value ? PSRelationType.Include : PSRelationType.Exclude;
                        sim.IsChecked = false;
                    }
                }
                else
                {
                    if (viewmodel.ProductCondition.RelBrands == null)
                    {
                        viewmodel.ProductCondition.RelBrands = new RelBrandViewModel();
                    }
                    viewmodel.ProductCondition.RelBrands.IsIncludeRelation = true;
                    viewmodel.ProductCondition.RelBrands.IsExcludeRelation = false;
                }

                if (viewmodel.ProductCondition.RelCategories != null && viewmodel.ProductCondition.RelCategories.CategoryList != null)
                {
                    viewmodel.ProductCondition.RelCategories.IsExcludeRelation = !viewmodel.ProductCondition.RelCategories.IsIncludeRelation;
                    foreach (SimpleObjectViewModel sim in viewmodel.ProductCondition.RelCategories.CategoryList)
                    {
                        sim.Relation  = viewmodel.ProductCondition.RelCategories.IsIncludeRelation.Value ? PSRelationType.Include : PSRelationType.Exclude;;
                        sim.IsChecked = false;
                    }
                }
                else
                {
                    if (viewmodel.ProductCondition.RelCategories == null)
                    {
                        viewmodel.ProductCondition.RelCategories = new RelCategory3ViewModel();
                    }
                    viewmodel.ProductCondition.RelCategories.IsIncludeRelation = true;
                    viewmodel.ProductCondition.RelCategories.IsExcludeRelation = false;
                }

                if (viewmodel.ProductCondition.RelProducts != null && viewmodel.ProductCondition.RelProducts.ProductList != null)
                {
                    foreach (RelProductAndQtyViewModel sim in viewmodel.ProductCondition.RelProducts.ProductList)
                    {
                        sim.IsChecked = false;
                    }
                }
                else
                {
                    if (viewmodel.ProductCondition.RelProducts == null)
                    {
                        viewmodel.ProductCondition.RelProducts = new RelProductViewModel();
                    }
                    viewmodel.ProductCondition.RelProducts.IsIncludeRelation = true;
                    viewmodel.ProductCondition.RelProducts.IsExcludeRelation = false;
                }
                if (viewmodel.ProductCondition.ListRelVendorViewModel == null)
                {
                    viewmodel.ProductCondition.ListRelVendorViewModel = new List <RelVendorViewModel>();
                }
                if (entity.ProductCondition.ListRelVendor != null)
                {
                    foreach (var item in entity.ProductCondition.ListRelVendor)
                    {
                        viewmodel.ProductCondition.ListRelVendorViewModel.Add(new RelVendorViewModel()
                        {
                            CouponsStatus = entity.Status,
                            VendorSysNo   = item.VendorSysNo,
                            VendorName    = item.VendorName,
                            IsChecked     = false
                        });
                    }
                }
            }
            else
            {
                viewmodel.ProductCondition           = new PSProductConditionViewModel();
                viewmodel.ProductCondition.RelBrands = new RelBrandViewModel();
                viewmodel.ProductCondition.RelBrands.IsIncludeRelation = true;
                viewmodel.ProductCondition.RelCategories = new RelCategory3ViewModel();
                viewmodel.ProductCondition.RelCategories.IsIncludeRelation = true;
                viewmodel.ProductCondition.RelProducts = new RelProductViewModel();
                viewmodel.ProductCondition.RelProducts.IsIncludeRelation = true;
            }
            #endregion

            #region 客户条件处理

            /*
             * 说明:由于原数据库设计变态,因此为了保证原来的兼容性,所以这里转换比较复杂
             * (1)如果限定类型是“无限定”,是插入了一条用户组的SysNo为-1记录到Coupon_SaleRules表:Type=R, CustomerRank=-1。
             * (2)如果限定类型是限定用户组,那么插入CustomerRank的SysNo记录到Coupon_SaleRules表:Type=R, CustomerRank=SysNo。
             * (3)如果限定类型是自选用户,那么插入Customer SysNo数据到Coupon_SaleRulesCustomer表。
             *      对于上述三种情况,转换到ViewModel中时,
             *      情况(1)则viewmodel.IsCustomerNoLimit = true,并且清空RelCustomerRanks.CustomerRankList
             *      但是在VtoE时,记得需要将viewmodel.IsCustomerNoLimit转换为CustomerRank=-1 的RelCustomerRanks.CustomerRankList一条记录
             *
             * (4)如果再限定用户地区,那么插入地区的SysNo到Coupon_SaleRules表:Type=A, AreaSysNo=SysNo
             * */
            if (viewmodel.CustomerCondition == null)
            {
                viewmodel.CustomerCondition                        = new PSCustomerConditionViewModel();
                viewmodel.CustomerCondition.RelAreas               = new RelAreaViewModel();
                viewmodel.CustomerCondition.RelCustomerRanks       = new RelCustomerRankViewModel();
                viewmodel.CustomerCondition.RelCustomers           = new RelCustomerViewModel();
                viewmodel.CustomerCondition.NeedEmailVerification  = false;
                viewmodel.CustomerCondition.NeedMobileVerification = false;
                viewmodel.CustomerCondition.InvalidForAmbassador   = false;
            }
            else
            {
                if (!viewmodel.CustomerCondition.NeedEmailVerification.HasValue)
                {
                    viewmodel.CustomerCondition.NeedEmailVerification = false;
                }
                if (!viewmodel.CustomerCondition.NeedMobileVerification.HasValue)
                {
                    viewmodel.CustomerCondition.NeedMobileVerification = false;
                }
                if (!viewmodel.CustomerCondition.InvalidForAmbassador.HasValue)
                {
                    viewmodel.CustomerCondition.InvalidForAmbassador = false;
                }

                if (viewmodel.CustomerCondition.RelAreas != null && viewmodel.CustomerCondition.RelAreas.AreaList != null)
                {
                    foreach (SimpleObjectViewModel sim in viewmodel.CustomerCondition.RelAreas.AreaList)
                    {
                        sim.IsChecked = false;
                    }
                    if (viewmodel.CustomerCondition.RelAreas.AreaList.Count > 0)
                    {
                        viewmodel.IsAreaLimit   = true;
                        viewmodel.IsAreaNoLimit = false;
                    }
                }
                else
                {
                    viewmodel.CustomerCondition.RelAreas = new RelAreaViewModel();
                }

                if (viewmodel.CustomerCondition.RelCustomerRanks != null && viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList != null)
                {
                    foreach (SimpleObjectViewModel sim in viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList)
                    {
                        sim.IsChecked = false;
                        CustomerRank cr = (CustomerRank)Enum.Parse(typeof(CustomerRank), sim.SysNo.Value.ToString(), true);
                        sim.Name = EnumConverter.GetDescription(cr);
                    }

                    if (viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList.Count > 0)
                    {
                        if (viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList.Count == 1 &&
                            viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList[0].SysNo == -1)
                        {
                            viewmodel.IsCustomerRank    = false;
                            viewmodel.IsCustomerID      = false;
                            viewmodel.IsCustomerNoLimit = true;
                            viewmodel.CustomerCondition.RelCustomerRanks.CustomerRankList.Clear();
                        }
                        else
                        {
                            viewmodel.IsCustomerRank    = true;
                            viewmodel.IsCustomerID      = false;
                            viewmodel.IsCustomerNoLimit = false;
                        }
                    }
                }
                else
                {
                    viewmodel.CustomerCondition.RelCustomerRanks = new RelCustomerRankViewModel();
                }

                if (viewmodel.CustomerCondition.RelCustomers != null && viewmodel.CustomerCondition.RelCustomers.CustomerIDList != null)
                {
                    foreach (CustomerAndSendViewModel sim in viewmodel.CustomerCondition.RelCustomers.CustomerIDList)
                    {
                        sim.IsChecked = false;
                    }
                    if (viewmodel.CustomerCondition.RelCustomers.CustomerIDList.Count > 0)
                    {
                        viewmodel.IsCustomerRank    = false;
                        viewmodel.IsCustomerID      = true;
                        viewmodel.IsCustomerNoLimit = false;
                    }
                }
                else
                {
                    viewmodel.CustomerCondition.RelCustomers = new RelCustomerViewModel();
                }
            }

            #endregion

            if (viewmodel.OrderAmountDiscountRule == null)
            {
                viewmodel.OrderAmountDiscountRule = new PSOrderAmountDiscountRuleViewModel();
            }
            else
            {
                if (viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank != null &&
                    viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank.Count > 0)
                {
                    //foreach (OrderAmountDiscountRankViewModel rank in viewmodel.OrderAmountDiscountRule.OrderAmountDiscountRank)
                    //{
                    //    if (rank.DiscountType.Value == PSDiscountTypeForOrderAmount.OrderAmountPercentage)
                    //    {
                    //        rank.DiscountValue = rank.DiscountValue.Value * 100;
                    //    }
                    //}
                }
            }

            if (viewmodel.OrderCondition == null)
            {
                viewmodel.OrderCondition = new PSOrderConditionViewModel();
            }
            //SHIPTYPE ,PAYTYPE 转换
            if (viewmodel.OrderCondition != null &&
                viewmodel.OrderCondition.ShippingTypeSysNoList != null &&
                viewmodel.OrderCondition.ShippingTypeSysNoList.Count > 0)
            {
                viewmodel.ShipTypeSysNo = entity.OrderCondition.ShippingTypeSysNoList[0];
            }

            if (viewmodel.OrderCondition != null &&
                viewmodel.OrderCondition.PayTypeSysNoList != null &&
                viewmodel.OrderCondition.PayTypeSysNoList.Count > 0)
            {
                viewmodel.PayTypeSysNo = entity.OrderCondition.PayTypeSysNoList[0];
            }

            if (viewmodel.BindCondition == null)
            {
                viewmodel.BindCondition = CouponsBindConditionType.None;
            }

            if (viewmodel.ValidPeriod == null)
            {
                viewmodel.ValidPeriod = CouponsValidPeriodType.All;
            }

            if (viewmodel.UsingFrequencyCondition == null)
            {
                viewmodel.UsingFrequencyCondition = new PSActivityFrequencyConditionViewModel();
            }

            if (!viewmodel.IsAutoBinding.HasValue)
            {
                viewmodel.IsAutoBinding = false;
            }
            if (!viewmodel.IsAutoUse.HasValue)
            {
                viewmodel.IsAutoUse = false;
            }
            if (!viewmodel.IsExistThrowInTypeCouponCode.HasValue)
            {
                viewmodel.IsExistThrowInTypeCouponCode = false;
            }
            if (!viewmodel.IsSendMail.HasValue)
            {
                viewmodel.IsSendMail = false;
            }

            if (viewmodel.BindRule == null)
            {
                viewmodel.BindRule = new CouponBindRuleViewModel();
            }

            if (viewmodel.BindRule.RelProducts == null)
            {
                viewmodel.BindRule.RelProducts = new RelProductViewModel();
            }
            //viewmodel.BindRule = new CouponBindRuleViewModel();
            //viewmodel.BindRule.RelProducts = new RelProductViewModel();
            //if (entity.BindCondition == CouponsBindConditionType.SO)
            //{
            //    if (entity.BindRule != null)
            //    {
            //        viewmodel.BindRule.AmountLimit = entity.BindRule.AmountLimit;
            //        if (entity.BindRule.RelProducts != null)
            //        {
            //            viewmodel.BindRule.RelProducts.IsIncludeRelation = entity.BindRule.RelProducts.IsIncludeRelation;
            //            viewmodel.BindRule.RelProducts.IsExcludeRelation = !entity.BindRule.RelProducts.IsIncludeRelation;
            //            if (entity.BindRule.RelProducts.ProductList != null && entity.BindRule.RelProducts.ProductList.Count > 0)
            //            {
            //                viewmodel.BindRule.RelProducts.ProductList = new List<RelProductAndQty>();
            //                foreach (var itemViewModel in entity.BindRule.RelProducts.ProductList)
            //                {
            //                    RelProductAndQtyViewModel item = new RelProductAndQtyViewModel();
            //                    item.ProductSysNo = itemViewModel.ProductSysNo;
            //                    item.MinQty = itemViewModel.MinQty;

            //                    item.ProductID = itemViewModel.ProductID;
            //                    item.ProductName = itemViewModel.ProductName;
            //                    item.AvailableQty = itemViewModel.AvailableQty;
            //                    item.ConsignQty = itemViewModel.ConsignQty;
            //                    item.VirtualQty = itemViewModel.VirtualQty;
            //                    item.UnitCost = itemViewModel.UnitCost;
            //                    item.CurrentPrice = itemViewModel.CurrentPrice;
            //                    item.GrossMarginRate = itemViewModel.GrossMarginRate;
            //                    item.Priority = itemViewModel.Priority;
            //                    item.ProductRangeType = itemViewModel.ProductRangeType;
            //                    viewmodel.BindRule.RelProducts.ProductList.Add(item);
            //                }
            //            }
            //        }
            //    }

            //}
            return(viewmodel);
        }