溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能

發(fā)布時(shí)間:2021-07-14 15:05:41 來(lái)源:億速云 閱讀:295 作者:小新 欄目:移動(dòng)開(kāi)發(fā)

這篇文章主要為大家展示了“微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能”這篇文章吧。

一、使用

1. 新建一個(gè)大轉(zhuǎn)盤(pán)的活動(dòng):

微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能

2. 獎(jiǎng)項(xiàng)設(shè)置

微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能

3. 保存后,在微信里給公眾號(hào)發(fā)一個(gè)“大轉(zhuǎn)盤(pán)”的消息, 就會(huì)收到大轉(zhuǎn)盤(pán)的內(nèi)容

微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能

4. 點(diǎn)擊進(jìn)入大轉(zhuǎn)盤(pán)活動(dòng),然后點(diǎn)擊中間的 “點(diǎn)擊抽獎(jiǎng)”:

微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能  微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能

二、實(shí)現(xiàn)

1. 頁(yè)面

1.1 前臺(tái)代碼
<% if (ErrLevel < 100)
   {
       Response.Write(ErrorInfo);
   }
   else if (ErrLevel == 101)
   {  //活動(dòng)已結(jié)束,跳轉(zhuǎn)到結(jié)束頁(yè)面
%>
<script type="text/javascript">
    window.location.href = "end.aspx?wid="+<%=wid%>+"&aid="+<%=aid%>+"&openid="+<%=openid%>+";";
</script>
<%
   }
   else
   {  %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="微信">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>幸運(yùn)大轉(zhuǎn)盤(pán)抽獎(jiǎng)</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../scripts/jquery/jquery.query.js"></script>
    <script src="../../scripts/jquery/alert.js" type="text/javascript"></script>
    <link href="css/activity-style2.css" rel="stylesheet" type="text/css">
    <style>
        .activity-lottery-winning {
            background: url(images/beijing.gif) repeat scroll 0 0 #7E65AB;
            background-size: 120px auto;
            overflow: hidden;
        }
    </style>
</head>
<body class="activity-lottery-winning">
    <form id="form1" runat="server">
        <p class="main">

            <asp:HiddenField ID="hidStatus" runat="server" Value="" EnableViewState="false" />
            <asp:HiddenField ID="hidErrInfo" runat="server" EnableViewState="false" />
            <asp:HiddenField ID="hidAwardId" runat="server" EnableViewState="false" Value="0" />
            <p id="outercont">
                <p id="outer-cont">
                    <p id="outer">
                        <img src="images/zp<%=picIndex %>-.png">
                    </p>
                </p>
                <p id="inner-cont">
                    <p id="inner">
                        <img src="images/activity-lottery-2.png">
                    </p>
                </p>
            </p>
            <p class="content">
                <p class="boxcontent boxwhite" id="zjl" style="display: none">
                    <p class="box">
                        <p class="title-orange"><span>恭喜你中獎(jiǎng)了</span></p>
                        <p class="Detail">

                            <p>你中了:<span class="red" id="prizetype"><asp:Literal ID="litzjlJP" runat="server" EnableViewState="false" Text=""></asp:Literal></span></p>
                            <p>兌獎(jiǎng)SN碼:<span class="red" id="sncode"><asp:Literal ID="litzjlSN" runat="server" EnableViewState="false" Text=""></asp:Literal></span></p>
                            <p class="red">
                                <asp:Literal ID="litContentInfo" runat="server" EnableViewState="false"></asp:Literal>
                            </p>
                            <p>
                                <input name="" class="px" id="tel" value="" type="text" placeholder="用戶(hù)請(qǐng)輸入您的手機(jī)號(hào)">
                            </p>

                            <asp:Literal ID="litPwd" runat="server" EnableViewState="false" Text=""></asp:Literal>
                            <p>
                                <input class="pxbtn" name="提 交" id="save-btn" type="button" value="用戶(hù)提交">
                            </p>
                        </p>
                    </p>
                </p>
                <p class="boxcontent boxwhite" id="result" style="display: none;">
                    <p class="box">
                        <p class="title-orange"><span>恭喜你中獎(jiǎng)了</span></p>
                        <p class="Detail">
                            <p>你中了:<span class="red" id="jiangping"><asp:Literal ID="litJp" runat="server" EnableViewState="false" Text=""></asp:Literal></span></p>
                            <p>兌獎(jiǎng)sn碼為:<span class="red" id="jpsn"><asp:Literal ID="litSNM" runat="server" EnableViewState="false"></asp:Literal></span></p>
                            <p class="red">你已經(jīng)兌獎(jiǎng)成功,本SN碼自定作廢!</p>
                        </p>


                    </p>
                </p>



                <p class="boxcontent boxwhite">
                    <p class="box">
                        <p class="title-red"><span>獎(jiǎng)項(xiàng)設(shè)置:</span></p>

                        <p class="Detail">
                            <asp:Literal ID="litOtherTip" runat="server" EnableViewState="false"></asp:Literal>
                            <asp:Literal ID="litJiangXing" runat="server" EnableViewState="false"></asp:Literal>
                        </p>
                    </p>
                </p>
                <p class="boxcontent boxwhite">
                    <p class="box">
                        <p class="title-red">活動(dòng)說(shuō)明:</p>
                        <p class="Detail">
                            <p class="red">
                                本次活動(dòng)每天可以轉(zhuǎn)
                            <asp:Literal ID="litdaysTimes" runat="server" EnableViewState="false"></asp:Literal>
                                次,總共可以轉(zhuǎn) 
                            <asp:Literal ID="littotTimes" runat="server" EnableViewState="false"></asp:Literal>
                                次 你已經(jīng)轉(zhuǎn)了 <span id="zhuantimes">
                                    <asp:Literal ID="litHasUsedTimes" runat="server" EnableViewState="false"></asp:Literal></span> 次
                            </p>
                            <p>
                                <asp:Literal ID="litRemark" runat="server" EnableViewState="false"></asp:Literal>
                            </p>
                        </p>
                    </p>
                </p>
            </p>

        </p>


        <script type="text/javascript">
            var thisurl= document.URL;
            var wid = <%=wid%>;
            var aid =<%=aid%>;
            var status = $("#hidStatus").val();
            var showInfo = $("#hidErrInfo").val();
            var openid ="<%=openid%>";
            var jxname="";
            var jpname="";
            var cjtip="";
            var zhuantimes=parseInt( $("#zhuantimes").text());
             
            var zjl = false;//沒(méi)中獎(jiǎng)為false中獎(jiǎng)為true 
            <% if (isZhJing)
               { %>
            $("#outercont").hide();
            $("#result").show();
               <%} %>
            if (status == "2") {
                $("#outercont").hide();

            }
            else if(status=="100")
            {
                $("#outercont").hide();
                $("#result").hide();
                $("#zjl").show();
            }


            $(function () {
                window.requestAnimFrame = (function () {
                    return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
                    function (callback) {
                        window.setTimeout(callback, 1000 / 60)
                    }
                })();
                var totalDeg = 360 * 3 + 0;
                var steps = [];
               
                var lostDeg = [360];
                var prizeDeg = <%=shuzu%>;
                var prize, sncode;
                var count = 0;
                var now = 0;
                var a = 0.01;
                var outter, inner, timer, running = false;
                function countSteps() {
                    var t = Math.sqrt(2 * totalDeg / a);
                    var v = a * t;
                    for (var i = 0; i < t; i++) {
                        steps.push((2 * v * i - a * i * i) / 2)
                    }
                    steps.push(totalDeg)
                }
                function step() {
                    // alert('rotate(' + steps[now++] + 'deg)');
                    outter.style.webkitTransform = 'rotate(' + steps[now++] + 'deg)';
                    outter.style.MozTransform = 'rotate(' + steps[now++] + 'deg)';

                    if (now < steps.length) {
                        running = true;
                        requestAnimFrame(step)
                    } else {
                        running = false;
                        setTimeout(function () {
                            $("#zhuantimes").text(++zhuantimes);
                            if (zjl) {
                                $("#sncode").text(sncode);
                                $("#jpsn").text(sncode);
                                $("#jiangping").text(jxname+" "+jpname);
                                $("#prizetype").text(jxname+" "+jpname);
                                $("#zjl").slideToggle(500);
                                $("#outercont").slideUp(500)
                            }  
                            else
                            {
                                alert(cjtip);
                            }
                        },
                        200)
                    }
                }

                function start(deg) {

                    deg = deg || lostDeg[parseInt(lostDeg.length * Math.random())];
                    running = true;
                    clearInterval(timer);
                    totalDeg = 360 * 5 + deg;
                    steps = [];
                    now = 0;
                    countSteps();
                    requestAnimFrame(step)
                }
                window.start = start;
                outter = document.getElementById('outer');
                inner = document.getElementById('inner');
                i = 10;
                $("#inner").click(function () {
                    if (status == "2") {
                        alert(showInfo);
                    }
                    if (running) return;
                   
                    $.ajax({
                        url: "dzpAct.ashx",
                        dataType: "json",
                        data: {
                            openid: openid,
                            myact: "choujiang",
                            aid: aid,
                            wid:wid,
                            rad: Math.random()
                        },
                        beforeSend: function () {
                            running = true;
                            timer = setInterval(function () {
                                i += 5;
                              
                                outter.style.webkitTransform = 'rotate(' + i + 'deg)';
                                outter.style.MozTransform = 'rotate(' + i + 'deg)'
                            },
                            1)
                        },
                        success: function (data) {
                            if (data.error == "sys" ||data.error == "nostart" ) {
                                cjtip=data.content;
                                count = 100;
                                clearInterval(timer);
                                return
                            }
                            else if(data.error=="notimes")
                            {
                                cjtip=data.content;
                                start();
                            }
                            else if (data.error=="succ") {
                                
                                zjl=true;
                                cjtip=data.content;
                                prize = data.sortid;
                                sncode = data.sn;
                                jpname=data.jpname;
                                jxname=data.jxname;
                                $("#hidAwardId").val(data.uid);
                                start(prizeDeg[data.sortid - 1])
                            }
                            
                            else {
                                cjtip=data.content;
                                start()
                            }
                            running = false;
                            count++
                        },
                        error: function () {

                            prize = null;
                            start();
                            running = false;
                            count++
                        },
                        timeout: 1000
                    })
                })
            });

            $("#save-btn").bind("click",
            function () {
                var btn = $(this);
              
                var tel = $("#tel").val();
                var pwd = "";
                var hidAwardId = $("#hidAwardId").val();
                if ($("#parssword").length>0 &&  $.trim($("#parssword").val()) == "") {
                    alert("請(qǐng)輸入兌獎(jiǎng)密碼!");
                    return
                }

                if ($.trim(tel) == "") {
                    alert("請(qǐng)輸入手機(jī)號(hào)!");
                    return
                }
                if($("#parssword").length>0){
                    pwd= $("#parssword").val();
                }
                var rad = Math.random();
                 
                var submitData = {
                    id: hidAwardId,
                    aid: aid,
                    pwd: pwd,
                    snumber:$("#sncode").text(),
                    tel: tel,
                    rad: rad,
                    openid:openid
                };
                 
                $.post('dzpAct.ashx?myact=update', submitData,
               function (data) {
                   if (data.success == "1") {
                       alert("提交成功!");
                       $("#result").slideToggle(500);
                       $("#zjl").slideToggle(500);
                       $("#outercont").slideUp(500);

                   } else {
                       alert(data.msg);
                   }
               },
               "json") 

            });

           
        </script>
        <script type="text/javascript">
            document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
                window.shareData = {
                    "imgUrl": "",
                    "timeLineLink":  thisurl + "&is_share=1",
                    "sendFriendLink":  thisurl + "&is_share=1",
                    "weiboLink":  thisurl + "&is_share=1",
                    "tTitle": "<%=dzpAction.actName%>",
                    "tContent": "請(qǐng)關(guān)注后,再來(lái)抽獎(jiǎng)。<%=dzpAction.brief%>",
                    "fTitle": "請(qǐng)關(guān)注后,再來(lái)抽獎(jiǎng)。<%=dzpAction.actName%>",
                    "fContent": "請(qǐng)關(guān)注后,再來(lái)抽獎(jiǎng)。<%=dzpAction.brief%>",
                    "wContent": "請(qǐng)關(guān)注后,再來(lái)抽獎(jiǎng)。<%=dzpAction.brief%>"
                };
                // 發(fā)送給好友
                WeixinJSBridge.on('menu:share:appmessage', function (argv) {
                    WeixinJSBridge.invoke('sendAppMessage', {
                        "img_url": window.shareData.imgUrl,
                        "img_width": "640",
                        "img_height": "640",
                        "link": window.shareData.sendFriendLink,
                        "desc": window.shareData.fContent,
                        "title": window.shareData.fTitle
                    }, function (res) {
                        _report('send_msg', res.err_msg);
                    })
                });

                // 分享到朋友圈
                WeixinJSBridge.on('menu:share:timeline', function (argv) {
                    WeixinJSBridge.invoke('shareTimeline', {
                        "img_url": window.shareData.imgUrl,
                        "img_width": "640",
                        "img_height": "640",
                        "link": window.shareData.timeLineLink,
                        "desc": window.shareData.tContent,
                        "title": window.shareData.tTitle
                    }, function (res) {
                        _report('timeline', res.err_msg);
                    });
                });

                // 分享到微博
                WeixinJSBridge.on('menu:share:weibo', function (argv) {
                    WeixinJSBridge.invoke('shareWeibo', {
                        "content": window.shareData.wContent,
                        "url": window.shareData.weiboLink,
                    }, function (res) {
                        _report('weibo', res.err_msg);
                    });
                });
            }, false)
        </script>


    </form>
      <p style="display: none">?微布斯科技提供 qq 121285904 www.webus.cn</p>

</body>
</html>
<% }%>
2.1  后臺(tái)代碼
/// <summary>
      /// ErrLevel:100表示正確無(wú)誤,1表示嚴(yán)重錯(cuò)誤,2表示業(yè)務(wù)方面有問(wèn)題;3直接跳轉(zhuǎn)到結(jié)束頁(yè)面
      /// </summary>
      public int ErrLevel = 100;
      public string ErrorInfo = "";
      public  Model.wx_dzpActionInfo dzpAction;
      public int picIndex = 0;
      public int aid = 0;
      public int wid = 0;
      public bool isZhJing = false;
      public string openid = "";
      public string shuzu = "";
      BLL.wx_dzpAwardUser ubll = new BLL.wx_dzpAwardUser();
      BLL.wx_dzpUsersTemp utbll = new BLL.wx_dzpUsersTemp();
      BLL.wx_dzpActionInfo actBll = new BLL.wx_dzpActionInfo();
      BLL.wx_dzpAwardItem itemBll = new BLL.wx_dzpAwardItem();
 
      protected void Page_Load(object sender, EventArgs e)
      {
          OnlyWeiXinLook();
          aid = MyCommFun.RequestInt("aid", 0);
          wid = MyCommFun.RequestInt("wid", 0);
          openid = MyCommFun.RequestOpenid();
 
          if (aid == 0 || wid == 0 || openid.Trim() == "")
          {
              ErrLevel = 1;
              ErrorInfo = "訪(fǎng)問(wèn)參數(shù)錯(cuò)誤!";
              return;
          }
          BindData();
      }
 
 
      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 = "未獲得到數(shù)據(jù)";
              return;
          }
          this.Title = dzpAction.actName;
 
          if (dzpAction.endDate <= DateTime.Now)
          {   //說(shuō)明活動(dòng)已經(jīng)結(jié)束
              ErrLevel = 101;
              ErrorInfo = "活動(dòng)已結(jié)束";
              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 + "  數(shù)量:" + 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=\"商家輸入兌獎(jiǎng)密碼\"></p>";
          }
          if (dzpAction.beginDate > DateTime.Now)
          {
              hidStatus.Value = "-2";
              ErrorInfo = hidErrInfo.Value = "活動(dòng)尚未開(kāi)始";
          }
          int hasCjTimes = utbll.getCJCiShu(aid, openid);//返回該用戶(hù)的抽獎(jiǎng)次數(shù)
          this.litHasUsedTimes.Text = hasCjTimes.ToString();
          int dayMaxTimes = dzpAction.dayMaxTimes == null ? 0 : dzpAction.dayMaxTimes.Value;
          int perMaxTimes = dzpAction.personMaxTimes == null ? 0 : dzpAction.personMaxTimes.Value;
          //判斷是否中獎(jiǎng)了
          Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
          if (award != null && award.id>0)
          {    //您中獎(jiǎng)了
              if (award.uTel != null && award.uTel.ToString().Trim() != "")
              {//已經(jīng)中獎(jiǎng),并且提交了
                  litJp.Text = "[" + award.jxName + "] " + award.jpName;
                  litSNM.Text = award.sn;
                  isZhJing = true;
              }
              else
              { //已經(jīng)中獎(jiǎng),但是未提交
                  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
          {
              //判斷每人最大抽獎(jiǎng)次數(shù),是否超過(guò)了
              if (hasCjTimes >= dzpAction.personMaxTimes)
              {
                hidStatus.Value = "2";
                //litOtherTip.Text = "<p class='red'>您已經(jīng)抽了" + hasCjTimes + "次了。</p>";
              }
              if (isTodayOverSum(dayMaxTimes))
              {
                  hidStatus.Value = "2";
                 // litOtherTip.Text = "<p class='red'>每人每天只有" + dayMaxTimes.ToString() + "次抽獎(jiǎng)機(jī)會(huì),您已經(jīng)使用完了。</p>";
              }
          }
      }
      #region 方法
      /// <summary>
      /// 判斷今天是否已經(jīng)超出抽獎(jiǎng)次數(shù)
      /// todayTTTimes:能抽獎(jiǎng)的總次數(shù)
      /// </summary>
      /// <param name="openid"></param>
      /// <param name="todayTTTimes">每天的抽獎(jiǎng)總次數(shù)</param>
      /// <returns></returns>
      private bool isTodayOverSum( int todayTTTimes)
      {
          if (todayTTTimes <= 0)
          {
              return true;
          }
 
          DateTime todaybegin = DateTime.Parse(DateTime.Now.ToShortDateString());
          DateTime mingtianBegin = todaybegin.AddDays(1);
          if (!utbll.ExistsOpenid(" actId=" + aid + "  and  openid='" + openid + "' and  createDate>='" + todaybegin + "' and createDate<'" + mingtianBegin + "'"))
          {
              return false;
 
          }
 
          Model.wx_dzpUsersTemp model = utbll.getModelByAidOpenid(aid, openid);
          if (model.times >= todayTTTimes)
          {
              return true;
          }
          else
          {
              
              return false;
          }
 
      }
 
      #endregion

undefined

2. 實(shí)現(xiàn)邏輯

undefined

public class dzpAct : IHttpHandler
    {
        BLL.wx_dzpActionInfo actbll = new BLL.wx_dzpActionInfo();
        BLL.wx_dzpAwardUser ubll = new BLL.wx_dzpAwardUser();
        BLL.wx_dzpUsersTemp utbll = new BLL.wx_dzpUsersTemp();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            string _action = MyCommFun.QueryString("myact");
            int aid = MyCommFun.RequestInt("aid");
            string openid = MyCommFun.RequestOpenid();  //得到微信用戶(hù)的openid
            if (_action == "choujiang")
            {
                Dictionary<string, string> jsonDict = new Dictionary<string, string>();
                try
                {
                    //抽獎(jiǎng)
                    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", "參數(shù)錯(cuò)誤!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    dzpAction = actbll.GetModel(aid);
                    if (dzpAction == null)
                    {
                        jsonDict.Add("error", "sys");
                        jsonDict.Add("content", "參數(shù)錯(cuò)誤!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    if (dzpAction.endDate <= DateTime.Now)
                    { //說(shuō)明活動(dòng)已經(jīng)結(jié)束
                        //非活動(dòng)期間
                        jsonDict.Add("error", "end");
                        jsonDict.Add("content", "活動(dòng)已結(jié)束");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    else if (dzpAction.beginDate > DateTime.Now)
                    {
                        //活動(dòng)未開(kāi)始
                        //非活動(dòng)期間
                        jsonDict.Add("error", "nostart");
                        jsonDict.Add("content", "活動(dòng)未開(kāi)始");
                        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;
                    //判斷每人最大抽獎(jiǎng)次數(shù),是否超過(guò)了
                    if (personCJTimes(openid, aid) >= dzpAction.personMaxTimes)
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您已抽過(guò)獎(jiǎng)了,歡迎下次再來(lái)!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    if (isTodayOverSum(aid, openid, dayMaxTimes))
                    {
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "每人每天只有" + dayMaxTimes.ToString() + "次抽獎(jiǎng)機(jī)會(huì)。");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    Model.wx_dzpAwardUser award = ubll.getZJinfoByOpenid(aid, openid);
                    if (award != null)
                    {
                        //您中獎(jiǎng)了
                        jsonDict.Add("error", "notimes");
                        jsonDict.Add("content", "您中獎(jiǎng)了,歡迎下次再來(lái)!");
                        context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                        return;
                    }
                    #endregion
                    #region 計(jì)算中獎(jiǎng)信息
                    /// 處理是否中獎(jiǎng)
                    /// hidStatus 狀態(tài)為-1:不能抽獎(jiǎng),直接跳轉(zhuǎn)到end.aspx頁(yè)面;
                    /// 0:抽獎(jiǎng)次數(shù)超過(guò)設(shè)置的最高次數(shù);
                    /// 1:還可以繼續(xù)抽獎(jiǎng);
                    /// 2:中獎(jiǎng)了;
                    List<Model.wx_dzpAwardItem> itemlist = itemBll.GetModelList("actId=" + aid);//該活動(dòng)的所有獎(jiǎng)項(xiàng)信息
                    int ttJpNum = 0;
                    for (int i = 0; i < itemlist.Count; i++)
                    {
                        ttJpNum += itemlist[i].jpRealNum.Value;
                    }
                    IList<Model.wx_dzpAwardUser> auserlist = ubll.getHasZJList(aid);//已經(jīng)中獎(jiǎng)的人列表
                    int ZhongJiangNum = 0;
                    if (auserlist != null)
                    {
                        ZhongJiangNum = auserlist.Count; //已經(jīng)中獎(jiǎng)的人數(shù)
                    }
                    int syZjNum = ttJpNum - ZhongJiangNum; //剩余的獎(jiǎng)品數(shù)量
                    if (syZjNum <= 0)
                    {  //說(shuō)明已經(jīng)沒(méi)有獎(jiǎng)品了
                        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里隨機(jī)出一個(gè)值
                    if (radNum < syZjNum)
                    {
                        //中獎(jiǎng)了,再?gòu)氖S嗒?jiǎng)品里抽取一個(gè)獎(jiǎng)品
                        Model.wx_dzpAwardItem dajiang = getZJItem(itemlist, auserlist);
                        if (dajiang != null)
                        {
                            //這是中的中獎(jiǎng)了
                            string snumber = Get_snumber(aid);
                            int uId = ubll.Add(aid, "", "", openid, dajiang.jxName, dajiang.jpName, snumber);
 
                            jsonDict.Add("error", "succ");
                            jsonDict.Add("content", "恭喜你中獎(jiǎng)了!");
                            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
                        {
                            //獎(jiǎng)品已經(jīng)全部中完了
                            jsonDict.Add("error", "-1");
                            jsonDict.Add("content", dzpAction.cfcjhf);
                            context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                            return;
                        }
                    }
                    else
                    {
                        //這個(gè)條件說(shuō)明:未中獎(jiǎng)
                        //拋出未中獎(jiǎng)的數(shù)據(jù)
 
                        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", "計(jì)算抽獎(jiǎng)出現(xiàn)未知錯(cuò)誤,請(qǐng)聯(lián)系管理員!");
                    context.Response.Write(MyCommFun.getJsonStr(jsonDict));
                    return;
                }
            }
            else if (_action == "update")
            {
                try
                {
                    #region 提交手機(jī)
                    /// 提交手機(jī)號(hào)碼
                    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\":\"提交出現(xiàn)異常??!\",\"success\":\"0\"}");
                        return;
                    }
 
                    if ((pwd.Length>0) &&( !actbll.ExistsPwd(aid, pwd)))
                    {
                        context.Response.Write("{\"msg\":\"商家兌換密碼錯(cuò)誤??!\",\"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\":\"提交出現(xiàn)異常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\":\"提交出現(xiàn)異常??!\",\"success\":\"0\"}");
 
                    return;
                }
            }
        }
        #region 方法
        /// <summary>
        /// 取中獎(jiǎng)的項(xiàng)目
        /// </summary>
        /// <param name="itemlist">所有的獎(jiǎng)品信息</param>
        /// <param name="haszjlist">已經(jīng)中獎(jiǎng)的列表</param>
        /// <returns></returns>
        private Model.wx_dzpAwardItem getZJItem(IList<Model.wx_dzpAwardItem> itemlist, IList<Model.wx_dzpAwardUser> haszjlist)
        {
            IList<Model.wx_dzpAwardItem> zjItemlist = new List<Model.wx_dzpAwardItem>();//剩余獎(jiǎng)品列表
            Model.wx_dzpAwardItem tmpItem = new Model.wx_dzpAwardItem();
            Model.wx_dzpAwardItem stmpItem = new Model.wx_dzpAwardItem();
            IList<Model.wx_dzpAwardUser> thiszjRs;
            for (int i = 0; i < itemlist.Count; i++)
            {
                tmpItem = itemlist[i];
                thiszjRs = (from user in haszjlist where user.jpName == tmpItem.jpName && user.jxName == tmpItem.jxName select user).ToArray<Model.wx_dzpAwardUser>();
                int tmpSYNum = 0;
                if (thiszjRs != null)
                {
                    tmpSYNum = MyCommFun.Obj2Int(tmpItem.jpRealNum) - thiszjRs.Count;
                }
                if (tmpSYNum <= 0)
                {
                    continue;
                }
                for (int j = 0; j < tmpSYNum; j++)
                {
                    stmpItem = new Model.wx_dzpAwardItem();
                    stmpItem.jpName = tmpItem.jpName;
                    stmpItem.jxName = tmpItem.jxName;
                    stmpItem.sort_id = tmpItem.sort_id;
                    zjItemlist.Add(stmpItem);
                }
            }
            Random rd = new Random((int)DateTime.Now.Ticks);
            int jpIndex = rd.Next(0, zjItemlist.Count);//從0到zjItemlist.Count里隨機(jī)出一個(gè)值
            return zjItemlist[jpIndex];
        }
        /// <summary>
        /// 判斷該用戶(hù)的抽獎(jiǎng)次數(shù)
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        private int personCJTimes(string openid, int aid)
        {
            int times = 0;
            times = utbll.GetRecordCount("actId=" + aid + " and openid='" + openid + "'");
            return times;
        }
        /// <summary>
        /// 判斷今天是否已經(jīng)超出抽獎(jiǎng)次數(shù)
        /// todayTTTimes:能抽獎(jiǎng)的總次數(shù)
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="todayTTTimes">每天的抽獎(jiǎng)總次數(shù)</param>
        /// <returns></returns>
        private bool isTodayOverSum(int aid, string openid, int todayTTTimes)
        {
            if (todayTTTimes <= 0)
            {
                return true;
            }
            Model.wx_dzpUsersTemp model = new Model.wx_dzpUsersTemp();
            model.openid = openid;
            DateTime todaybegin = DateTime.Parse(DateTime.Now.ToShortDateString());
            DateTime mingtianBegin = todaybegin.AddDays(1);
            if (!utbll.ExistsOpenid(" actId=" + aid + "  and  openid='" + openid + "' and  createDate>='" + todaybegin + "' and createDate<'" + mingtianBegin + "'"))
            { //第一次,插入
                model.times = 1;
                model.createDate = DateTime.Now;
                model.openid = openid;
                model.actId = aid;
                utbll.Add(model);
                return false;
            }
            model = utbll.getModelByAidOpenid(aid, openid);
            if (model.times >= todayTTTimes)
            {
                return true;
            }
            else
            {
                model.times += 1;
                utbll.Update(model);
                return false;
            }
        }
        /// <summary>
        /// 返回中獎(jiǎng)序列號(hào)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string Get_snumber(int aid)
        {
            Random rd = new Random((int)DateTime.Now.Ticks);
            int radNum = rd.Next(0, 9);//從0到9里隨機(jī)出一個(gè)值
 
            return "SNdzp" + aid + "_" + MyCommFun.ConvertDateTimeInt(DateTime.Now) + radNum;
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

以上是“微信開(kāi)發(fā)中如何實(shí)現(xiàn)大轉(zhuǎn)盤(pán)功能”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI