重庆小潘seo博客

当前位置:首页 > 重庆网络营销 > 小潘杂谈 >

小潘杂谈

微信开发之大转盘功能

时间:2020-09-11 11:30:06 作者:重庆seo小潘 来源:
微信营销是一种新型的营销模式,由于微信更重视用户之间的互动,故而这种营销推广不不能盲目地套用微博营销的单纯大量广告推送方式。这种方式在微信营销中的效果非常差,会令用户反感,继而取消去企业或商家的微信公众账号关注。对于企业来说,做微信推广重

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

下面详细介绍:一、使用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 alt="微信开发之大转盘功能" src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js" type="text/javascript"></script><script type="text/javascript" alt="微信开发之大转盘功能" src="../../scripts/jquery/jquery.query.js"></script><script alt="微信开发之大转盘功能" 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>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();//得到微信用户的openidif (_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='" + openid + "'");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 + "andopenid='" + openid + "' andcreateDate>='" + 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>/// 返回中奖序列号/// </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;}#endregionpublic bool IsReusable{get{return false;}}} 【相关推荐】

1.微信公众号平台源码下载

2.阿狸子订单系统源码以上就是微信开发之大转盘功能的详细内容,更多请关注小潘博客其它相关文章!