0

0

微信开发之大转盘功能

Y2J

Y2J

发布时间:2017-05-08 11:13:46

|

3605人浏览过

|

来源于php中文网

原创

微信营销是一种新型的营销模式,由于微信更重视用户之间的互动,故而这种营销推广不不能盲目地套用微博营销的单纯大量广告推送方式。这种方式在微信营销中的效果非常差,会令用户反感,继而取消去企业或商家的微信公众账号关注。对于企业来说,做微信推广重要的一个方面就是提高用户和公众账号之间的黏度,而微信大转盘就是其中最为常见的活动。

下面详细介绍:

一、使用

1. 新建一个大转盘的活动:

image

2. 奖项设置

image

3. 保存后,在微信里给公众号发一个“大转盘”的消息, 就会收到大转盘的内容

Screenshot_2015-06-07-21-50-15

4. 点击进入大转盘活动,然后点击中间的 “点击抽奖”:

 Screenshot_2015-06-08-22-16-09  Screenshot_2015-06-08-22-20-43 

二、实现

1. 页面

1.1 前台代码
<% if (ErrLevel < 100)
   {
       Response.Write(ErrorInfo);
   }
   else if (ErrLevel == 101)
   {  //活动已结束,跳转到结束页面
%>

<%
   }
   else
   {  %>




    

    
    
    
    
    
    
    
    
    幸运大转盘抽奖
    
    
    
    
    


    

-.png">

微信开发之大转盘功能

恭喜你中奖了

你中了:

兑奖SN码:

恭喜你中奖了

你中了:

企站帮微商城系统Access版
企站帮微商城系统Access版

OdnShop(原企站帮微商城系统,更名为OdnShop),基于ASP.NET 4.0+Access开发的轻量级微信商城系统,前台简洁美观,后台容易操作。系统容易部署,空间成本低,大部分的几百块一年的虚拟主机均可支持(具体请咨询空间商),适合要求不高,预算不多的小商店,小企业初次尝试微信线上销售产品,目前基本的核心功能,包括微信登陆/支付,产品管理,购物车与订单管理,分享获取积分,积分礼品兑换功能

下载

兑奖sn码为:

你已经兑奖成功,本SN码自定作废!

奖项设置:

活动说明:

本次活动每天可以转 次,总共可以转 次 你已经转了

©微布斯科技提供 qq 121285904 www.webus.cn

<% }%>
2.1  后台代码
/// 
      /// ErrLevel:100表示正确无误,1表示严重错误,2表示业务方面有问题;3直接跳转到结束页面
      /// 
      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 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("

" + item.jxName + ":" + item.jpName + " 数量:" + item.jpNum + "

"); 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 = "

"; } 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 = "

您已经抽了" + hasCjTimes + "次了。

"; } if (isTodayOverSum(dayMaxTimes)) { hidStatus.Value = "2"; // litOtherTip.Text = "

每人每天只有" + dayMaxTimes.ToString() + "次抽奖机会,您已经使用完了。

"; } } } #region 方法 /// /// 判断今天是否已经超出抽奖次数 /// todayTTTimes:能抽奖的总次数 /// /// /// 每天的抽奖总次数 /// 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

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 jsonDict = new Dictionary();
                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 itemlist = itemBll.GetModelList("actId=" + aid);//该活动的所有奖项信息
                    int ttJpNum = 0;
                    for (int i = 0; i < itemlist.Count; i++)
                    {
                        ttJpNum += itemlist[i].jpRealNum.Value;
                    }
                    IList 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 方法
        /// 
        /// 取中奖的项目
        /// 
        /// 所有的奖品信息
        /// 已经中奖的列表
        /// 
        private Model.wx_dzpAwardItem getZJItem(IList itemlist, IList haszjlist)
        {
            IList zjItemlist = new List();//剩余奖品列表
            Model.wx_dzpAwardItem tmpItem = new Model.wx_dzpAwardItem();
            Model.wx_dzpAwardItem stmpItem = new Model.wx_dzpAwardItem();
            IList 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();
                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];
        }
        /// 
        /// 判断该用户的抽奖次数
        /// 
        /// 
        /// 
        private int personCJTimes(string openid, int aid)
        {
            int times = 0;
            times = utbll.GetRecordCount("actId=" + aid + " and openid='" + openid + "'");
            return times;
        }
        /// 
        /// 判断今天是否已经超出抽奖次数
        /// todayTTTimes:能抽奖的总次数
        /// 
        /// 
        /// 每天的抽奖总次数
        /// 
        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;
            }
        }
        /// 
        /// 返回中奖序列号
        /// 
        /// 
        /// 
        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.阿狸子订单系统源码

相关文章

微信app下载
微信app下载

微信是一款手机通信软件,支持通过手机网络发送语音短信、视频、图片和文字。微信可以单聊及群聊,还能根据地理位置找到附近的人,带给大家全新的移动沟通体验,有需要的小伙伴快来保存下载体验吧!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
go语言 注释编码
go语言 注释编码

本专题整合了go语言注释、注释规范等等内容,阅读专题下面的文章了解更多详细内容。

2

2026.01.31

go语言 math包
go语言 math包

本专题整合了go语言math包相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

go语言输入函数
go语言输入函数

本专题整合了go语言输入相关教程内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

golang 循环遍历
golang 循环遍历

本专题整合了golang循环遍历相关教程,阅读专题下面的文章了解更多详细内容。

0

2026.01.31

Golang人工智能合集
Golang人工智能合集

本专题整合了Golang人工智能相关内容,阅读专题下面的文章了解更多详细内容。

1

2026.01.31

2026赚钱平台入口大全
2026赚钱平台入口大全

2026年最新赚钱平台入口汇总,涵盖任务众包、内容创作、电商运营、技能变现等多类正规渠道,助你轻松开启副业增收之路。阅读专题下面的文章了解更多详细内容。

76

2026.01.31

高干文在线阅读网站大全
高干文在线阅读网站大全

汇集热门1v1高干文免费阅读资源,涵盖都市言情、京味大院、军旅高干等经典题材,情节紧凑、人物鲜明。阅读专题下面的文章了解更多详细内容。

73

2026.01.31

无需付费的漫画app大全
无需付费的漫画app大全

想找真正免费又无套路的漫画App?本合集精选多款永久免费、资源丰富、无广告干扰的优质漫画应用,涵盖国漫、日漫、韩漫及经典老番,满足各类阅读需求。阅读专题下面的文章了解更多详细内容。

67

2026.01.31

漫画免费在线观看地址大全
漫画免费在线观看地址大全

想找免费又资源丰富的漫画网站?本合集精选2025-2026年热门平台,涵盖国漫、日漫、韩漫等多类型作品,支持高清流畅阅读与离线缓存。阅读专题下面的文章了解更多详细内容。

19

2026.01.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
Node.js 教程
Node.js 教程

共57课时 | 9.9万人学习

Rust 教程
Rust 教程

共28课时 | 5.2万人学习

Vue 教程
Vue 教程

共42课时 | 7.5万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号