コード例 #1
0
 public void ProcessRequest(HttpContext context)
 {
     context.Response.ContentType = "text/plain";
     try
     {
         string   str        = context.Request["name"].ToString();
         string   val        = context.Request["val"].ToString();
         string   str3       = context.Request["condition"].ToString();
         string   str4       = context.Request["begin"].ToString();
         string   str5       = context.Request["end"].ToString();
         string   str6       = context.Request["total"].ToString();
         string   str7       = context.Request["isAllMember"].ToString();
         string   str8       = context.Request["memberlvl"].ToString();
         string   str9       = context.Request["maxNum"].ToString();
         string   str10      = context.Request["type"].ToString();
         string   couponName = "";
         decimal  i          = 0M;
         decimal  num2       = 0M;
         DateTime now        = DateTime.Now;
         DateTime time2      = DateTime.Now;
         int      num3       = 0;
         bool     flag       = false;
         string   str12      = "";
         int      num4       = 1;
         int      num5       = 0;
         if (string.IsNullOrEmpty(str) || (str.Length > 20))
         {
             context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券名称\"}");
         }
         else
         {
             couponName = str;
             if (!this.bDecimal(val, ref i))
             {
                 context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券面值\"}");
             }
             else if (!this.bDecimal(str3, ref num2))
             {
                 context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券适用最大满足额\"}");
             }
             else if (!this.bDate(str4, true, ref now))
             {
                 context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的生效日期\"}");
             }
             else if (!this.bDate(str5, false, ref time2))
             {
                 context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的失效日期\"}");
             }
             else if (!this.bInt(str6, ref num3))
             {
                 context.Response.Write("{\"type\":\"error\",\"data\":\"请输入正确的优惠券发放量\"}");
             }
             else
             {
                 flag = bool.Parse(str7);
                 if (!flag)
                 {
                     if (string.IsNullOrEmpty(str8))
                     {
                         context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的会员等级\"}");
                         return;
                     }
                     str12 = str8;
                 }
                 if (!this.bInt(str9, ref num4))
                 {
                     context.Response.Write("{\"type\":\"error\",\"data\":\"请选择正确的优惠券最大领取张数\"}");
                 }
                 else
                 {
                     this.bInt(str10, ref num5);
                     if ((num2 < i) && (num2 != 0M))
                     {
                         context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券面值不能大于满足金额\"}");
                     }
                     else if (time2 < now)
                     {
                         context.Response.Write("{\"type\":\"error\",\"data\":\"优惠券失效日期不能早于生效日期\"}");
                     }
                     else
                     {
                         CouponInfo coupon = new CouponInfo {
                             CouponName     = couponName,
                             CouponValue    = i,
                             ConditionValue = num2,
                             BeginDate      = now,
                             EndDate        = time2,
                             StockNum       = num3,
                             IsAllProduct   = (num5 == 0) ? true : false
                         };
                         if (flag)
                         {
                             coupon.MemberGrades = "0";
                         }
                         else
                         {
                             coupon.MemberGrades = str12;
                         }
                         coupon.maxReceivNum = num4;
                         CouponActionStatus status = CouponHelper.CreateCoupon(coupon);
                         if (status == CouponActionStatus.Success)
                         {
                             coupon = CouponHelper.GetCoupon(couponName);
                             if (coupon != null)
                             {
                                 context.Response.Write("{\"type\":\"success\",\"data\":\"" + coupon.CouponId.ToString() + "\"}");
                             }
                             else
                             {
                                 context.Response.Write("{\"type\":\"error\",\"data\":\"写数据库异常\"}");
                             }
                         }
                         else
                         {
                             context.Response.Write("{\"type\":\"error\",\"data\":\"" + this.GetErrMsg(status.ToString()) + "\"}");
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         context.Response.Write("{\"type\":\"error\",\"data\":\"" + exception.Message + "\"}");
     }
 }
コード例 #2
0
        public void CopyRedEnvelope(string openId, MemberInfo memberInfo)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary.Add("OpenId", openId);
            dictionary.Add("UserName", memberInfo.UserName);
            try
            {
                IList <RedEnvelopeGetRecordInfo> list = WeiXinRedEnvelopeProcessor.GettWaitToUserRedEnvelopeGetRecord(openId);
                if (list == null || list.Count == 0)
                {
                    dictionary.Add("RedEnvelopeErrMsg", "红包记录为空");
                }
                int num = 1;
                foreach (RedEnvelopeGetRecordInfo item in list)
                {
                    WeiXinRedEnvelopeInfo weiXinRedEnvelope = WeiXinRedEnvelopeProcessor.GetWeiXinRedEnvelope(item.RedEnvelopeId);
                    if (weiXinRedEnvelope == null)
                    {
                        dictionary.Add("RedEnvelopeErrMsg" + num, "红包信息为空" + item.RedEnvelopeId.ToNullString());
                    }
                    else
                    {
                        CouponItemInfo couponItemInfo = new CouponItemInfo();
                        couponItemInfo.UserId             = memberInfo.UserId;
                        couponItemInfo.UserName           = memberInfo.UserName;
                        couponItemInfo.CanUseProducts     = "";
                        couponItemInfo.ClosingTime        = weiXinRedEnvelope.EffectivePeriodEndTime;
                        couponItemInfo.RedEnvelopeId      = weiXinRedEnvelope.Id;
                        couponItemInfo.CouponName         = weiXinRedEnvelope.Name;
                        couponItemInfo.OrderUseLimit      = weiXinRedEnvelope.EnableUseMinAmount;
                        couponItemInfo.Price              = item.Amount;
                        couponItemInfo.StartTime          = weiXinRedEnvelope.EffectivePeriodStartTime;
                        couponItemInfo.UseWithGroup       = false;
                        couponItemInfo.UseWithPanicBuying = false;
                        couponItemInfo.GetDate            = DateTime.Now;
                        if (WeiXinRedEnvelopeProcessor.SetRedEnvelopeGetRecordToMember(item.Id, memberInfo.UserName))
                        {
                            CouponActionStatus couponActionStatus = CouponHelper.AddRedEnvelopeItemInfo(couponItemInfo);
                            if (couponActionStatus != 0)
                            {
                                dictionary.Add("SendDiffentTypeClaimCodesErrMsg" + num, "发送优惠券失败-" + couponActionStatus.ToString());
                            }
                            num++;
                        }
                        else
                        {
                            dictionary.Add("SetRedEnvelopeGetRecordToMemberErrMsg" + num, "设置红包记录给会员失败");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.WriteExceptionLog(ex, dictionary, "RedEnvelope");
            }
        }