目錄
一、使用
1. 新建一個大唱盤的活動:
2 . 獎項設定
3. 儲存後,在微信裡給公眾號發一個「大轉盤」的訊息,就會收到大轉盤的內容
4. 點選進入大唱盤活動,然後點選中間的「點選抽獎」:
二、實作
1. 頁面
1.1 前台程式碼
2.1  後台程式碼
首頁 微信小程式 微信開發 微信開發之大轉盤功能

微信開發之大轉盤功能

May 08, 2017 am 11:13 AM

微信行銷是一種新型的行銷模式,由於微信更重視用戶之間的互動,故而這種行銷推廣不不能盲目地套用微博行銷的單純大量廣告推播方式。這種方式在微信行銷的效果非常差,會令用戶反感,進而取消去企業或商家的微信大眾帳號追蹤。對企業來說,做微信推廣重要的一個面向就是提高使用者和公眾帳號之間的黏度,而微信大轉盤就是其中最常見的活動。

下面詳細介紹:

一、使用

1. 新建一個大唱盤的活動:

微信開發之大轉盤功能

2 . 獎項設定

微信開發之大轉盤功能

3. 儲存後,在微信裡給公眾號發一個「大轉盤」的訊息,就會收到大轉盤的內容

微信開發之大轉盤功能

4. 點選進入大唱盤活動,然後點選中間的「點選抽獎」:

 微信開發之大轉盤功能  微信開發之大轉盤功能 

二、實作

1. 頁面

1.1 前台程式碼
<% if (ErrLevel < 100)
   {
       Response.Write(ErrorInfo);
   }
   else if (ErrLevel == 101)
   {  //活动已结束,跳转到结束页面
%>
<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>幸运大转盘抽奖</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(微信開發之大轉盤功能s/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="/static/imghw/default1.png"  data-src="微信開發之大轉盤功能s/zp<%=picIndex % alt="微信開發之大轉盤功能" >-.png"  class="lazy"  >
                    </p>
                </p>
                <p id="inner-cont">
                    <p id="inner">
                        <img  src="/static/imghw/default1.png"  data-src="微信開發之大轉盤功能s/activity-lottery-2.png"  class="lazy"   alt="微信開發之大轉盤功能" >
                    </p>
                </p>
            </p>
            <p class="content">
                <p class="boxcontent boxwhite" id="zjl" style="display: none">
                    <p class="box">
                        <p class="title-orange"><span>恭喜你中奖了</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>兑奖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="用户请输入您的手机号">
                            </p>

                            <asp:Literal ID="litPwd" runat="server" EnableViewState="false" Text=""></asp:Literal>
                            <p>
                                <input class="pxbtn" name="提 交" id="save-btn" type="button" value="用户提交">
                            </p>
                        </p>
                    </p>
                </p>
                <p class="boxcontent boxwhite" id="result" style="display: none;">
                    <p class="box">
                        <p class="title-orange"><span>恭喜你中奖了</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>兑奖sn码为:<span class="red" id="jpsn"><asp:Literal ID="litSNM" runat="server" EnableViewState="false"></asp:Literal></span></p>
                            <p class="red">你已经兑奖成功,本SN码自定作废!</p>
                        </p>


                    </p>
                </p>



                <p class="boxcontent boxwhite">
                    <p class="box">
                        <p class="title-red"><span>奖项设置:</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">活动说明:</p>
                        <p class="Detail">
                            <p class="red">
                                本次活动每天可以转
                            <asp:Literal ID="litdaysTimes" runat="server" EnableViewState="false"></asp:Literal>
                                次,总共可以转 
                            <asp:Literal ID="littotTimes" runat="server" EnableViewState="false"></asp:Literal>
                                次 你已经转了 <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;//没中奖为false中奖为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(&#39;rotate(&#39; + steps[now++] + &#39;deg)&#39;);
                    outter.style.webkitTransform = &#39;rotate(&#39; + steps[now++] + &#39;deg)&#39;;
                    outter.style.MozTransform = &#39;rotate(&#39; + steps[now++] + &#39;deg)&#39;;

                    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(&#39;outer&#39;);
                inner = document.getElementById(&#39;inner&#39;);
                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 = &#39;rotate(&#39; + i + &#39;deg)&#39;;
                                outter.style.MozTransform = &#39;rotate(&#39; + i + &#39;deg)&#39;
                            },
                            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("请输入兑奖密码!");
                    return
                }

                if ($.trim(tel) == "") {
                    alert("请输入手机号!");
                    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(&#39;dzpAct.ashx?myact=update&#39;, 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(&#39;WeixinJSBridgeReady&#39;, function onBridgeReady() {
                window.shareData = {
                    "imgUrl": "",
                    "timeLineLink":  thisurl + "&is_share=1",
                    "sendFriendLink":  thisurl + "&is_share=1",
                    "weiboLink":  thisurl + "&is_share=1",
                    "tTitle": "<%=dzpAction.actName%>",
                    "tContent": "请关注后,再来抽奖。<%=dzpAction.brief%>",
                    "fTitle": "请关注后,再来抽奖。<%=dzpAction.actName%>",
                    "fContent": "请关注后,再来抽奖。<%=dzpAction.brief%>",
                    "wContent": "请关注后,再来抽奖。<%=dzpAction.brief%>"
                };
                // 发送给好友
                WeixinJSBridge.on(&#39;menu:share:appmessage&#39;, function (argv) {
                    WeixinJSBridge.invoke(&#39;sendAppMessage&#39;, {
                        "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(&#39;send_msg&#39;, res.err_msg);
                    })
                });

                // 分享到朋友圈
                WeixinJSBridge.on(&#39;menu:share:timeline&#39;, function (argv) {
                    WeixinJSBridge.invoke(&#39;shareTimeline&#39;, {
                        "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(&#39;timeline&#39;, res.err_msg);
                    });
                });

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


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

</body>
</html>
<% }%>
登入後複製
2.1  後台程式碼
/// <summary>
      /// ErrLevel:100表示正确无误,1表示严重错误,2表示业务方面有问题;3直接跳转到结束页面
      /// </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 = "访问参数错误!";
              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 = "未获得到数据";
              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=&#39;red&#39;>您已经抽了" + hasCjTimes + "次了。</p>";
              }
              if (isTodayOverSum(dayMaxTimes))
              {
                  hidStatus.Value = "2";
                 // litOtherTip.Text = "<p class=&#39;red&#39;>每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会,您已经使用完了。</p>";
              }
          }
      }
      #region 方法
      /// <summary>
      /// 判断今天是否已经超出抽奖次数
      /// todayTTTimes:能抽奖的总次数
      /// </summary>
      /// <param name="openid"></param>
      /// <param name="todayTTTimes">每天的抽奖总次数</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=&#39;" + openid + "&#39; and  createDate>=&#39;" + todaybegin + "&#39; and createDate<&#39;" + mingtianBegin + "&#39;"))
          {
              return false;
 
          }
 
          Model.wx_dzpUsersTemp model = utbll.getModelByAidOpenid(aid, openid);
          if (model.times >= todayTTTimes)
          {
              return true;
          }
          else
          {
              
              return false;
          }
 
      }
 
      #endregion
登入後複製

2. 實作邏輯

#
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();  //得到微信用户的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;
                }
            }
        }
        #region 方法
        /// <summary>
        /// 取中奖的项目
        /// </summary>
        /// <param name="itemlist">所有的奖品信息</param>
        /// <param name="haszjlist">已经中奖的列表</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>();//剩余奖品列表
            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里随机出一个值
            return zjItemlist[jpIndex];
        }
        /// <summary>
        /// 判断该用户的抽奖次数
        /// </summary>
        /// <param name="openid"></param>
        /// <returns></returns>
        private int personCJTimes(string openid, int aid)
        {
            int times = 0;
            times = utbll.GetRecordCount("actId=" + aid + " and openid=&#39;" + openid + "&#39;");
            return times;
        }
        /// <summary>
        /// 判断今天是否已经超出抽奖次数
        /// todayTTTimes:能抽奖的总次数
        /// </summary>
        /// <param name="openid"></param>
        /// <param name="todayTTTimes">每天的抽奖总次数</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=&#39;" + openid + "&#39; and  createDate>=&#39;" + todaybegin + "&#39; and createDate<&#39;" + mingtianBegin + "&#39;"))
            { //第一次,插入
                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>
        /// 返回中奖序列号
        /// </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里随机出一个值
 
            return "SNdzp" + aid + "_" + MyCommFun.ConvertDateTimeInt(DateTime.Now) + radNum;
        }
        #endregion
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
登入後複製

 【相關推薦】

1.微信公眾號平台原始碼下載

2.阿狸子訂單系統原始碼

以上是微信開發之大轉盤功能的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP微信開發:如何實作訊息加密解密 PHP微信開發:如何實作訊息加密解密 May 13, 2023 am 11:40 AM

PHP是一種開源的腳本語言,廣泛應用於網頁開發和伺服器端編程,尤其在微信開發中得到了廣泛的應用。如今,越來越多的企業和開發者開始使用PHP進行微信開發,因為它成為了真正的易學易用的開發語言。在微信開發中,訊息的加密和解密是一個非常重要的問題,因為它們涉及資料的安全性。對於沒有加密和解密方式的消息,駭客可以輕鬆取得其中的數據,對用戶造成威脅

H5PHP技術助力大轉盤抽獎活動創意 H5PHP技術助力大轉盤抽獎活動創意 Mar 04, 2024 pm 12:06 PM

在當今數位化時代,互動行銷活動被廣泛應用於企業的市場推廣中,其中大轉盤抽獎活動常被用來吸引用戶關注和參與。而結合H5和PHP技術,不僅可以增強抽獎活動的趣味性和即時性,還能提高用戶參與度和互動性,為企業的品牌行銷帶來更多機會。在這篇文章中,我們將介紹如何利用H5和PHP技術來打造一個創意十足的大轉盤抽獎活動,並提供具體的程式碼範例。 1.抽獎活動前端設計首先,

用PHP開發微信群發工具 用PHP開發微信群發工具 May 13, 2023 pm 05:00 PM

隨著微信的普及,越來越多的企業開始將其作為行銷工具。而微信群發功能,則是企業進行微信行銷的重要手段之一。但是,如果只依靠手動發送,對於行銷人員來說是一件極為費時費力的工作。所以,開發一款微信群發工具就顯得格外重要。本文將介紹如何使用PHP開發微信群發工具。一、準備工作開發微信群發工具,我們需要掌握以下幾個技術點:PHP基礎知識微信公眾平台開發開發工具:Sub

PHP微信開發:如何實現使用者標籤管理 PHP微信開發:如何實現使用者標籤管理 May 13, 2023 pm 04:31 PM

在微信公眾號開發中,使用者標籤管理是一個非常重要的功能,可以讓開發者更了解和管理自己的使用者。本篇文章將介紹如何使用PHP實作微信使用者標籤管理功能。一、取得微信用戶openid在使用微信用戶標籤管理功能之前,我們首先需要取得用戶的openid。在微信公眾號開發中,透過使用者授權的方式取得openid是比較常見的做法。在使用者授權完成後,我們可以透過以下程式碼取得用

PHP微信開發:如何實作群發訊息傳送記錄 PHP微信開發:如何實作群發訊息傳送記錄 May 13, 2023 pm 04:31 PM

隨著微信成為了人們生活中越來越重要的通訊工具,其敏捷的訊息傳遞功能迅速受到廣大企業和個人的青睞。對企業而言,將微信發展為一個行銷平台已經成為趨勢,而微信開發的重要性也逐漸凸顯。在其中,群發功能更是被廣泛使用,那麼,作為PHP程式設計師,如何實現群發訊息發送記錄呢?以下將為大家簡單介紹一下。 1.了解微信公眾號相關開發知識在了解如何實現群發訊息發送記錄之前,我

PHP微信開發:如何實現投票功能 PHP微信開發:如何實現投票功能 May 14, 2023 am 11:21 AM

在微信公眾號開發中,投票功能經常被運用。投票功能是讓使用者快速參與互動的好方式,也是舉辦活動和調查意見的重要工具。本文將為您介紹如何使用PHP實作微信投票功能。在取得微信公眾號授權首先,你需要取得微信公眾號的授權。在微信公眾平台上,你需要設定微信公眾號碼的api地址、官方帳號和公眾號碼對應的token。在我們使用PHP語言開發的過程中,我們需要使用微信官方提供的PH

PHP微信開發:如何實現客服聊天視窗管理 PHP微信開發:如何實現客服聊天視窗管理 May 13, 2023 pm 05:51 PM

微信是目前全球用戶規模最大的社群平台之一,隨著行動網路的普及,越來越多的企業開始意識到微信行銷的重要性。在進行微信行銷時,客服服務是至關重要的一環。為了更好地管理客服聊天窗口,我們可以藉助PHP語言進行微信開發。一、PHP微信開發簡介PHP是一種開源的伺服器端腳本語言,廣泛用於Web開發領域。結合微信公眾平台提供的開發接口,我們可以使用PHP語言進行微信

使用PHP實現微信公眾號開發的步驟 使用PHP實現微信公眾號開發的步驟 Jun 27, 2023 pm 12:26 PM

如何使用PHP實現微信公眾號開發微信公眾號已經成為了許多企業推廣和互動的重要管道,而PHP作為常用的Web語言,也可以用來進行微信公眾號的開發。本文將介紹使用PHP實現微信公眾號開發的具體步驟。第一步:取得微信公眾號的開發者帳號在開始微信公眾號開發之前,需要先去申請一個微信公眾號的開發者帳號。具體的註冊流程可參考微信公眾平台的官方網

See all articles