예제 #1
0
        /// <summary>
        /// 大转盘回复内容
        /// </summary>
        /// <param name="id">模块主键Id</param>
        /// <param name="apiid">微帐号主键id</param>
        /// <param name="openid">openid</param>
        /// <param name="responseType">回复类型:1纯文字,2图文</param>
        /// <param name="responseVaule">回复的内容</param>
        private IList <Model.ResponseContentEntity> DZPReponse(int id, int apiid, string openid)
        {
            IList <Model.ResponseContentEntity> responselist = new List <Model.ResponseContentEntity>();

            Model.ResponseContentEntity responseEntity = new Model.ResponseContentEntity();
            responseEntity.id  = id;
            responseEntity.wid = apiid;


            BLL.wx_dzpActionInfo   ggkActBll = new BLL.wx_dzpActionInfo();
            Model.wx_dzpActionInfo actModel  = ggkActBll.GetModel(id);
            if (actModel.beginDate > DateTime.Now)
            {  //活动尚未开始
                responseEntity.rcType   = Model.ReponseContentType.text;
                responseEntity.rContent = "活动【" + actModel.actName + "】将于" + actModel.beginDate + "开始。";
            }
            else if (actModel.endDate <= DateTime.Now)
            {
                //活动结束
                responseEntity.rcType    = Model.ReponseContentType.txtpic;
                responseEntity.rContent  = actModel.endNotice;
                responseEntity.rContent2 = actModel.endContent;
                responseEntity.detailUrl = MyCommFun.getWebSite() + "/weixin/dzp/end.aspx?wid=" + apiid + "&aid=" + id;
                responseEntity.picUrl    = actModel.endPic;
            }
            else
            {
                //活动正在进行中

                responseEntity.rcType    = Model.ReponseContentType.txtpic;
                responseEntity.rContent  = actModel.actName;
                responseEntity.rContent2 = actModel.brief;
                responseEntity.detailUrl = MyCommFun.getWebSite() + "/weixin/dzp/index.aspx?wid=" + apiid + "&aid=" + id;
                responseEntity.picUrl    = actModel.beginPic;
            }
            responselist.Add(responseEntity);
            return(responselist);
        }
예제 #2
0
        private void ShowInfo(int id)
        {
            hidid.Value = id.ToString();
            Model.wx_dzpActionInfo        dzpAction = dzpBll.GetModel(id);
            IList <Model.wx_dzpAwardItem> aItemlist = iBll.GetModelList("actId=" + id);

            Model.wx_requestRule rule = rBll.GetModelList("modelFunctionName='大转盘' and modelFunctionId=" + id)[0];
            txtKW.Text = rule.reqKeywords;

            if (dzpAction.beginPic != null && dzpAction.beginPic.Trim() != "/weixin/dzp/images/start.jpg")
            {
                txtImgUrl.Text       = dzpAction.beginPic;
                imgbeginPic.ImageUrl = dzpAction.beginPic;
            }
            txtactName.Text      = dzpAction.actName;
            txtcontractInfo.Text = dzpAction.contractInfo;
            txtbrief.Value       = dzpAction.brief;
            txtbeginDate.Text    = dzpAction.beginDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
            txtendDate.Text      = dzpAction.endDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
            txtactContent.Value  = dzpAction.actContent;
            txtcfcjhf.Text       = dzpAction.cfcjhf;
            this.txtdjPwd.Text   = dzpAction.djPwd;
            //结束
            if (dzpAction.endPic != null && dzpAction.endPic.Trim() != "/weixin/dzp/images/end.jpg")
            {
                txtEndPic.Text     = dzpAction.endPic;
                imgEndPic.ImageUrl = dzpAction.endPic;
            }
            txtendNotice.Text  = dzpAction.endNotice;
            txtendContent.Text = dzpAction.endContent;

            //奖项基本信息
            txtpersonNum.Text      = MyCommFun.ObjToStr(dzpAction.personNum);
            txtpersonMaxTimes.Text = MyCommFun.ObjToStr(dzpAction.personMaxTimes);
            txtdayMaxTimes.Text    = MyCommFun.ObjToStr(dzpAction.dayMaxTimes);


            //绑定奖项信息
            IList <Model.wx_dzpAwardItem> itemlist = iBll.GetModelList("actId=" + id + " order by sort_id asc");

            if (itemlist != null && itemlist.Count > 0)
            {
                int     count = itemlist.Count;
                TextBox txtJXName;
                TextBox txtJPName;
                TextBox txtNum;
                TextBox txtRealNum;
                Model.wx_dzpAwardItem itemEntity = new Model.wx_dzpAwardItem();
                for (int i = 1; i <= count; i++)
                {
                    itemEntity = itemlist[(i - 1)];
                    txtJXName  = this.FindControl("txt" + i + "JXName") as TextBox;
                    txtJPName  = this.FindControl("txt" + i + "JPName") as TextBox;
                    txtNum     = this.FindControl("txt" + i + "Num") as TextBox;
                    txtRealNum = this.FindControl("txt" + i + "RealNum") as TextBox;

                    txtJXName.Text  = itemEntity.jxName;
                    txtJPName.Text  = itemEntity.jpName;
                    txtNum.Text     = itemEntity.jpNum == null ? "0" : itemEntity.jpNum.Value.ToString();
                    txtRealNum.Text = itemEntity.jpRealNum == null ? "0" : itemEntity.jpRealNum.Value.ToString();
                }
            }
        }
예제 #3
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.wx_userweixin weixin = GetWeiXinCode();

            Model.wx_requestRuleContent rc = new Model.wx_requestRuleContent();
            int id = MyCommFun.Str2Int(hidid.Value);

            #region  //先判断
            string strErr = "";
            if (this.txtKW.Text.Trim().Length == 0)
            {
                strErr += "关键词不能为空!";
            }
            if (this.txtactName.Text.Trim().Length == 0)
            {
                strErr += "活动名称不能为空!";
            }
            if (this.txtbeginDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtbeginDate.Text))
            {
                strErr += "开始时间不能为空!";
            }
            if (this.txtendDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtendDate.Text))
            {
                strErr += "结束时间不能为空!";
            }
            if (txt1JXName.Text.Trim().Length == 0 || txt1JPName.Text.Trim().Length == 0 || txt1Num.Text.Trim().Length == 0 || txt1RealNum.Text.Trim().Length == 0)
            {
                strErr += "第一个奖项不能为空!";
            }
            if (txt2JXName.Text.Trim().Length == 0 || txt2JPName.Text.Trim().Length == 0 || txt2Num.Text.Trim().Length == 0 || txt2RealNum.Text.Trim().Length == 0)
            {
                strErr += "第二个奖项不能为空!";
            }

            if (strErr != "")
            {
                JscriptMsg(strErr, "back", "Error");
                return;
            }
            DateTime begin = DateTime.Parse(txtbeginDate.Text.Trim());
            DateTime end   = DateTime.Parse(txtendDate.Text.Trim());
            if (begin >= end)
            {
                JscriptMsg("开始时间必须小于结束时间", "back", "Error");
                return;
            }
            #endregion

            #region 赋值
            Model.wx_dzpActionInfo dzp  = new Model.wx_dzpActionInfo();
            Model.wx_requestRule   rule = new Model.wx_requestRule();

            string beginPic = imgbeginPic.ImageUrl;
            if (txtImgUrl.Text.Trim() != "")
            {
                beginPic = txtImgUrl.Text.Trim();
            }
            string endPic = imgEndPic.ImageUrl;
            if (txtEndPic.Text.Trim() != "")
            {
                endPic = txtEndPic.Text.Trim();
            }

            if (id > 0)
            {
                dzp = dzpBll.GetModel(id);
            }

            dzp.actName      = txtactName.Text.Trim();
            dzp.contractInfo = txtcontractInfo.Text.Trim();
            dzp.brief        = txtbrief.Value.Trim();
            dzp.beginDate    = begin;
            dzp.endDate      = end;
            dzp.actContent   = txtactContent.Value.Trim();
            dzp.cfcjhf       = txtcfcjhf.Text.Trim();
            dzp.endNotice    = txtendNotice.Text.Trim();
            dzp.endContent   = txtendContent.Text.Trim();
            dzp.djPwd        = txtdjPwd.Text.Trim();

            dzp.beginPic       = beginPic;
            dzp.endPic         = endPic;
            dzp.personNum      = MyCommFun.Str2Int(txtpersonNum.Text);
            dzp.personMaxTimes = MyCommFun.Str2Int(txtpersonMaxTimes.Text);
            dzp.dayMaxTimes    = MyCommFun.Str2Int(txtdayMaxTimes.Text);

            #endregion

            if (id <= 0)
            {  //新增
                dzp.wid        = weixin.id;
                dzp.createDate = DateTime.Now;
                //1新增主表
                id = dzpBll.Add(dzp);

                //2新增奖项表
                EditAwardItem(id);
                //3 新增回复规则表
                AddRule(weixin.id, id);
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加大转盘活动,主键为" + id); //记录日志
                JscriptMsg("添加大转盘活动成功!", "dzplist.aspx", "Success");
            }
            else
            {   //修改
                //1修改主表
                dzpBll.Update(dzp);
                //2删除,且新增奖项表
                EditAwardItem(id);
                //3 修改回复规则表
                IList <Model.wx_requestRule> rlist = rBll.GetModelList("modelFunctionName = '大转盘' and modelFunctionId=" + id);

                if (rlist != null && rlist.Count > 0)
                {
                    rule             = rlist[0];
                    rule.reqKeywords = txtKW.Text.Trim();
                    rBll.Update(rule);
                }
                else
                {
                    AddRule(weixin.id, id);
                }

                AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改大转盘活动,主键为" + id); //记录日志
                JscriptMsg("修改大转盘活动成功!", "dzplist.aspx", "Success");
            }
        }
예제 #4
0
        private void BindData()
        {
            dzpAction = actBll.GetModel(aid);
            IList <Model.wx_dzpAwardItem> itemlist = itemBll.GetModelList("actId=" + aid);

            if (dzpAction == null || itemlist == null || itemlist.Count <= 0)
            {
                ErrLevel  = 1;
                ErrorInfo = "未获得到数据";
                return;
            }
            this.Title = dzpAction.actName;

            if (dzpAction.endDate <= DateTime.Now)
            {   //说明活动已经结束
                ErrLevel  = 101;
                ErrorInfo = "活动已结束";
                return;
            }

            StringBuilder sb = new StringBuilder("");

            Model.wx_dzpAwardItem item = new Model.wx_dzpAwardItem();
            int ttJpNum = 0;

            shuzu = "[";
            for (int i = 0; i < itemlist.Count; i++)
            {
                item = itemlist[i];
                sb.Append("<p>" + item.jxName + ":" + item.jpName + "  数量:" + item.jpNum + "</p>");
                ttJpNum += item.jpRealNum.Value;
                picIndex++;
                if (i < (itemlist.Count - 1))
                {
                    shuzu += item.jiaodu_min + ",";
                }
                else
                {
                    shuzu += item.jiaodu_min;
                }
            }
            shuzu              += "]";
            litJiangXing.Text   = sb.ToString();
            litRemark.Text      = dzpAction.brief;
            litContentInfo.Text = dzpAction.contractInfo;

            littotTimes.Text  = dzpAction.personMaxTimes == null ? "0" : dzpAction.personMaxTimes.Value.ToString();
            litdaysTimes.Text = dzpAction.dayMaxTimes == null ? "0" : dzpAction.dayMaxTimes.Value.ToString();
            if (dzpAction.djPwd.Trim().Length > 0)
            {
                litPwd.Text = "  <p>  <input name=\"\" class=\"px\" id=\"parssword\" type=\"password\" value=\"\" placeholder=\"商家输入兑奖密码\"></p>";
            }
            if (dzpAction.beginDate > DateTime.Now)
            {
                hidStatus.Value = "-2";
                ErrorInfo       = hidErrInfo.Value = "活动尚未开始";
            }
            int hasCjTimes = utbll.getCJCiShu(aid, openid);//返回该用户的抽奖次数

            this.litHasUsedTimes.Text = hasCjTimes.ToString();

            int dayMaxTimes = dzpAction.dayMaxTimes == null ? 0 : dzpAction.dayMaxTimes.Value;
            int perMaxTimes = dzpAction.personMaxTimes == null ? 0 : dzpAction.personMaxTimes.Value;

            //判断是否中奖了

            Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
            if (award != null && award.id > 0)
            {     //您中奖了
                if (award.uTel != null && award.uTel.ToString().Trim() != "")
                { //已经中奖,并且提交了
                    litJp.Text  = "[" + award.jxName + "] " + award.jpName;
                    litSNM.Text = award.sn;
                    isZhJing    = true;
                }
                else
                { //已经中奖,但是未提交
                    hidStatus.Value  = "100";
                    litzjlJP.Text    = "[" + award.jxName + "] " + award.jpName;
                    litzjlSN.Text    = award.sn;
                    hidAwardId.Value = award.id.ToString();

                    litJp.Text  = "[" + award.jxName + "] " + award.jpName;
                    litSNM.Text = award.sn;
                }
            }
            else
            {
                //判断每人最大抽奖次数,是否超过了
                if (hasCjTimes >= dzpAction.personMaxTimes)
                {
                    hidStatus.Value  = "2";
                    litOtherTip.Text = "<p class='red'>您已经抽了" + hasCjTimes + "次了。</p>";
                }
                if (isTodayOverSum(dayMaxTimes))
                {
                    hidStatus.Value  = "2";
                    litOtherTip.Text = "<p class='red'>每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会,您已经使用完了。</p>";
                }
            }
        }
예제 #5
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string _action = MyCommFun.QueryString("myact");
            int aid = MyCommFun.RequestInt("aid");
            string openid = MyCommFun.RequestOpenid();  //得到微信用户的openid
            if (_action == "choujiang")
            {
                Dictionary<string, string> jsonDict = new Dictionary<string, string>();

                try
                {
                    //抽奖
                    Model.wx_dzpActionInfo dzpAction = new Model.wx_dzpActionInfo();
                  
                    BLL.wx_dzpAwardItem itemBll = new BLL.wx_dzpAwardItem();



                    #region 判断
                    int wid = MyCommFun.RequestInt("wid");
                    if (aid == 0 || wid == 0 || openid.Trim() == "")
                    {
                        jsonDict.Add("error", "sys");
                        jsonDict.Add("content", "参数错误!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;

                    }
                    dzpAction = actbll.GetModel(aid);
                    if (dzpAction == null)
                    {
                        jsonDict.Add("error", "sys");
                        jsonDict.Add("content", "参数错误!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }

                    if (dzpAction.endDate <= DateTime.Now)
                    { //说明活动已经结束
                        //非活动期间
                        jsonDict.Add("error", "end");
                        jsonDict.Add("content", "活动已结束");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    else if (dzpAction.beginDate > DateTime.Now)
                    {
                        //活动未开始
                        //非活动期间
                        jsonDict.Add("error", "nostart");
                        jsonDict.Add("content", "活动未开始");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    int dayMaxTimes = dzpAction.dayMaxTimes == null ? 0 : dzpAction.dayMaxTimes.Value;
                    int perMaxTimes = dzpAction.personMaxTimes == null ? 0 : dzpAction.personMaxTimes.Value;
                    //判断每人最大抽奖次数,是否超过了
                    if (personCJTimes(openid, aid) >= dzpAction.personMaxTimes)
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您已抽过奖了,欢迎下次再来!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    if (isTodayOverSum(aid, openid, dayMaxTimes))
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会。");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
                    if (award != null)
                    {
                        //您中奖了
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您已奖了,欢迎下次再来!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }


                    #endregion

                    #region 计算中奖信息

                    /// 处理是否中奖
                    /// hidStatus 状态为-1:不能抽奖,直接跳转到end.aspx页面;
                    /// 0:抽奖次数超过设置的最高次数;
                    /// 1:还可以继续抽奖;
                    /// 2:中奖了;

                    List<Model.wx_dzpAwardItem> itemlist = itemBll.GetModelList("actId=" + aid);//该活动的所有奖项信息
                    int ttJpNum = 0;
                    for (int i = 0; i < itemlist.Count; i++)
                    {
                        ttJpNum += itemlist[i].jpRealNum.Value;
                    }


                    IList<Model.wx_dzpAwardUser> auserlist = ubll.getHasZJList(aid);//已经中奖的人列表
                    int ZhongJiangNum = 0;
                    if (auserlist != null)
                    {
                        ZhongJiangNum = auserlist.Count; //已经中奖的人数
                    }

                    int syZjNum = ttJpNum - ZhongJiangNum; //剩余的奖品数量
                    if (syZjNum <= 0)
                    {  //说明已经没有奖品了
                        jsonDict.Add("error", "-1");
                        jsonDict.Add("content", dzpAction.cfcjhf);
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    dzpAction.personNum = MyCommFun.Obj2Int(dzpAction.personNum, 1);
                    dzpAction.personMaxTimes = MyCommFun.Obj2Int(dzpAction.personMaxTimes, 1);
                    int fenmo = dzpAction.personNum.Value * dzpAction.personMaxTimes.Value;

                    Random rd = new Random((int)DateTime.Now.Ticks);
                    int radNum = rd.Next(0, fenmo);//从0到fenmo里随机出一个值
                    if (radNum < syZjNum)
                    {
                        //中奖了,再从剩余奖品里抽取一个奖品
                        Model.wx_dzpAwardItem dajiang = getZJItem(itemlist, auserlist);
                        if (dajiang != null)
                        {
                            //这是中的中奖了
                            string snumber = Get_snumber(aid);
                            int uId = ubll.Add(aid, "", "", openid, dajiang.jxName, dajiang.jpName, snumber);

                            jsonDict.Add("error", "succ");
                            jsonDict.Add("content", "恭喜你中奖了!");
                            jsonDict.Add("sortid", dajiang.sort_id.Value.ToString());
                            jsonDict.Add("jxname", dajiang.jxName);
                            jsonDict.Add("jpname", dajiang.jpName);
                            jsonDict.Add("uid", uId.ToString());
                            jsonDict.Add("sn", snumber);
                            context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                            return;
                        }
                        else
                        {
                            //奖品已经全部中完了
                            jsonDict.Add("error", "-1");
                            jsonDict.Add("content", dzpAction.cfcjhf);
                            context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                            return;
                        }

                    }
                    else
                    {
                        //这个条件说明:未中奖
                        //抛出未中奖的数据 

                        jsonDict.Add("error", "-1");
                        jsonDict.Add("content", dzpAction.cfcjhf);
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;

                    }




                    #endregion
                }
                catch (Exception ex)
                {
                    jsonDict.Add("error", "sys");
                    jsonDict.Add("content", "计算抽奖出现未知错误,请联系管理员!");
                    context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                    return;
                }




            }
            else if (_action == "update")
            {
                try
                {
                    #region 提交手机
                    /// 提交手机号码
                    string tel = MyCommFun.QueryString("tel");
                    string pwd = MyCommFun.QueryString("pwd");
                    string snumber = MyCommFun.QueryString("snumber");
                    int id = MyCommFun.RequestInt("id");

                    if (aid == 0 || id == 0 || snumber == "" || tel == "")
                    {
                        context.Response.Write("{\"msg\":\"提交出现异常!!\",\"success\":\"0\"}");
                        return;
                    }

                    if ((pwd.Length>0) &&( !actbll.ExistsPwd(aid, pwd)))
                    {
                        context.Response.Write("{\"msg\":\"商家兑换密码错误!!\",\"success\":\"0\"}");
                        return;
                    }


                    BLL.wx_dzpAwardUser ubll = new BLL.wx_dzpAwardUser();
                    Model.wx_dzpAwardUser model = ubll.GetModel(id);
                    if (model == null)
                    {
                        context.Response.Write("{\"msg\":\"提交出现异常2!!\",\"success\":\"0\"}");
                        return;
                    }
                    model.uTel = tel;
                    if (pwd.Length > 0)
                    {
                        model.hasLingQu = true;
                    }
                    else
                    {
                        model.hasLingQu = false;
                    }
                    ubll.Update(model);

                    context.Response.Write("{\"msg\":\"提交成功!\",\"success\":\"1\"}");
                    return;
                    #endregion

                }
                catch
                {
                    context.Response.Write("{\"msg\":\"提交出现异常!!\",\"success\":\"0\"}");

                    return;
                }

            }
        }
예제 #6
0
        //保存
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.wx_userweixin weixin = GetWeiXinCode();

            Model.wx_requestRuleContent rc = new Model.wx_requestRuleContent();
            int id = MyCommFun.Str2Int(hidid.Value);
            #region  //先判断
            string strErr = "";
            if (this.txtKW.Text.Trim().Length == 0)
            {
                strErr += "关键词不能为空!";
            }
            if (this.txtactName.Text.Trim().Length == 0)
            {
                strErr += "活动名称不能为空!";
            }
            if (this.txtbeginDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtbeginDate.Text))
            {
                strErr += "开始时间不能为空!";
            }
            if (this.txtendDate.Text.Trim().Length == 0 || !MyCommFun.isDateTime(txtendDate.Text))
            {
                strErr += "结束时间不能为空!";
            }
            if (txt1JXName.Text.Trim().Length == 0 || txt1JPName.Text.Trim().Length == 0 || txt1Num.Text.Trim().Length == 0 || txt1RealNum.Text.Trim().Length == 0)
            {
                strErr += "第一个奖项不能为空!";
            }
            if (txt2JXName.Text.Trim().Length == 0 || txt2JPName.Text.Trim().Length == 0 || txt2Num.Text.Trim().Length == 0 || txt2RealNum.Text.Trim().Length == 0)
            {
                strErr += "第二个奖项不能为空!";
            }

            if (strErr != "")
            {
                JscriptMsg(strErr, "back", "Error");
                return;
            }
            DateTime begin = DateTime.Parse(txtbeginDate.Text.Trim());
            DateTime end = DateTime.Parse(txtendDate.Text.Trim());
            if (begin >= end)
            {
                JscriptMsg("开始时间必须小于结束时间", "back", "Error");
                return;
            }
            #endregion

            #region 赋值
            Model.wx_dzpActionInfo dzp = new Model.wx_dzpActionInfo();
            Model.wx_requestRule rule = new Model.wx_requestRule();

            string beginPic = imgbeginPic.ImageUrl;
            if (txtImgUrl.Text.Trim() != "")
            {
                beginPic = txtImgUrl.Text.Trim();
            }
            string endPic = imgEndPic.ImageUrl;
            if (txtEndPic.Text.Trim() != "")
            {
                endPic = txtEndPic.Text.Trim();
            }

            if (id > 0)
            {
                dzp = dzpBll.GetModel(id);
            }

            dzp.actName = txtactName.Text.Trim();
            dzp.contractInfo = txtcontractInfo.Text.Trim();
            dzp.brief = txtbrief.Value.Trim();
            dzp.beginDate = begin;
            dzp.endDate = end;
            dzp.actContent = txtactContent.Value.Trim();
            dzp.cfcjhf = txtcfcjhf.Text.Trim();
            dzp.endNotice = txtendNotice.Text.Trim();
            dzp.endContent = txtendContent.Text.Trim();
            dzp.djPwd = txtdjPwd.Text.Trim();

            dzp.beginPic = beginPic;
            dzp.endPic = endPic;
            dzp.personNum = MyCommFun.Str2Int(txtpersonNum.Text);
            dzp.personMaxTimes = MyCommFun.Str2Int(txtpersonMaxTimes.Text);
            dzp.dayMaxTimes = MyCommFun.Str2Int(txtdayMaxTimes.Text);

            #endregion

            if (id <= 0)
            {  //新增
                dzp.wid = weixin.id;
                dzp.createDate = DateTime.Now;
                //1新增主表
                id = dzpBll.Add(dzp);

                //2新增奖项表
                EditAwardItem(id);
                //3 新增回复规则表
                AddRule(weixin.id, id);
                AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加大转盘活动,主键为" + id); //记录日志
                JscriptMsg("添加大转盘活动成功!", "dzplist.aspx", "Success");
            }
            else
            {   //修改
                //1修改主表
                dzpBll.Update(dzp);
                //2删除,且新增奖项表
                EditAwardItem(id);
                //3 修改回复规则表
                IList<Model.wx_requestRule> rlist = rBll.GetModelList("modelFunctionName = '大转盘' and modelFunctionId=" + id);

                if (rlist != null && rlist.Count > 0)
                {
                    rule = rlist[0];
                    rule.reqKeywords = txtKW.Text.Trim();
                    rBll.Update(rule);
                }
                else
                {
                    AddRule(weixin.id, id);
                }

                AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改大转盘活动,主键为" + id); //记录日志
                JscriptMsg("修改大转盘活动成功!", "dzplist.aspx", "Success");
            }

        }
예제 #7
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string _action = MyCommFun.QueryString("myact");
            int    aid     = MyCommFun.RequestInt("aid");
            string openid  = MyCommFun.RequestOpenid(); //得到微信用户的openid

            if (_action == "choujiang")
            {
                Dictionary <string, string> jsonDict = new Dictionary <string, string>();

                try
                {
                    //抽奖
                    Model.wx_dzpActionInfo dzpAction = new Model.wx_dzpActionInfo();

                    BLL.wx_dzpAwardItem itemBll = new BLL.wx_dzpAwardItem();



                    #region 判断
                    int wid = MyCommFun.RequestInt("wid");
                    if (aid == 0 || wid == 0 || openid.Trim() == "")
                    {
                        jsonDict.Add("error", "sys");
                        jsonDict.Add("content", "参数错误!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    dzpAction = actbll.GetModel(aid);
                    if (dzpAction == null)
                    {
                        jsonDict.Add("error", "sys");
                        jsonDict.Add("content", "参数错误!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }

                    if (dzpAction.endDate <= DateTime.Now)
                    { //说明活动已经结束
                        //非活动期间
                        jsonDict.Add("error", "end");
                        jsonDict.Add("content", "活动已结束");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    else if (dzpAction.beginDate > DateTime.Now)
                    {
                        //活动未开始
                        //非活动期间
                        jsonDict.Add("error", "nostart");
                        jsonDict.Add("content", "活动未开始");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    int dayMaxTimes = dzpAction.dayMaxTimes == null ? 0 : dzpAction.dayMaxTimes.Value;
                    int perMaxTimes = dzpAction.personMaxTimes == null ? 0 : dzpAction.personMaxTimes.Value;
                    //判断每人最大抽奖次数,是否超过了
                    if (personCJTimes(openid, aid) >= dzpAction.personMaxTimes)
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您已抽过奖了,欢迎下次再来!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    if (isTodayOverSum(aid, openid, dayMaxTimes))
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会。");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
                    if (award != null)
                    {
                        //您中奖了
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您已奖了,欢迎下次再来!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }


                    #endregion

                    #region 计算中奖信息

                    /// 处理是否中奖
                    /// hidStatus 状态为-1:不能抽奖,直接跳转到end.aspx页面;
                    /// 0:抽奖次数超过设置的最高次数;
                    /// 1:还可以继续抽奖;
                    /// 2:中奖了;

                    List <Model.wx_dzpAwardItem> itemlist = itemBll.GetModelList("actId=" + aid);//该活动的所有奖项信息
                    int ttJpNum = 0;
                    for (int i = 0; i < itemlist.Count; i++)
                    {
                        ttJpNum += itemlist[i].jpRealNum.Value;
                    }


                    IList <Model.wx_dzpAwardUser> auserlist = ubll.getHasZJList(aid);//已经中奖的人列表
                    int ZhongJiangNum = 0;
                    if (auserlist != null)
                    {
                        ZhongJiangNum = auserlist.Count; //已经中奖的人数
                    }

                    int syZjNum = ttJpNum - ZhongJiangNum; //剩余的奖品数量
                    if (syZjNum <= 0)
                    {                                      //说明已经没有奖品了
                        jsonDict.Add("error", "-1");
                        jsonDict.Add("content", dzpAction.cfcjhf);
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    dzpAction.personNum      = MyCommFun.Obj2Int(dzpAction.personNum, 1);
                    dzpAction.personMaxTimes = MyCommFun.Obj2Int(dzpAction.personMaxTimes, 1);
                    int fenmo = dzpAction.personNum.Value * dzpAction.personMaxTimes.Value;

                    Random rd     = new Random((int)DateTime.Now.Ticks);
                    int    radNum = rd.Next(0, fenmo);//从0到fenmo里随机出一个值
                    if (radNum < syZjNum)
                    {
                        //中奖了,再从剩余奖品里抽取一个奖品
                        Model.wx_dzpAwardItem dajiang = getZJItem(itemlist, auserlist);
                        if (dajiang != null)
                        {
                            //这是中的中奖了
                            string snumber = Get_snumber(aid);
                            int    uId     = ubll.Add(aid, "", "", openid, dajiang.jxName, dajiang.jpName, snumber);

                            jsonDict.Add("error", "succ");
                            jsonDict.Add("content", "恭喜你中奖了!");
                            jsonDict.Add("sortid", dajiang.sort_id.Value.ToString());
                            jsonDict.Add("jxname", dajiang.jxName);
                            jsonDict.Add("jpname", dajiang.jpName);
                            jsonDict.Add("uid", uId.ToString());
                            jsonDict.Add("sn", snumber);
                            context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                            return;
                        }
                        else
                        {
                            //奖品已经全部中完了
                            jsonDict.Add("error", "-1");
                            jsonDict.Add("content", dzpAction.cfcjhf);
                            context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                            return;
                        }
                    }
                    else
                    {
                        //这个条件说明:未中奖
                        //抛出未中奖的数据

                        jsonDict.Add("error", "-1");
                        jsonDict.Add("content", dzpAction.cfcjhf);
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }



                    #endregion
                }
                catch (Exception ex)
                {
                    jsonDict.Add("error", "sys");
                    jsonDict.Add("content", "计算抽奖出现未知错误,请联系管理员!");
                    context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                    return;
                }
            }
            else if (_action == "update")
            {
                try
                {
                    #region 提交手机
                    /// 提交手机号码
                    string tel     = MyCommFun.QueryString("tel");
                    string pwd     = MyCommFun.QueryString("pwd");
                    string snumber = MyCommFun.QueryString("snumber");
                    int    id      = MyCommFun.RequestInt("id");

                    if (aid == 0 || id == 0 || snumber == "" || tel == "")
                    {
                        context.Response.Write("{\"msg\":\"提交出现异常!!\",\"success\":\"0\"}");
                        return;
                    }

                    if ((pwd.Length > 0) && (!actbll.ExistsPwd(aid, pwd)))
                    {
                        context.Response.Write("{\"msg\":\"商家兑换密码错误!!\",\"success\":\"0\"}");
                        return;
                    }


                    BLL.wx_dzpAwardUser   ubll  = new BLL.wx_dzpAwardUser();
                    Model.wx_dzpAwardUser model = ubll.GetModel(id);
                    if (model == null)
                    {
                        context.Response.Write("{\"msg\":\"提交出现异常2!!\",\"success\":\"0\"}");
                        return;
                    }
                    model.uTel = tel;
                    if (pwd.Length > 0)
                    {
                        model.hasLingQu = true;
                    }
                    else
                    {
                        model.hasLingQu = false;
                    }
                    ubll.Update(model);

                    context.Response.Write("{\"msg\":\"提交成功!\",\"success\":\"1\"}");
                    return;

                    #endregion
                }
                catch
                {
                    context.Response.Write("{\"msg\":\"提交出现异常!!\",\"success\":\"0\"}");

                    return;
                }
            }
        }
예제 #8
0
        private void BindData()
        {
            dzpAction = actBll.GetModel(aid);
            IList<Model.wx_dzpAwardItem> itemlist = itemBll.GetModelList("actId=" + aid);
            if (dzpAction == null || itemlist == null || itemlist.Count <= 0)
            {
                ErrLevel = 1;
                ErrorInfo = "未获得到数据";
                return;
            }
            this.Title = dzpAction.actName;

            if (dzpAction.endDate <= DateTime.Now)
            {   //说明活动已经结束
                ErrLevel = 101;
                ErrorInfo = "活动已结束";
                return;
            }

            StringBuilder sb = new StringBuilder("");
            Model.wx_dzpAwardItem item = new Model.wx_dzpAwardItem();
            int ttJpNum = 0;
            shuzu = "[";
            for (int i = 0; i < itemlist.Count; i++)
            {
                item = itemlist[i];
                sb.Append("<p>" + item.jxName + ":" + item.jpName + "  数量:" + item.jpNum + "</p>");
                ttJpNum += item.jpRealNum.Value;
                picIndex++;
                if (i < (itemlist.Count - 1))
                {
                    shuzu += item.jiaodu_min + ",";
                }
                else
                {
                    shuzu += item.jiaodu_min;
                }
            }
            shuzu += "]";
            litJiangXing.Text = sb.ToString();
            litRemark.Text = dzpAction.brief;
            litContentInfo.Text = dzpAction.contractInfo;

            littotTimes.Text = dzpAction.personMaxTimes == null ? "0" : dzpAction.personMaxTimes.Value.ToString();
            litdaysTimes.Text = dzpAction.dayMaxTimes == null ? "0" : dzpAction.dayMaxTimes.Value.ToString();
            if (dzpAction.djPwd.Trim().Length > 0)
            {
                litPwd.Text = "  <p>  <input name=\"\" class=\"px\" id=\"parssword\" type=\"password\" value=\"\" placeholder=\"商家输入兑奖密码\"></p>";
            }
            if (dzpAction.beginDate > DateTime.Now)
            {
                hidStatus.Value = "-2";
                ErrorInfo = hidErrInfo.Value = "活动尚未开始";
            }
            int hasCjTimes = utbll.getCJCiShu(aid, openid);//返回该用户的抽奖次数
            this.litHasUsedTimes.Text = hasCjTimes.ToString();

            int dayMaxTimes = dzpAction.dayMaxTimes == null ? 0 : dzpAction.dayMaxTimes.Value;
            int perMaxTimes = dzpAction.personMaxTimes == null ? 0 : dzpAction.personMaxTimes.Value;
            //判断是否中奖了

            Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
            if (award != null && award.id>0)
            {    //您中奖了
                if (award.uTel != null && award.uTel.ToString().Trim() != "")
                {//已经中奖,并且提交了
                    litJp.Text = "[" + award.jxName + "] " + award.jpName;
                    litSNM.Text = award.sn;
                    isZhJing = true;
                }
                else
                { //已经中奖,但是未提交
                    hidStatus.Value = "100";
                    litzjlJP.Text = "[" + award.jxName + "] " + award.jpName;
                    litzjlSN.Text = award.sn;
                    hidAwardId.Value = award.id.ToString();

                    litJp.Text = "[" + award.jxName + "] " + award.jpName;
                    litSNM.Text = award.sn;
                }

            }
            else
            {
                //判断每人最大抽奖次数,是否超过了
                if (hasCjTimes >= dzpAction.personMaxTimes)
                {
                  hidStatus.Value = "2";
                  litOtherTip.Text = "<p class='red'>您已经抽了" + hasCjTimes + "次了。</p>";
                }
                if (isTodayOverSum(dayMaxTimes))
                {
                    hidStatus.Value = "2";
                    litOtherTip.Text = "<p class='red'>每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会,您已经使用完了。</p>";
                }

            }
        }