public static string GenerateRandomCode(int length) { Thread.Sleep(10); const string template = "234679ACDEFGHJKLMNPQRTUVWXYZ"; int success = 0; Random random = new Random(); random.Next(); string CouponCode = string.Empty; while (success == 0) { StringBuilder builder = new StringBuilder(); int maxRandom = template.Length - 1; for (int i = 0; i < length; i++) { builder.Append(template[random.Next(maxRandom)]); } CouponCode = builder.ToString(); if (!CouponDA.CheckExistCode(CouponCode, null)) { success = 1; } } return(CouponCode); }
private static void ProcessEachForRigister(Coupon master) { //获取注册未发放优惠券的顾客 (实时发)5分钟一次,造优惠券,发给顾客 string userType = "R"; List <Customer> customerList = CouponDA.GetRegisterUser(userType, master);//获取注册未发放优惠券的顾客 if (customerList == null || customerList.Count <= 0) { WriteLog("没能查询到符合条件的用户"); return; } WriteLog("查询到新注册的用户" + customerList.Count + "个"); master.BindStatus = "S";//字段 CouponDA.UpdateBindRulesStatus(master); int num = 0; string userList = string.Empty; foreach (Customer customer in customerList) { #region CreateCode CouponCode codeEntity = new CouponCode(); codeEntity.CouponSysNo = master.SysNo; codeEntity.CodeType = "C"; codeEntity.CustomerMaxFrequency = 1; GetCodeExpireDate(master, codeEntity); codeEntity = CouponDA.CreateCode(codeEntity); #endregion CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = codeEntity.Code; logEntity.CouponSysNo = master.SysNo; logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); #region sendMail MailEntity customerMail = new MailEntity(); customerMail.MailSubject = master.CouponName; if (!string.IsNullOrEmpty(customer.MailAddress) && master.IsSendMail == "Y") { customerMail.MailBody = ConstValues.MailTemplate.Replace("@InDate", DateTime.Now.ToString("yyyy-MM-dd")) .Replace("@CustomerHello@", customer.CustomerID) .Replace("@CouponCode@", codeEntity.Code) .Replace("@nums@", "1") .Replace("@EndDateStr@", codeEntity.EndDate.ToString("yyyy-MM-dd")); customerMail.MailAddress = customer.MailAddress; CouponDA.SendMailInfo(customerMail); } #endregion num++; userList += "顾客编号:" + customer.CustomerSysNo + ",顾客ID:" + customer.CustomerID + "\r\n"; } WriteLog(DateTime.Now + "注册送优惠券成功发送" + num + "个顾客,分别是:\r\n" + userList); }
private static void ProcessEachForTBVip_Old(Coupon master) { string userType = "Z"; //触发条件 master.BindStatus = "S"; //发放状态 List <Customer> customerList = CouponDA.GetAlipayCustomer(userType, master);//获取未发放优惠券的顾客 WriteLog("获取用户数" + customerList.Count + "个"); if (customerList.Count <= 0) { WriteLog("没有找到符合条件的支付宝金账户"); } else { using (TransactionScope ts = new TransactionScope()) { string message = string.Format("({0}){1} -- ", master.SysNo, master.CouponName); //通用型优惠券代码 CouponCode code = CouponDA.QueryBindingCode(master); CouponDA.UpdateBindRulesStatus(master); int index = 0; string userList = string.Empty; CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = code.Code; logEntity.CouponSysNo = master.SysNo; MailEntity customerMail = new MailEntity(); customerMail.MailSubject = master.CouponName; foreach (Customer customer in customerList) { logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); if (!string.IsNullOrEmpty(customer.MailAddress) && master.IsSendMail == "Y") { customerMail.MailBody = ConstValues.MailTemplate.Replace("@Title@", master.CouponName) .Replace("@CustomerHello@", "您好,感谢您对大昌优品的支持。") .Replace("@CouponCode@", code.Code) .Replace("@nums@", code.CustomerMaxFrequency.ToString()) .Replace("@EndDateStr@", code.EndDate.ToString("yyyy-MM-dd")); customerMail.MailAddress = customer.MailAddress; CouponDA.SendMailInfo(customerMail); } ++index; userList += "顾客编号:" + customer.CustomerSysNo + ",顾客ID:" + customer.CustomerID + "\r\n"; } WriteLog(DateTime.Now + "支付宝金账户优惠券成功发送" + index + "个顾客,分别是:\r\n" + userList); ts.Complete(); } } }
/// <summary> /// 支付宝金账户发放优惠券 /// </summary> /// <param name="item"></param> private static void ProcessEachForTBVip(Coupon master) { string userType = "Z"; //触发条件 master.BindStatus = "S"; //发放状态 List <Customer> customerList = null; customerList = CouponDA.GetAlipayCustomer(userType, master);//获取未发放优惠券的顾客 if (customerList.Count <= 0) { WriteLog("没有找到符合条件的支付宝金账户"); return; } //更新绑定状态为S CouponDA.UpdateBindRulesStatus(master); int num = 0; string userList = string.Empty; foreach (Customer customer in customerList) { #region CreateCode CouponCode codeEntity = new CouponCode(); codeEntity.CouponSysNo = master.SysNo; GetCodeExpireDate(master, codeEntity); codeEntity = CouponDA.CreateCode(codeEntity); #endregion CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = codeEntity.Code; logEntity.CouponSysNo = master.SysNo; logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); #region sendMail MailEntity customerMail = new MailEntity(); customerMail.MailSubject = master.CouponName; if (!string.IsNullOrEmpty(customer.MailAddress) && master.IsSendMail == "Y") { customerMail.MailBody = ConstValues.MailTemplate.Replace("@InDate", DateTime.Now.ToString("yyyy-MM-dd")) .Replace("@CustomerHello@", customer.CustomerID) .Replace("@CouponCode@", codeEntity.Code) .Replace("@nums@", "1") .Replace("@EndDateStr@", codeEntity.EndDate.ToString("yyyy-MM-dd")); customerMail.MailAddress = customer.MailAddress; CouponDA.SendMailInfo(customerMail); } #endregion num++; userList += "顾客编号:" + customer.CustomerSysNo + ",顾客ID:" + customer.CustomerID + "\r\n"; } WriteLog(DateTime.Now + "支付宝金账户送优惠券成功发送" + num + "个顾客,分别是:\r\n" + userList); }
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); }
public static void StopCoupon(int couponSysNo, int merchantSysNo, string userName) { if (couponSysNo > 0 && merchantSysNo > 0) { if (merchantSysNo != CouponDA.GetCouponMerchantSysNo(couponSysNo)) { throw new BusinessException(LanguageHelper.GetText("您没有权限操作该数据")); } } if (CouponDA.GetCouponStatus(couponSysNo) == CouponStatus.Run) { CouponDA.UpdateStatus(couponSysNo, CouponStatus.Stoped, userName); } else { throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("只有运行状态的活动才能终止!")); } }
public static void PCodeForSpecialUser(Coupon master, CouponCode code, List <Customer> customerList) { // 自选用户 string userType = "S"; master.BindStatus = "E";//字段 CouponDA.UpdateBindRulesStatus(master); int index = 0; string userList = string.Empty; CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = code.Code; logEntity.CouponSysNo = master.SysNo; MailEntity customerMail = new MailEntity(); customerMail.MailSubject = master.CouponName; foreach (Customer customer in customerList) { logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); //if (!string.IsNullOrEmpty(customer.MailAddress) && master.IsSendMail == "Y") //{ // customerMail.MailBody = ConstValues.MailTemplate.Replace("@InDate", DateTime.Now.ToString("yyyy-MM-dd")) // .Replace("@CustomerHello@", customer.CustomerID) // .Replace("@CouponCode@", code.Code) // .Replace("@nums@", code.CustomerMaxFrequency.ToString()) // .Replace("@EndDateStr@", code.EndDate.ToString("yyyy-MM-dd")); // customerMail.MailAddress = customer.MailAddress; // CouponDA.SendMailInfo(customerMail); //} ++index; userList += "顾客编号:" + customer.CustomerSysNo + ",顾客ID:" + customer.CustomerID + "\r\n"; } CouponDA.UpdateCouponSaleRulesCustomerStatus(master);//自选用户标识已发放 WriteLog(DateTime.Now + "自选用户优惠券成功发送" + index + "个顾客,分别是:\r\n" + userList); }
public static void VoidCoupon(int couponSysNo, int merchantSysNo, string userName) { if (couponSysNo > 0 && merchantSysNo > 0) { if (merchantSysNo != CouponDA.GetCouponMerchantSysNo(couponSysNo)) { throw new BusinessException(LanguageHelper.GetText("您没有权限操作该数据")); } } CouponStatus status = CouponDA.GetCouponStatus(couponSysNo); if (status == CouponStatus.Init || status == CouponStatus.Ready || status == CouponStatus.WaitingAudit) { CouponDA.UpdateStatus(couponSysNo, CouponStatus.Void, userName); } else { throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("只有初始态、待审核、就绪状态的活动才能作废!")); } }
private static void ProcessEachForSpecial(Coupon master, List <Customer> customerList) { if (customerList == null || customerList.Count <= 0) { WriteLog("没能查询到符合条件的用户"); return; } using (TransactionScope ts = new TransactionScope()) { string message = string.Format("({0}){1} -- ", master.SysNo, master.CouponName); CouponCode code = null; //通用型优惠券代码 只有一条记录 code = CouponDA.QueryBindingCode(master); if (code != null && code.TotalCount > 0) { int availCustomerCount = 0; if (code.CustomerMaxFrequency != 0 && code.TotalCount != 0) { availCustomerCount = code.TotalCount / code.CustomerMaxFrequency; } if (availCustomerCount == 0 || availCustomerCount < code.CustomerMaxFrequency) { message += string.Format("(通用型)优惠券不够发放({0})只够发放{1}个客户,需要发放{2}个客户。" , code.Code, availCustomerCount, customerList.Count); } } WriteLog(message); //发放特殊用户的优惠券,直接发放到用户中心 PCodeForSpecialUser(master, code, customerList); ts.Complete(); } }
public static QueryResult QueryCouponCodeRedeemLog(CouponCodeRedeemLogFilter filter) { return(CouponDA.QueryCouponCodeRedeemLog(filter)); }
public static void Process() { int isTestZ = Convert.ToInt32(ConfigurationSettings.AppSettings["IsTestZ"].ToString()); int isTestS = Convert.ToInt32(ConfigurationSettings.AppSettings["IsTestS"].ToString()); int isTestR = Convert.ToInt32(ConfigurationSettings.AppSettings["IsTestR"].ToString()); int isTestB = Convert.ToInt32(ConfigurationSettings.AppSettings["IsTestB"].ToString()); int IsTestO = Convert.ToInt32(ConfigurationSettings.AppSettings["IsTestO"].ToString()); // int notInclude = Convert.ToInt32(ConfigurationSettings.AppSettings["NotInclude"].ToString()); try { List <Coupon> coupons = CouponDA.GetAvailableCoupon(); WriteLog(DateTime.Now + "查询到优惠券活动" + coupons.Count + "条"); foreach (Coupon item in coupons) { string date = DateTime.Now.ToString("yyyy-MM-dd"); //A不限 R 注册 B 生日 Z 支付宝金账户 O购物送优惠卷 //获取自选用户列表 List <Customer> customerList = CouponDA.GetLimitCustomerForSpecial(item); #region if (customerList != null && customerList.Count > 0 && item.BindCondition == "A" && ((item.IsAutoBinding == "Y" && item.BindingDate.ToString("yyyy-MM-dd") == date) || item.IsAutoBinding == "N") && isTestS == 1) //自选年用户送优惠券 { WriteLog(DateTime.Now + "为自选用户发放优惠券:" + item.CouponName); ProcessEachForSpecial(item, customerList); } else if (item.BindCondition == "R" && ((item.IsAutoBinding == "Y" && item.BindingDate.ToString("yyyy-MM-dd") == date) || item.IsAutoBinding == "N") && isTestR == 1)//注册送优惠券 { WriteLog(string.Format("{0}为注册用户发放优惠券:{1} {2}", DateTime.Now, item.SysNo, item.CouponName)); ProcessEachForRigister(item); } else if (item.BindCondition == "B" && ((item.IsAutoBinding == "Y" && item.BindingDate.ToString("yyyy-MM-dd") == date) || item.IsAutoBinding == "N") && isTestB == 1)//生日送优惠券 { WriteLog(string.Format("{0}为生日用户发放优惠券:{1} {2}", DateTime.Now, item.SysNo, item.CouponName)); ProcessEachForBirthday(item); } else if (item.BindCondition == "Z" && ((item.IsAutoBinding == "Y" && item.BindingDate.ToString("yyyy-MM-dd") == date) || item.IsAutoBinding == "N") && isTestZ == 1)//支付宝金账户优惠券 { WriteLog(string.Format("{0}-(新)为支付宝金账户用户发放优惠券:{1} {2}", DateTime.Now, item.SysNo, item.CouponName)); ProcessEachForTBVip(item); } #endregion else if (item.BindCondition == "O" && ((item.IsAutoBinding == "Y" && item.BindingDate.ToString("yyyy-MM-dd") == date) || item.IsAutoBinding == "N") && IsTestO == 1)//购物送优惠卷 { WriteLog(string.Format("{0}-为购物账户用户发放优惠券:{1} {2}", DateTime.Now, item.SysNo, item.CouponName)); ProcessEachForSO(item); } } if (isTestZ == 1)//支付宝金账户优惠券 { List <Coupon> aliPayCoupons = CouponDA.GetAliPayCoupon(); foreach (Coupon aliItem in aliPayCoupons) { WriteLog(string.Format("{0}-(旧)为支付宝金账户用户发放优惠券:{1} {2}", DateTime.Now, aliItem.SysNo, aliItem.CouponName)); ProcessEachForTBVip_Old(aliItem); } } } catch (Exception ex) { WriteLog("异常信息:" + ex.Message); } WriteLog(DateTime.Now + "优惠券发放结束。"); }
public static QueryResult QueryCouponCodeCustomerLog(CouponCodeCustomerLogFilter filter) { return(CouponDA.QueryCouponCodeCustomerLog(filter)); }
public static QueryResult QueryCouponList(CouponQueryFilter queryFilter) { return(CouponDA.QueryCouponList(queryFilter)); }
private static void ProcessEachForBirthday(Coupon master) { //获取要过生日未发放生日优惠券的顾客 (一天发一次)造优惠券,发给顾客 string userType = "B"; List <Customer> customerList = CouponDA.GetBirthdayUser(master.SysNo);//获取要过生日未发放生日优惠券的顾客 if (customerList == null || customerList.Count <= 0) { WriteLog("没能查询到符合条件的用户"); return; } WriteLog("查询到今天过生日的用户" + customerList.Count + "个"); master.BindStatus = "S";//字段 CouponDA.UpdateBindRulesStatus(master); int num = 0; string userList = string.Empty; foreach (Customer customer in customerList) { #region CreateCode CouponCode codeEntity = new CouponCode(); codeEntity.CouponSysNo = master.SysNo; codeEntity.CodeType = "T"; codeEntity.CustomerMaxFrequency = 1; GetCodeExpireDate(master, codeEntity); codeEntity = CouponDA.CreateCode(codeEntity); #endregion CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = codeEntity.Code; logEntity.CouponSysNo = master.SysNo; logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); #region sendMail MailEntity customerMail = new MailEntity(); customerMail.MailSubject = string.Format("亲爱的{0},生日将际,大昌优品为你送上一份生日礼物", customer.CustomerID);//master.CouponName; if (!string.IsNullOrEmpty(customer.MailAddress) && master.IsSendMail == "Y") { int _num = 1; StringBuilder result = new StringBuilder(); IList <ProductTop6Entity> product = CouponDA.GetProductTop6(); result.Append(ConstValues.BirthdayMailTemplate.Replace("@CustomerHello@", customer.CustomerID)); foreach (ProductTop6Entity item in product) { result.Replace(String.Format("@ProductImage{0}@", _num), String.Format(imageText, item.DefaultImage)); result.Replace(String.Format("@ProductTitle{0}@", _num), item.ProductTitle); result.Replace(String.Format("@ProductUrl{0}@", _num), String.Format(produceUrl, item.ProductID, DateTime.Now.ToString("yyyyMMdd"))); result.Replace(String.Format("@ProductPrice{0}@", _num), item.CurrentPrice.ToString("0.00")); _num += 1; } result.Replace("@DateTime@", DateTime.Now.ToString("yyyy.MM.dd")); result.Replace("@Birthday@", DateTime.Now.ToString("yyyyMMdd")); customerMail.MailBody = result.ToString(); customerMail.MailAddress = customer.MailAddress; CouponDA.SendMailInfo(customerMail); } #endregion num++; userList += "顾客编号:" + customer.CustomerSysNo + ",顾客ID:" + customer.CustomerID + "\r\n"; } WriteLog(DateTime.Now + "生日送优惠券成功发送" + num + "个顾客,分别是:\r\n" + userList); }
public static void CheckCoupon(Coupon info) { if (info != null) { if (info.SysNo.HasValue && info.MerchantSysNo > 0) { if (info.MerchantSysNo != CouponDA.GetCouponMerchantSysNo(info.SysNo.Value)) { throw new BusinessException(LanguageHelper.GetText("您没有权限操作该数据")); } } if (!info.BeginDate.HasValue) { throw new BusinessException(LanguageHelper.GetText("开始时间不能为空")); } if (!info.EndDate.HasValue) { throw new BusinessException(LanguageHelper.GetText("结束时间不能为空")); } if (info.EndDate < DateTime.Now.Date) { throw new BusinessException(LanguageHelper.GetText("结束时间必须大于当前时间")); } if (info.BeginDate >= info.EndDate) { throw new BusinessException(LanguageHelper.GetText("开始时间必须小于结束时间")); } if (info.DiscountRules == null || info.DiscountRules.Count < 1) { throw new BusinessException(LanguageHelper.GetText("折扣方式不能为空")); } if (info.BindRule != null) { if (info.BindRule != null && info.BindRule.BindCondition == CouponsBindConditionType.None) { if ((info.GeneralCode == null || string.IsNullOrEmpty(info.GeneralCode.Code)) && string.IsNullOrWhiteSpace(info.ThrowInCodes)) { throw new BusinessException(LanguageHelper.GetText("触发条件不限的优惠券活动必须生成优惠券代码")); } if (!string.IsNullOrWhiteSpace(info.GeneralCode.Code) && CouponDA.CheckExistCode(info.GeneralCode.Code, info.SysNo)) { throw new ECommerce.Utility.BusinessException(LanguageHelper.GetText("优惠券代码已存在")); } } //泰隆暂时不提供此活动 if (info.BindRule.BindCondition == CouponsBindConditionType.SO && info.BindRule.ProductRange.ProductRangeType == ProductRangeType.Limit) { if (info.BindRule.ProductRange.Products == null || info.BindRule.ProductRange.Products.Count < 1) { throw new BusinessException(LanguageHelper.GetText("优惠券获取方式限制商品列表不能为空")); } } if (info.BindRule.BindCondition == CouponsBindConditionType.SO) { if (info.SaleRule.CustomerRange.Customers == null || info.SaleRule.CustomerRange.Customers.Count < 1) { throw new BusinessException(LanguageHelper.GetText("优惠券使用规则顾客范围列表不能为空")); } } if (info.BindRule.ValidPeriod == CouponValidPeriodType.CustomPeriod) { if ((!info.BindRule.BindBeginDate.HasValue) || (!info.BindRule.BindEndDate.HasValue)) { throw new BusinessException(LanguageHelper.GetText("自定义优惠券有效期起止时间不能为空")); } } } if (info.SaleRule != null && info.SaleRule.ProductRange.ProductRangeType == ProductRangeType.Limit) { if (info.SaleRule.ProductRange.Products == null || info.SaleRule.ProductRange.Products.Count < 1) { throw new BusinessException(LanguageHelper.GetText("优惠券使用范围限制商品列表不能为空")); } } if (info.SaleRule != null && info.SaleRule.CustomerRange.CustomerRangeType == CouponCustomerRangeType.Limit) { if (info.SaleRule.CustomerRange.Customers == null || info.SaleRule.CustomerRange.Customers.Count < 1) { throw new BusinessException(LanguageHelper.GetText("优惠券使用范围限制顾客列表不能为空")); } } } else { throw new BusinessException(LanguageHelper.GetText("优惠券活动信息不能为空")); } }
public static QueryResult <CouponCode> QueryCouponCodeList(CouponCodeQueryFilter queryFilter) { return(CouponDA.QueryCouponCodeList(queryFilter)); }
public static void UpdateStatus(int couponSysNo, CouponStatus status, string userName) { CouponDA.UpdateStatus(couponSysNo, status, userName); }
public static Coupon Load(int?sysNo) { return(CouponDA.Load(sysNo)); }
private static void ProcessEachForSO(Coupon master) { string userType = "O"; List <Customer> customernewList = new List <Customer>(); List <Customer> customerCheckList = new List <Customer>(); //(所有商品)LimitType = "A"; if (master.LimitType == "A") { //根据商家SysNo获取符合条件的订单信息和顾客信息 customernewList = CouponDA.GetCustomerAndSO(master); } //(限定商品)LimitType = "I"; if (master.LimitType == "I") { //限定商品---是否指定商品(true是) if (CouponDA.CheckIfRelationTypeY(master.SysNo)) { //(指定商品)根据商家SysNo获取符合条件的订单信息和顾客信息 customernewList = CouponDA.GetCustomerAndSoByTypeI(master); } else { //(排他商品)根据商家SysNo获取符合条件的订单信息和顾客信息 customernewList = CouponDA.GetCustomerAndSoByTypeINO(master); } } if (customernewList == null || customernewList.Count <= 0) { WriteLog("没能查询到符合条件的用户"); return; } else { foreach (Customer customer in customernewList) { //排除已经发送优惠卷的订单信息和顾客信息 if (!CouponDA.CheckIfSendCustomerCouponCode(master.SysNo, customer.SOSysNo)) { customerCheckList.Add(customer); } } } if (customerCheckList == null || customerCheckList.Count <= 0) { WriteLog("没能查询到符合条件的用户"); return; } WriteLog("查询到可发的用户" + customerCheckList.Count + "个"); master.BindStatus = "S";//字段 CouponDA.UpdateBindRulesStatus(master); int num = 0; string userList = string.Empty; foreach (Customer customer in customerCheckList) { if (!CouponDA.CheckIfSendCustomerCouponCode(master.SysNo, customer.SOSysNo)) { #region CreateCode CouponCode codeEntity = new CouponCode(); codeEntity.CouponSysNo = master.SysNo; codeEntity.CodeType = "C"; codeEntity.CustomerMaxFrequency = 1; GetCodeExpireDate(master, codeEntity); codeEntity = CouponDA.CreateCode(codeEntity); #endregion CouponCodeCustomerLog logEntity = new CouponCodeCustomerLog(); logEntity.CouponCode = codeEntity.Code; logEntity.CouponSysNo = master.SysNo; logEntity.CustomerSysNo = customer.CustomerSysNo; logEntity.SOSysNo = customer.SOSysNo; logEntity.UserCodeType = userType; CouponDA.InsertCustomerLog(logEntity); num++; userList += "顾客编号:" + customer.CustomerSysNo + "\r\n"; } } WriteLog(DateTime.Now + "购买商品送优惠券成功发送" + num + "次,分别是:\r\n" + userList); }
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); }