Переглянути джерело

Merge branch 'develop' of 192.168.3.17:zhanghongbo/qfw into develop

renzheng 9 роки тому
батько
коміт
853006960f

+ 47 - 0
core/src/flop.json

@@ -0,0 +1,47 @@
+{
+    "isOver": false,
+    "multiple": [
+        {
+            "multiple": 2,
+            "proportion": 0.9
+        },
+        {
+            "multiple": 3,
+            "proportion": 60
+        },
+        {
+            "multiple": 5,
+            "proportion": 30
+        },
+        {
+            "multiple": 6,
+            "proportion": 0.1
+        }
+    ],
+	"cards":[
+		{
+			"type":1,
+			"words":"薪水蹭蹭涨上天"
+		},
+		{
+			"type":2,
+			"words":"闪闪亮亮惹人爱"
+		},
+		{
+			"type":3,
+			"words":"驰骋职场棒棒哒"
+		},
+		{
+			"type":4,
+			"words":"身体强壮如金刚"
+		},
+		{
+			"type":5,
+			"words":"新年桃花朵朵开"
+		},
+		{
+			"type":6,
+			"words":"瘦出魔鬼好身材"
+		}
+	]
+}

+ 6 - 0
core/src/qfw/active/active.go

@@ -8,8 +8,14 @@ import (
 
 var se util.SimpleEncrypt = util.SimpleEncrypt{Key: "topnet2015topnet2015"}
 
+type Active struct {
+	*xweb.Action
+	flop xweb.Mapper `xweb:"/active/flop/(.*)"`
+}
+
 //抽奖活动
 func init() {
 	//添加模块解析
+	xweb.AddAction(&Active{})
 	xweb.AddAction(&Activemanage{})
 }

+ 0 - 1
core/src/qfw/active/activemanage.go

@@ -203,7 +203,6 @@ type Activemanage struct {
 	luckdraw    xweb.Mapper `xweb:"/activity/(\\w+)/([^.]*)"`
 	getluckdraw xweb.Mapper `xweb:"/activity/luckdraw"`
 	addredis    xweb.Mapper `xweb:"/activity/addredis"`
-	flop        xweb.Mapper `xweb:"/activity/flop/(.*)"`
 }
 
 //分享成功后建立redis判断值

+ 105 - 11
core/src/qfw/active/flop.go

@@ -3,27 +3,121 @@ package active
 import (
 	"github.com/go-xweb/xweb"
 	"gopkg.in/mgo.v2/bson"
+	"log"
+	"math/rand"
+	"qfw/coreconfig"
 	"qfw/coreutil"
+	"qfw/mobile"
+	"qfw/util"
 	"qfw/util/credit"
 	"qfw/util/mongodb"
+	"time"
 )
 
-func (a *Activemanage) Flop(openid string) error {
-	var s_openid string
-	if a.GetSession("s_m_openid") == nil {
-		s_openid = openid
-		a.T["flag"] = false
+var flopEncrypt util.SimpleEncrypt = util.SimpleEncrypt{Key: "flopActive"}
+
+//翻牌
+func (a *Active) Flop(encryptOpenid string) error {
+	//判断活动是否结束
+	if coreconfig.Flop.IsOver {
+		a.T["IsOver"] = true
 	} else {
-		s_openid = a.GetSession("s_m_openid").(string)
-		a.T["flag"] = true
-		a.T["shareid"] = coreutil.FindMyShareId("topjy", s_openid)
-	}
-	if data := mongodb.FindOne("flop", bson.M{"s_openid": openid}); data != nil && len(*data) > 0 {
-		a.T["data"] = *data
+		a.T["IsOver"] = false
+		openid := flopEncrypt.DecodeString(encryptOpenid)
+		var flag int = 3             //标识
+		var cardType int = 1         //翻牌的类型
+		var multiple int = 2         //倍数
+		var nickName, words string   //昵称、牌上的文字
+		var oldCredit, newCredit int //新、老积分
+		var getFlopData = func() {
+			if data := mongodb.FindOne("flop", bson.M{"s_openid": openid}); data != nil && len(*data) > 0 {
+				nickName = (*data)["s_nickname"].(string)
+				oldCredit = util.IntAll((*data)["i_oldcredit"])
+				newCredit = util.IntAll((*data)["i_newcredit"])
+				cardType = util.IntAll((*data)["i_type"])
+				words = (*data)["s_words"].(string)
+				nickName = (*data)["s_nickname"].(string)
+			}
+		}
+		//分享出去
+		if a.GetSession("userId") == nil || a.GetSession("s_m_openid") == nil || a.GetSession("i_credit") == nil {
+			getFlopData()
+			a.T["shareid"] = coreutil.FindMyShareId("topjy", openid)
+		} else { //可以翻牌
+			s_openid := a.GetSession("s_m_openid").(string)
+			encryptOpenid = flopEncrypt.EncodeString(s_openid)
+			if a.GetSession("nickName") != nil {
+				nickName = a.GetSession("nickName").(string)
+			}
+			data := mongodb.FindOne("flop", bson.M{"s_openid": s_openid})
+			if data == nil || len(*data) == 0 {
+				oldCredit = a.GetSession("i_credit").(int)
+				multiple = getMultiple()
+				newCredit = oldCredit * multiple
+				//翻牌类型
+				card := coreconfig.Flop.Cards[rand.New(rand.NewSource(time.Now().UnixNano())).Intn(6)+1]
+				cardType = util.IntAll(card["type"])
+				words = card["words"].(string)
+				if updateCredit(a.GetSession("userId").(string), oldCredit, newCredit, a.Action) {
+					mongodb.Save("flop", bson.M{
+						"s_openid":     s_openid,
+						"i_oldcredit":  oldCredit,
+						"i_newcredit":  newCredit,
+						"l_createdate": time.Now().Unix(),
+						"i_type":       cardType,
+						"s_words":      words,
+						"s_nickname":   nickName,
+						"i_multiple":   multiple,
+					})
+				} else {
+					log.Println("翻牌的时候", s_openid, "的积分修改失败!")
+				}
+				flag = 1
+			} else {
+				getFlopData()
+				flag = 2
+			}
+		}
+		a.T["openid"] = encryptOpenid
+		a.T["cardType"] = cardType
+		a.T["oldCredit"] = oldCredit
+		a.T["newCredit"] = newCredit
+		a.T["words"] = words
+		a.T["nickName"] = nickName
+		a.T["flag"] = flag
+		a.T["multiple"] = multiple
+		a.T["signature"] = mobile.GetSignature(a.Url())
 	}
 	return a.Render("/active/flop.html", &a.T)
 }
 
+//获取倍数
+func getMultiple() int {
+	array := coreconfig.Flop.Multiple
+	weightValue := getRandomIndex(array)
+	multiple := util.IntAll(array[weightValue]["multiple"])
+	if multiple == 0 {
+		return 2
+	}
+	return multiple
+}
+
+//根据权重随机获取数组的索引
+func getRandomIndex(array []map[string]interface{}) int {
+	var weightSum, stepWeightSum float64
+	for _, v := range array {
+		weightSum += v["proportion"].(float64)
+	}
+	randVal := rand.New(rand.NewSource(time.Now().UnixNano())).Float64()
+	for i := 0; i < len(array); i++ {
+		stepWeightSum += array[i]["proportion"].(float64)
+		if randVal <= stepWeightSum/weightSum {
+			return i
+		}
+	}
+	return 0
+}
+
 //翻福卡修改积分
 func updateCredit(id string, o_value1, n_value int, xb *xweb.Action) bool {
 	clog := make(map[string]interface{})

+ 18 - 0
core/src/qfw/coreconfig/Flop.go

@@ -0,0 +1,18 @@
+package coreconfig
+
+import (
+	"qfw/util"
+)
+
+//系统配置
+type flop struct {
+	Multiple []map[string]interface{} `json:"multiple"`
+	Cards    []map[string]interface{} `json:"cards"`
+	IsOver   bool                     `json:"isOver"`
+}
+
+var Flop flop
+
+func readflop() {
+	util.ReadConfig("./flop.json", &Flop)
+}

+ 1 - 0
core/src/qfw/coreconfig/coreconfig.go

@@ -12,4 +12,5 @@ func init() {
 	readServiceClassify()
 	readredPackage()
 	readluckDraw()
+	readflop()
 }

BIN
core/src/web/staticres/images/flop/bg-1.png


BIN
core/src/web/staticres/images/flop/bg-2.png


BIN
core/src/web/staticres/images/flop/blessing.png


BIN
core/src/web/staticres/images/flop/btn.png


BIN
core/src/web/staticres/images/flop/bubble.png


BIN
core/src/web/staticres/images/flop/card-1.png


BIN
core/src/web/staticres/images/flop/card-2.png


BIN
core/src/web/staticres/images/flop/card-3.png


BIN
core/src/web/staticres/images/flop/card-4.png


BIN
core/src/web/staticres/images/flop/card-5.png


BIN
core/src/web/staticres/images/flop/card-6.png


BIN
core/src/web/staticres/images/flop/card.png


BIN
core/src/web/staticres/images/flop/flop-notice.png


BIN
core/src/web/staticres/images/flop/tip-bg.png


+ 256 - 44
core/src/web/templates/active/flop.html

@@ -1,75 +1,287 @@
 <html>
 <head>
-<title>企明星-剑鱼</title>
+<title>企明星-翻牌活动</title>
 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
-<link href="/wxswordfish/style.css" rel="stylesheet">
 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
 <script src="/js/jquery.js"></script>
-<script src="/wxswordfish/share.js"></script>
 <script>
-	initShare({{.T.signature}},{{.T.shareid}});
+var signature = {{.T.signature}};
+var shareTitle = "{{.T.nickName}}在2016年{{.T.words}}";
+var shareLink = "http://www.qimingxing.info/active/flop/{{.T.openid}}";
+var shareIcon = "http://www.qimingxing.info/images/flop/blessing.png";
+if(typeof(signature) != "undefined" && signature != null && signature.length == 4){
+	wx.config({
+	    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+	    appId: signature[0], // 必填,公众号的唯一标识
+	    timestamp:signature[1], // 必填,生成签名的时间戳
+	    nonceStr: signature[2], // 必填,生成签名的随机串
+	    signature: signature[3],// 必填,签名,见附录1
+	    jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
+	});
+	wx.ready(function () {
+        wx.onMenuShareTimeline({
+		    title: shareTitle, // 分享标题
+		    link: shareLink, // 分享链接
+		    imgUrl: shareIcon, // 分享图标
+		    success: function () { 
+		       //alert('分享成功');
+		    },
+		    cancel: function () { 
+		       //alert('分享失败,或用户取消了');
+		    }
+		});
+		
+		wx.onMenuShareAppMessage({
+		    title: shareTitle, // 分享标题
+		    desc: '企明星给您拜年!猴年翻福牌,翻来好运气!关注企明星,回复“福牌”得好运。', // 分享描述
+		    link:  shareLink,// 分享链接
+		    imgUrl: shareIcon, // 分享图标
+		    type: 'link', // 分享类型,music、video或link,不填默认为link'
+		    dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
+		    success: function () { 
+		        //alert('分享成功');
+		    },
+		    cancel: function () { 
+				//alert('分享失败,或用户取消了');
+		    }
+		});
+    });
+}	
 </script>
 <style type="text/css">
 body{
 	margin: 0px;
 	font-family: tahoma, arial, 'Hiragino Sans GB', 'Microsoft YaHei', 宋体, sans-serif;
 	-webkit-tap-highlight-color: transparent;
-}
-ul{
-	list-style: none;
-	padding: 0px;
-	margin: 0px;
+	background-color: #B63845;
 }
 img{
 	vertical-align: sub;
 }
-.brand a{
-	display: block;
-	float: left;
-	margin: 20px;
+.body-bg{
+	width: 100%;
+	height: 100%;
+}
+.btn{
 	width: 180px;
-	height: 240px;
+	height: 43px;
+	position: absolute;
+	left: 50%;
+	margin-left: -90px;
+	display: none;
+}
+.bubble{
+	position: absolute;
+	right: 20px;
+	top: 0px;
+	width: 97.5px;
+	height: 53px;
+	display: none;
+}
+.cards{
+	position: absolute;
+	left: 0px;
+	right: 0px;
 	text-align: center;
-	position: relative;
+	display: none;
 }
-.brand img{
-	width: 180px;
-	height: 240px;
+.cards>img{
+	width: 250px;
+	height: 282.4px;
 }
-.brand .info{
+.flop-tip{
+	color: #a52f2e;
+	background-image: url("/images/flop/tip-bg.png");
+	background-size: 100% 100%;
+	position: absolute;
+	width: 280px;
+	line-height: 22px;
+	left: 50%;
+	margin-left: -145px;
+	display: none;
+	font-size: 14px;
+	font-weight: bold;
+	text-align: center;
+	padding: 5px;
+	margin-bottom: 10px;
 	display: none;
-	background-color: #f0f0f0;
-	color: #369242;
-	line-height:240px;
 }
-.vertical .info{
-	width: 0;
-	height: 240px;
-	margin: 0 auto;
+.flop-tip>span{
+	margin-right: 3px;
+}
+.flop-tip>font{
+	font-size: 12px;
+	font-weight: normal;
+}
+.multiple{
+	font-size: 22px;
+	text-align: center;
+	position: relative;
+	width: 15px;
+	display: inline-block;
+	vertical-align: top;
+	overflow: hidden;
+	height: 20px;
+}
+.flop-notice{
+	color: #ffa461;
+	background-image: url("/images/flop/flop-notice.png");
+	background-size: 100% 100%;
+	position: absolute;
+	top: 30px;
+	width: 280px;
+	left: 50%;
+	margin-left: -140px;
+	text-align: center;
+	padding-top: 7px;
+	padding-bottom: 7px;
+	display: none;
+}
+.flop-notice>span{
+	display: inline-block;
+	max-width: 140px;
+	overflow: hidden;
+	white-space: nowrap;
+	text-overflow: ellipsis;
+	vertical-align: top;
+}
+.flop-share{
+	position: absolute;
+	left: 0px;
+	right: 0px;
+	bottom: 0px;
+	height: 90px;
+	background-color: #ffffff;
+}
+.flop-share>*{
+	display: inline-block;
+	width: 70px;
+	height: 70px;
+	margin-left: 10px;
+	vertical-align: top;
+	margin-top: 10px;
+}
+.flop-share>div{
+	width: 150px;
+	padding-top: 10px;
+	line-height: 25px;
+	font-size: 14px;
+}
+ul{
+	list-style: none;
+	padding: 0px;
+	margin: 0px;
+}
+.random{
+	position: absolute;
+	left: 2px;
+	height: 155px;
 }
 </style>
 </head>
 <body>
-
-
-
-
+<img src="/images/flop/bubble.png" class="bubble">
+{{if eq .T.flag 1}}
+<img src="/images/flop/bg-1.png" class="body-bg" id="flop-before">
+{{end}}
+<img src="/images/flop/bg-2.png" class="body-bg" id="flop-after"{{if eq .T.flag 1}} style="display: none;"{{end}}>
+<div class="flop-notice">
+	<span>{{.T.nickName}}</span>,您的猴年福牌是:
+</div>
+<div class="cards">
+	{{if eq .T.flag 1}}<img src="/images/flop/card.png">{{end}}
+	<img src="/images/flop/card-{{.T.cardType}}.png"{{if eq .T.flag 1}} style="display: none;"{{end}}>
+</div>
+{{if eq .T.flag 1}}
+<img src="/images/flop/btn.png" class="btn">
+{{else if eq .T.flag 3}}
+<div class="flop-share">
+	<img src="/front/weixinshare/{{.T.shareid}}">
+	<div>
+		长按图片识别二维码<br>
+		您也可以测福牌
+	</div>
+</div>
+{{end}}
+<div class="flop-tip">
+	恭喜!你的企明星积分翻
+	<span class="multiple">
+	<ul class="random">
+		<li>7</li>
+		<li>3</li>
+		<li>6</li>
+		<li>8</li>
+		<li>5</li>
+		<li>9</li>
+		<li>2</li>
+	</ul>
+	</span>倍!<br>
+	您的积分已从{{.T.oldCredit}}分涨到{{.T.newCredit}}分。<br>
+	<font>积分明细请到企明星(www.qmx.top)查询!</font>
+</div>
 <script type="text/javascript">
-var turn = function(target,time,opts){
-	target.find('a').hover(function(){
-		$(this).find('img').stop().animate(opts[0],time,function(){
-			$(this).hide().next().show();
-			$(this).next().animate(opts[1],time);
-		});
-	},function(){
-		$(this).find('.info').animate(opts[0],time,function(){
-			$(this).hide().prev().show();
-			$(this).prev().animate(opts[1],time);
-		});
-	});
+if({{.T.IsOver}}){
+	alert("活动已经结束!");
 }
-var verticalOpts = [{'width':0},{'width':'180px'}];
-turn($('#vertical'),100,verticalOpts);
+$(function(){
+	var windowWidth = $(window).width();
+	var windowHeight = $(window).height();
+	var defaultWidth = 320;
+	var defaultHeight = 416;
+	var width = 250;
+	var height = 282.4;
+	var top = 120;
+	var noticeTop = 80;
+	if(windowHeight > defaultHeight){
+		top = top / defaultHeight * windowHeight;
+		noticeTop = noticeTop / defaultHeight * windowHeight;
+	}
+	if(windowWidth > defaultWidth && windowHeight > defaultHeight){
+		width = width / defaultWidth * windowWidth;
+		if(width > 350){//最大宽度350
+			width = 350
+		}
+		height = width / 625 * 706;
+		$(".cards>img").css({width: width,height: height}).show();
+	}
+	$(".cards").css({"top": top}).show();
+	$(".flop-notice").css({"top": noticeTop});
+	if(windowHeight - $(".cards").height()  - top - $(".flop-tip").height() > 40){
+		$(".flop-tip").css({"line-height": "30px",top: $(".cards").height()+top});
+	}else{
+		$(".flop-tip").css({"top": $(".cards").height()+top-30});
+	}
+	//
+	{{if eq .T.flag 1}}
+		$(".btn").css({"top": $(".cards").height()+top}).show();
+		$(".btn").click(function(){
+			$("#flop-before,.btn").hide();
+			$("#flop-after,.flop-tip,.flop-notice").show();
+			var marginTop = 0;
+			var plus = true;
+			var randomInterval = setInterval(function(){
+				$(".random").css({top : "-22px"});
+				$(".random").append($(".random li:first"));
+			},20);
+			setTimeout(function(){
+				clearInterval(randomInterval);
+				$(".multiple").html({{.T.multiple}});
+			},1000);
+			setTimeout(function(){
+				$(".bubble").fadeIn();
+			},3000);
+			$('.cards').children('img:first').stop().animate({'width':0},100,function(){
+				$(this).hide().next().show();
+				$(this).next().animate({'width':width+'px'},500);
+			});
+		});
+	{{else}}
+		$(".flop-notice").show();
+	{{end}}
+	{{if eq .T.flag 2}}
+		$(".flop-tip").show();
+	{{end}}
+});
 </script>
 </body>
 </html>

+ 0 - 13
core/src/web/templates/swordfish/wxshareguide.html

@@ -46,7 +46,6 @@
 var mySwiper = null;
 var currentIndex = 0;
 $(function(){
-	initShare({{.T.signature}},{{.T.shareid}});
 	var width = $(window).width();
 	var height = $(window).height();
 	var defaultHeight = 416;
@@ -60,7 +59,6 @@ $(function(){
 		top = top / defaultHeight * height;
 	}
 	$("#QRcode").css({"width":width,"height":width,"top": top-width,"left":"50%","margin-left": -(width/2)});
-	$(".bottom-toolbar,.feedback-dialog").remove();
 	var flag = true;
 	mySwiper = new Swiper('.swiper-container', {
 		loop: true,
@@ -104,17 +102,6 @@ $(function(){
 			});
 		}
     });
-	/*
-	var imgHeight = 1159;
-	var imgWidth = 750;
-	var width = document.body.clientWidth;
-	var height = document.body.clientHeight;
-	if(imgWidth > width){
-		var h = width / imgWidth * imgHeight;
-		$(".swiper-slide img").css({width: width,height: h,marginTop: -(h / 2)});
-	}else if(imgHeight > height){
-		$(".swiper-slide img").css({width: height / imgHeight * imgWidth,height: height,marginTop: -(height / 2)});
-	}*/
 });
 function backToIndex(){
 	if(mySwiper == null || mySwiper.activeIndex == 1){