//获取优惠券 private 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 (!PromotionDA.CheckExistCode(CouponCode, null)) { success = 1; } } return(CouponCode); }
/// <summary> /// 获取当前用户可参与的优惠券活动(当商家不确定或者为自营商品时获取平台优惠券活动,第三方商家是获取当前用户在该商家可参与的优惠券活动) /// </summary> /// Create by John.E.Kang 2015.11.03 /// <param name="UserSysNo">用户编码</param> /// <param name="MerchantSysNo">商家编码</param> /// <returns></returns> public static List <CouponInfo> GetCouponList(int UserSysNo, int MerchantSysNo) { int RemainingNumber = 0; List <CouponInfo> couponList_pre = new List <CouponInfo>(); List <CouponInfo> couponList = new List <CouponInfo>(); try { couponList_pre = PromotionDA.GetCouponList(UserSysNo, MerchantSysNo); foreach (var item in couponList_pre) { CouponInfo couponinfo = PromotionDA.GetCouponInfo(item.SysNo); if (couponinfo != null) { item.SaleRulesList = couponinfo.SaleRulesList; item.AssignCustomerList = couponinfo.AssignCustomerList; item.DiscountRuleList = couponinfo.DiscountRuleList; item.SaleRulesEx = couponinfo.SaleRulesEx; //当为百分比折扣是显示前台显示折扣价 if (couponinfo.DiscountRuleList[0].DiscountType == CouponDiscountType.OrderAmountPercentage) { item.DiscountRuleList[0].Value = 1 - couponinfo.DiscountRuleList[0].Value; } } //活动已参与次数 int UsedTotalNumber = PromotionDA.GetCodeNumberByCouponNumber(item.SysNo); //校验用户是否可领取优惠券 bool receivable = false; if (couponinfo.SaleRulesEx.CustomerMaxFrequency.HasValue) { receivable = PromotionDA.CheckUserAreadyGetCode(UserSysNo, item.SysNo, (int)couponinfo.SaleRulesEx.CustomerMaxFrequency, out RemainingNumber); } if (!receivable && !(item.SaleRulesEx.MaxFrequency.HasValue && UsedTotalNumber >= item.SaleRulesEx.MaxFrequency)) { couponList.Add(item); } } return(couponList); } catch { couponList = null; return(couponList); } }
/// <summary> /// 构建购物车商品分组 /// </summary> /// <param name="category"></param> /// <param name="sysNo"></param> /// <param name="qty"></param> /// <returns></returns> public static ShoppingItemGroup BuildShoppingItemGroup(string category, int sysNo, int qty) { ShoppingItemGroup result = new ShoppingItemGroup(); if (category.ToLower().Equals("product")) { result.ShoppingItemList = new List <ShoppingItem>() { new ShoppingItem() { ProductSysNo = sysNo, UnitQuantity = 1, ProductChecked = true } }; result.PackageType = 0; result.PackageNo = 0; result.Quantity = qty; result.PackageChecked = true; } else if (category.ToLower().Equals("package")) { result.ShoppingItemList = new List <ShoppingItem>(); //根据套餐编号加载套餐内的商品和数量 ComboInfo comb = PromotionDA.GetComboByComboSysNo(sysNo); result.ShoppingItemList = new List <ShoppingItem>(); if (comb != null && comb.Items != null && comb.Items.Count > 0) { foreach (var combItem in comb.Items) { result.ShoppingItemList.Add(new ShoppingItem() { ProductSysNo = combItem.ProductSysNo, UnitQuantity = combItem.Quantity }); } } result.PackageChecked = true; result.PackageType = 1; result.PackageNo = sysNo; result.Quantity = qty; } return(result); }
/// <summary> /// 获取指定商品的所有促销信息 /// </summary> /// <param name="productSysNo"></param> /// <returns></returns> public static ProductPromotionInfo GetProductPromotionInfo(int productSysNo) { if (productSysNo <= 0) { return(null); } string cacheKey = "GetProductPromotionInfo_" + productSysNo; if (HttpRuntime.Cache[cacheKey] != null) { return((ProductPromotionInfo)HttpRuntime.Cache[cacheKey]); } ProductPromotionInfo promotion = new ProductPromotionInfo(); promotion.ProductSysNo = productSysNo; //套餐 promotion.ComboList = PromotionDA.GetComboListByMasterProductSysNo(productSysNo); //团购 promotion.GroupBuySysNo = PromotionDA.ProductIsGroupBuying(productSysNo); //限时和秒杀 CountdownInfo countdown = PromotionDA.GetProductCountdownByProductSysNo(productSysNo); if (countdown != null) { promotion.Countdown = countdown; promotion.CountdownSysNo = countdown.SysNo.Value; promotion.IsSecKill = countdown.IsSecondKill.HasValue ? countdown.IsSecondKill.Value : false; } else { promotion.CountdownSysNo = 0; promotion.IsSecKill = false; } //赠品 promotion.SaleGiftList = PromotionDA.GetSaleGiftListByProductSysNo(productSysNo); HttpRuntime.Cache.Insert(cacheKey, promotion, null, DateTime.Now.AddSeconds(CacheTime.Short), Cache.NoSlidingExpiration); return(promotion); }
public static string UserGetCouponCode(int UserSysNo, int CouponSysNo, out string couponCodestr) { couponCodestr = ""; int RemainingNumber = 0; CouponInfo coupon = new CouponInfo(); coupon = PromotionDA.GetCouponInfo(CouponSysNo); if (coupon == null) { return("优惠券活动异常,请联系客服!"); } CouponCode couponCode = new CouponCode(); CouponCodeCustomerLog couponCodeCustomLog = new CouponCodeCustomerLog(); try { //校验用户是否已领取优惠券 int CouponNumber = PromotionDA.GetCodeNumberByCouponNumber(coupon.SysNo); if (coupon.SaleRulesEx.MaxFrequency.HasValue && CouponNumber >= coupon.SaleRulesEx.MaxFrequency) { return("活动优惠券已被领完,谢谢参与!"); } if (coupon.SaleRulesEx.CustomerMaxFrequency.HasValue && PromotionDA.CheckUserAreadyGetCode(UserSysNo, CouponSysNo, (int)coupon.SaleRulesEx.CustomerMaxFrequency, out RemainingNumber)) { return("您领取次数已完,谢谢参与!"); } string GenerateCode = GenerateRandomCode(10); couponCode.Code = GenerateCode; //领取优惠券为通用优惠券 couponCode.CodeType = "C"; couponCode.CouponSysNo = coupon.SysNo; couponCode.CustomerMaxFrequency = 1; couponCode.EndDate = coupon.EndDate; couponCode.TotalCount = 1; couponCode.BeginDate = coupon.BeginDate; int couponCodeSysNo = PromotionDA.InsertCouponCode(UserSysNo, couponCode); if (couponCodeSysNo <= 0) { return("无法领取优惠券,请联系客服!"); } couponCodeCustomLog.CouponCode = GenerateCode; couponCodeCustomLog.CouponSysNo = coupon.SysNo; couponCodeCustomLog.CustomerSysNo = UserSysNo; couponCodeCustomLog.UserCodeType = "L"; if (PromotionDA.InsertCustomerLog(couponCodeCustomLog)) { couponCodestr = GenerateCode; return("您已成功领取优惠券,号码:" + GenerateCode); //if (RemainingNumber>0) //{ // RemainingNumber--; // return "您已成功领取优惠券,号码:" + GenerateCode + "。\n你还有" + RemainingNumber+"次领取机会!"; //} //else //{ // return "您已成功领取优惠券,号码:" + GenerateCode; //} } else { return("无法领取优惠券,请联系客服!"); } } catch { return("领取优惠券异常,请联系客服!"); } }