Esempio n. 1
0
        public static Coupon Create(Coupon info)
        {
            if (info != null)
            {
                SetCoupon(info);
                CheckCoupon(info);
                using (ECommerce.Utility.ITransaction tran = ECommerce.Utility.TransactionManager.Create())
                {
                    //活动基本信息
                    info.SysNo = CouponDA.CreateMaster(info);

                    //折扣方式
                    CouponDA.AddDiscountRule(info);

                    //使用范围
                    CouponDA.SetCouponSaleRule(info);
                    CouponDA.AddSeleRulesProductCondition(info);
                    CouponDA.AddCustomerCondition(info);
                    //获取方式
                    CouponDA.SetCouponBindRules(info);
                    CouponDA.AddBindRulesProductCondition(info);

                    //优惠券
                    if (info.SysNo.HasValue && info.BindRule != null && info.BindRule.BindCondition == CouponsBindConditionType.None)
                    {
                        if (info.GeneralCode != null && (!string.IsNullOrWhiteSpace(info.GeneralCode.Code)))
                        {
                            if (CouponDA.CheckExistCode(info.GeneralCode.Code, info.SysNo))
                            {
                                throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("优惠券代码已存在"));
                            }
                            info.GeneralCode.CouponSysNo = info.SysNo.Value;
                            CouponDA.CreateCouponCode(info.GeneralCode, info.InUser);
                        }
                        else if (!string.IsNullOrWhiteSpace(info.ThrowInCodes))
                        {
                            string couponCodeXml = GetCouponCodeXml(info.ThrowInCodes);
                            if (couponCodeXml != null)
                            {
                                info.GeneralCode.CouponSysNo = info.SysNo.Value;
                                CouponDA.BatchCreateCouponCode(couponCodeXml, info, info.InUser);
                            }
                        }
                    }
                    tran.Complete();
                }
                if (info.SysNo.HasValue)
                {
                    info = CouponDA.Load(info.SysNo);
                }
            }
            return(info);
        }
Esempio n. 2
0
        public static Coupon Update(Coupon info)
        {
            if (info != null && info.SysNo.HasValue)
            {
                CouponStatus status = CouponDA.GetCouponStatus(info.SysNo.Value);
                if (status != CouponStatus.Init)
                {
                    throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("只有初始态的活动才能保存或发布"));
                }
                SetCoupon(info);
                CheckCoupon(info);
                using (ECommerce.Utility.ITransaction tran = ECommerce.Utility.TransactionManager.Create())
                {
                    //活动基本信息
                    CouponDA.UpdateMaster(info);

                    //折扣方式
                    CouponDA.DeleteDiscountRule(info.SysNo);
                    CouponDA.AddDiscountRule(info);

                    //使用范围
                    CouponDA.SetCouponSaleRule(info);
                    CouponDA.DeleteSeleRulesProductCondition(info.SysNo);
                    CouponDA.AddSeleRulesProductCondition(info);
                    CouponDA.DeleteSeleRulesCustomerCondition(info.SysNo);
                    CouponDA.AddCustomerCondition(info);
                    //获取方式
                    CouponDA.SetCouponBindRules(info);
                    CouponDA.DeleteBindRulesProductCondition(info.SysNo);
                    CouponDA.AddBindRulesProductCondition(info);

                    //优惠券
                    CouponDA.DelAllCouponCode(info.SysNo);
                    //优惠券
                    if (info.SysNo.HasValue && info.BindRule != null && info.BindRule.BindCondition == CouponsBindConditionType.None)
                    {
                        if (info.GeneralCode != null && (!string.IsNullOrWhiteSpace(info.GeneralCode.Code)))
                        {
                            if (CouponDA.CheckExistCode(info.GeneralCode.Code, info.SysNo))
                            {
                                throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("优惠券代码已存在"));
                            }
                            info.GeneralCode.CouponSysNo = info.SysNo.Value;
                            CouponDA.CreateCouponCode(info.GeneralCode, info.EditUser);
                        }
                        else if (!string.IsNullOrWhiteSpace(info.ThrowInCodes))
                        {
                            string couponCodeXml = GetCouponCodeXml(info.ThrowInCodes);
                            if (couponCodeXml != null)
                            {
                                CouponDA.BatchCreateCouponCode(couponCodeXml, info, info.InUser);
                            }
                        }
                    }

                    //if (info.CouponCodes != null && info.CouponCodes.Count > 0)
                    //{
                    //    foreach (CouponCode code in info.CouponCodes)
                    //    {
                    //        if (CouponDA.CheckExistCode(code.Code))
                    //        {
                    //            throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("优惠券代码已存在"));
                    //        }
                    //        CouponDA.CreateCouponCode(code, info.InUser);
                    //    }
                    //}
                    tran.Complete();
                }
            }
            return(info);
        }