/// <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); }