/// <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);
            }
        }
        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("领取优惠券异常,请联系客服!");
            }
        }