Ejemplo n.º 1
0
        /// <summary>
        /// 进入主页获赠优惠券
        /// </summary>
        private void getMyCoupon()
        {
            DataTable  allCoupons = CouponHelper.GetAllCoupons();                           //优惠券列表
            DataTable  allCouponItemsClaimCode = CouponHelper.GetAllCouponItemsClaimCode(); //所有已发送优惠券的claimcode
            MemberInfo currentMember           = MemberProcessor.GetCurrentMember();

            if (currentMember == null)
            {
                return;//如果当前没有登录则不执行该方法
            }
            for (int i = 0; i < allCoupons.Rows.Count; i++)
            {
                if (allCoupons.Rows[i]["sendAtHomepage"].ToString() == "1")//如果需要在主页赠送,就开始判断该用户是否已获取过
                {
                    for (int o = 0; o < allCouponItemsClaimCode.Rows.Count; o++)
                    {
                        string currentClaimCode = allCouponItemsClaimCode.Rows[o]["ClaimCode"].ToString();
                        bool   isSend           = currentMember.UserId.ToString() == currentClaimCode.TrimStart('0');
                        if (isSend)
                        {
                            return;//如果发送过,返回
                        }
                        else
                        {
                            continue;//如果没有发送,继续循环查找
                        }
                    }
                    //发送优惠券
                    int            couponId  = Convert.ToInt32(allCoupons.Rows[i]["CouponId"]);
                    string         claimCode = currentMember.UserId.ToString("000000000000000");
                    CouponItemInfo item      = new CouponItemInfo();
                    System.Collections.Generic.IList <CouponItemInfo> listCouponItem = new System.Collections.Generic.List <CouponItemInfo>();
                    item = new CouponItemInfo(couponId, claimCode, new int?(currentMember.UserId), currentMember.UserName, currentMember.Email, System.DateTime.Now);
                    listCouponItem.Add(item);
                    CouponHelper.SendClaimCodes(couponId, listCouponItem);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 进入主页获赠优惠券
        /// </summary>
        private void getMyCoupon()
        {
            MemberInfo currentMember = MemberProcessor.GetCurrentMember();

            if (currentMember == null)
            {
                return;                                                                    //如果当前没有登录则不执行该方法
            }
            DataTable allCoupons = CouponHelper.GetAllCoupons();                           //优惠券列表
            DataTable allCouponItemsClaimCode = CouponHelper.GetAllCouponItemsClaimCode(); //所有已发送优惠券的claimcode

            for (int i = 0; i < allCoupons.Rows.Count; i++)
            {
                if (allCoupons.Rows[i]["sendAtHomepage"].ToString() == "1")    //如果需要在主页赠送,就开始判断该用户是否已获取过
                {
                    bool isSend = true;
                    //发送优惠券
                    int couponId = Convert.ToInt32(allCoupons.Rows[i]["CouponId"]);
                    for (int o = 0; o < allCouponItemsClaimCode.Rows.Count; o++)
                    {
                        string   currentClaimCode  = allCouponItemsClaimCode.Rows[o]["ClaimCode"].ToString();
                        string[] claimCodeUnhandle = currentClaimCode.TrimStart('b').Split('|');
                        if (claimCodeUnhandle.Length == 2)
                        {
                            isSend = (currentMember.UserId.ToString() == claimCodeUnhandle[1] && couponId.ToString() == claimCodeUnhandle[0]);
                            if (isSend)
                            {
                                break;    //如果发送过,跳出循环
                            }
                            else
                            {
                                continue;    //如果没有发送,继续循环查找
                            }
                        }
                        else
                        {
                            isSend = currentMember.UserId.ToString() == currentClaimCode.TrimStart('0');
                            if (isSend)
                            {
                                break;    //如果发送过,跳出循环
                            }
                            else
                            {
                                continue;    //如果没有发送,继续循环查找
                            }
                        }
                    }
                    if (!isSend)
                    {
                        int    number;
                        string claimCode = string.Empty;
                        claimCode += couponId + "|" + currentMember.UserId;
                        claimCode  = claimCode.PadLeft(15, 'b');
                        CouponItemInfo item = new CouponItemInfo();
                        System.Collections.Generic.IList <CouponItemInfo> listCouponItem = new System.Collections.Generic.List <CouponItemInfo>();
                        item = new CouponItemInfo(couponId, claimCode, new int?(currentMember.UserId), currentMember.UserName, currentMember.Email, System.DateTime.Now);
                        listCouponItem.Add(item);
                        CouponHelper.SendClaimCodes(couponId, listCouponItem);
                    }
                }
            }
        }