Browse Source

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

wangshan 9 năm trước cách đây
mục cha
commit
36f48d4a3c
34 tập tin đã thay đổi với 979 bổ sung229 xóa
  1. 15 0
      common/src/qfw/util/mongodb/mongodbutil_test.go
  2. 47 0
      core/src/flop.json
  3. 7 0
      core/src/qfw/active/active.go
  4. 0 1
      core/src/qfw/active/activemanage.go
  5. 116 11
      core/src/qfw/active/flop.go
  6. 18 0
      core/src/qfw/coreconfig/Flop.go
  7. 1 0
      core/src/qfw/coreconfig/coreconfig.go
  8. 1 2
      core/src/qfw/coreutil/Int64_test.go
  9. BIN
      core/src/web/staticres/images/flop/bg-1.png
  10. BIN
      core/src/web/staticres/images/flop/bg-2.png
  11. BIN
      core/src/web/staticres/images/flop/blessing.png
  12. BIN
      core/src/web/staticres/images/flop/btn.png
  13. BIN
      core/src/web/staticres/images/flop/bubble.png
  14. BIN
      core/src/web/staticres/images/flop/card-1.png
  15. BIN
      core/src/web/staticres/images/flop/card-2.png
  16. BIN
      core/src/web/staticres/images/flop/card-3.png
  17. BIN
      core/src/web/staticres/images/flop/card-4.png
  18. BIN
      core/src/web/staticres/images/flop/card-5.png
  19. BIN
      core/src/web/staticres/images/flop/card-6.png
  20. BIN
      core/src/web/staticres/images/flop/card.png
  21. BIN
      core/src/web/staticres/images/flop/flop-notice.png
  22. BIN
      core/src/web/staticres/images/flop/tip-bg.png
  23. 282 43
      core/src/web/templates/active/flop.html
  24. 4 4
      core/src/web/templates/common/top.html
  25. 0 13
      core/src/web/templates/swordfish/wxshareguide.html
  26. 3 1
      weixin/src/config.json
  27. 6 86
      weixin/src/qfw/weixin/msgtxtchandler.go
  28. 90 14
      weixin/src/qfw/weixin/subscribehandler.go
  29. 4 1
      weixin/src/qfw/weixin/txt_test.go
  30. 2 20
      weixin/src/qfw/weixin/voicehandler.go
  31. 11 1
      weixin/src/qfw/weixin/weixin.go
  32. 330 0
      weixin/src/qfw/weixin/wxadmin.go
  33. 10 2
      weixin/src/qfw/weixinconfig/config_test.go
  34. 32 30
      weixin/src/qfw/weixinconfig/weixinconfig.go

+ 15 - 0
common/src/qfw/util/mongodb/mongodbutil_test.go

@@ -82,3 +82,18 @@ func Test_reg(t *testing.T) {
 	log.Println(con.ReplaceAllString(s, ""))
 
 }
+
+func Test_aggregate(t *testing.T) {
+	InitMongodbPool(1, "192.168.3.18:27080", "qfw")
+	sess := GetMgoConn()
+	defer DestoryMongoConn(sess)
+	var res []M
+	sess.DB("qfw").C("user").Pipe([]M{M{"$match": M{"l_registedate": M{"$gte": 1436326192}}},
+		M{"$group": M{"_id": "$black", "count": M{"$sum": 1}}}}).All(&res)
+	var sun int
+	for _, v := range res {
+		log.Println(v["_id"] == nil)
+	}
+	log.Println(res, sun)
+
+}

+ 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":"瘦出魔鬼好身材"
+		}
+	]
+}

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

@@ -8,8 +8,15 @@ import (
 
 var se util.SimpleEncrypt = util.SimpleEncrypt{Key: "topnet2015topnet2015"}
 
+type Active struct {
+	*xweb.Action
+	flop     xweb.Mapper `xweb:"/active/flop/(.*)"`
+	flopAjax xweb.Mapper `xweb:"/active/flopAjax"`
+}
+
 //抽奖活动
 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判断值

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

@@ -3,27 +3,132 @@ 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
-	} else {
-		s_openid = a.GetSession("s_m_openid").(string)
-		a.T["flag"] = true
-		a.T["shareid"] = coreutil.FindMyShareId("topjy", s_openid)
+var flopEncrypt util.SimpleEncrypt = util.SimpleEncrypt{Key: "flopActive"}
+
+//翻牌
+func (a *Active) FlopAjax() error {
+	if a.GetSession("flopData") != nil {
+		data := a.GetSession("flopData").(bson.M)
+		if updateCredit(data["s_userid"].(string), util.IntAll(data["i_oldcredit"]), util.IntAll(data["i_newcredit"]), a.Action) {
+			mongodb.Save("flop", data)
+		} else {
+			log.Println("翻牌的时候", data["s_openid"].(string), "的积分修改失败!")
+		}
 	}
-	if data := mongodb.FindOne("flop", bson.M{"s_openid": openid}); data != nil && len(*data) > 0 {
-		a.T["data"] = *data
+	return nil
+}
+
+//进入翻牌
+func (a *Active) Flop(encryptOpenid string) error {
+	//判断活动是否结束
+	if coreconfig.Flop.IsOver {
+		a.T["IsOver"] = true
+	} else {
+		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)
+				multiple = util.IntAll((*data)["i_multiple"])
+			}
+		}
+		//分享出去
+		if a.GetSession("userId") == nil || a.GetSession("s_m_openid") == nil || a.GetSession("i_credit") == nil {
+			getFlopData()
+			a.T["shareid"] = coreutil.FindMyShareId("topflop", 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)]
+				cardType = util.IntAll(card["type"])
+				words = card["words"].(string)
+				a.SetSession("flopData", bson.M{
+					"s_userid":     a.GetSession("userId").(string),
+					"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,
+				})
+				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()
 }

+ 1 - 2
core/src/qfw/coreutil/Int64_test.go

@@ -27,6 +27,5 @@ func TestBase64(t *testing.T) {
 }
 
 func Test_spit(t *testing.T) {
-	s := "41"
-	log.Println(s[:2])
+
 }

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


+ 282 - 43
core/src/web/templates/active/flop.html

@@ -1,75 +1,314 @@
 <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;
+	font-size: 100%;
+	text-align: center;
 }
 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;
+}
+.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:0.875em;
+	font-weight: bold;
+	text-align: center;
+	padding: 5px;
+	margin-bottom: 10px;
+	display: none;
+}
+.flop-tip>span{
+	margin-right: 3px;
+}
+.flop-tip>font{
+	font-size: 0.75em;
+	font-weight: normal;
+}
+.multiple{
+	font-size: 1.375em;
+	text-align: center;
+	position: relative;
+	width: 15px;
+	display: inline-block;
+	vertical-align: top;
+	overflow: hidden;
+	height: 25px;
 }
-.brand .info{
+.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;
-	background-color: #f0f0f0;
-	color: #369242;
-	line-height:240px;
 }
-.vertical .info{
-	width: 0;
-	height: 240px;
-	margin: 0 auto;
+.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>img{
+	display: inline-block;
+	width: 70px;
+	height: 70px;
+	margin-left: 10px;
+	vertical-align: top;
+	margin-top: 10px;
+}
+.flop-share>div{
+	display: inline-block;
+	width: 150px;
+	line-height: 25px;
+	font-size: 0.875em;
+	position: relative;
+	top: 50%;
+	margin-top: -25px;
+}
+ul{
+	list-style: none;
+	padding: 0px;
+	margin: 0px;
+}
+.random{
+	position: absolute;
+	left: 2px;
+	height: 155px;
+}
+.random li{
+	height: 25px;
 }
 </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">
+	{{if eq .T.flag 1}}
+	<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>
+	{{else if eq .T.flag 2}}
+	{{.T.multiple}}
+	{{end}}
+	</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("活动已经结束!");
+}else{
+	$(function(){
+		var windowWidth = $(window).width();
+		var windowHeight = $(window).height();
+		var defaultWidth = 320;
+		var defaultHeight = 416;
+		var width = 250;
+		var height = 282.4;
+		var cardTop = 120;
+		var noticeTop = 80;
+		if(windowWidth > 750){
+			$(".body-bg").css({width: 750,height: windowHeight});
+		}
+		if(windowHeight > defaultHeight){
+			cardTop = cardTop / 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});
+		}
+		$(".cards").css({top: cardTop}).show();
+		$(".flop-notice").css({top: noticeTop});
+		var flopTipTop = windowHeight - $(".cards").height()  - cardTop - $(".flop-tip").height();
+		if(flopTipTop > 30 && flopTipTop < 40){
+			$(".flop-tip").css({"line-height": "30px",top: $(".cards").height() + cardTop - 20});
+		}else if(flopTipTop > 40){
+			$(".flop-tip").css({"line-height": "30px",top: $(".cards").height() + cardTop - 10});
+		}else{
+			$(".flop-tip").css({top: $(".cards").height()+cardTop-30});
+		}
+		//
+		{{if eq .T.flag 1}}
+			$(".btn").css({top: $(".cards").height()+cardTop}).show();
+			$(".btn").one("click",function(){
+				//
+				$.post("/active/flopAjax",null,null);
+				$("#flop-before,.btn").hide();
+				$("#flop-after,.flop-tip,.flop-notice").show();
+				var randomInterval = setInterval(function(){
+					$(".random").css({top : "-27px"});
+					$(".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}}
+		{{if eq .T.flag 3}}
+			var shareHeight = windowHeight - cardTop - height + 30;
+			if(shareHeight > 110){
+				shareHeight = 110;
+			}
+			$(".flop-share").css({height: shareHeight});
+			$(".flop-share>img").css({width: shareHeight-20,height: shareHeight-20});
+		{{end}}
 	});
 }
-var verticalOpts = [{'width':0},{'width':'180px'}];
-turn($('#vertical'),100,verticalOpts);
 </script>
 </body>
 </html>

+ 4 - 4
core/src/web/templates/common/top.html

@@ -67,7 +67,7 @@ function b_loadTop(){
 				if(hasMsgCount){
 					html += '<a class="b-round-dot"></a>';
 				}
-				html += '</span>'+result.nickName;
+				html += '</span><span>'+result.nickName+'</span>';
 				html += '<div id="head-hideMenu" class="head-hideMenu"><ul>'
 					    	+'<li onclick="window.location.href=\'/member/msgcenter\'"><i class="glyphicon youjian"></i><span>消息中心';
 				if(hasMsgCount){
@@ -78,9 +78,6 @@ function b_loadTop(){
 						+'<li onclick="window.location.href=\'/front/logout\'" class="border-b-0"><i class="glyphicon tuichu"></i>退出</li>';
 						+'</ul></div>';
 				$("#b-loginStatus").addClass("b-logined").html(html)
-				.click(function(){
-					window.location.href = "/member/show/memberindex";
-				})
 				.mouseover(function(){
 					$("#head-hideMenu").show();
 				}).mouseleave(function(){
@@ -91,6 +88,9 @@ function b_loadTop(){
 				}).mouseleave(function(){
 					$(this).hide();
 				});
+				$("#b-loginStatus>span").click(function(){
+					window.location.href = "/member/show/memberindex";
+				});
 				//处理公用底部扫码登录按钮
 				$("#bottom-bar>li:first").addClass("invisible");
 				//处理认证完之后第一次登录弹出提示框

+ 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){

+ 3 - 1
weixin/src/config.json

@@ -36,6 +36,8 @@
 	},"weixinautorpl":"小主的吩咐我们已经收到了,请留下您的联系方式(手机号或qq号),企明星客服会在下一个工作日9:00-17:00给小主回复哦!",
 	"creditRpc":"127.0.0.1:8765",
 	"subscribemonitorcyc":3,
-	"subscribemonitortimes":12
+	"subscribemonitortimes":12,
+	"mids":["oJULtwzXo6EFV1Ah-XeyRBimXGM8"],
+	"dir":"/opt/mntdisk/qfw-v1.1"
 
 }

+ 6 - 86
weixin/src/qfw/weixin/msgtxtchandler.go

@@ -1,13 +1,10 @@
 package weixin
 
 import (
-	"encoding/json"
 	"fmt"
-	"io/ioutil"
 	_ "log"
 	"math/rand"
-	"net"
-	"net/http"
+
 	"qfw/weixin/dao"
 	wf "qfw/weixinconfig"
 	"strconv"
@@ -15,28 +12,6 @@ import (
 	"time"
 )
 
-const (
-	APIKEY = "893b61852a7de8e3194194a0fe11917c"
-	APIURL = "http://www.tuling123.com/openapi/api"
-)
-
-var robotclient *http.Client
-
-//初始化图灵123 HttpClient加上超时
-func InitRobotHttpClient() {
-	robotclient = &http.Client{Transport: &http.Transport{
-		Dial: func(netw, addr string) (net.Conn, error) {
-			deadline := time.Now().Add(2 * time.Second)
-			c, err := net.DialTimeout(netw, addr, 2*time.Second)
-			if err != nil {
-				return nil, err
-			}
-			c.SetDeadline(deadline)
-			return c, nil
-		},
-	}}
-}
-
 //文本消息处理
 func MsgTxtHandler(w ResponseWriter, r *Request) {
 	openid := r.FromUserName
@@ -57,12 +32,12 @@ func MsgTxtHandler(w ResponseWriter, r *Request) {
 			processPIdentifyMsgTxt(us, w, r)
 		} else if us.Type == "oidentify" {
 			processOIdentifyMsgTxt(us, w, r)
-		} else if us.Type == "robot" { //聊天机器人
-			processRobotMsg(r.FromUserName, r.Content, w, r)
+		} else if us.Type == "wxadmin" {
+			processWxAdmin(openid, r.Content, w, r)
 		}
-	} else if r.Content == "小星" {
-		UserSession[r.FromUserName] = NewUserSession("robot")
-		w.ReplyText("嗨,小星来陪你解闷。有什么开心的,不开心的说说来,大伙乐呵乐呵。\n输入q或Q离开。")
+	} else if r.Content == "微信管理" && mids[openid] {
+		UserSession[r.FromUserName] = NewUserSession("wxadmin")
+		w.ReplyText("您已进入微信管理,请输入指令操作:\n1.查看抽奖模式(指令:f0)\n2.切换抽奖模式(指令:c*,*为数字。如c0(自动模式),c1(手动模式1),c2(手动模式2),c3(手动模式3))\n3.统计抽奖结果(tjr*,tjr120(最近两分钟),tjr120-1200(最近两分钟至最近20分钟之间的))\n4.统计新用户数(tju*)\n5.服务器情况监测(ser0)\n6服务管理(man*,man1重启主程序(man11关闭),man2重启微信,man3重启积分(man33关闭),man4重启微信认证(man44关闭))。\n输入q或Q离开。")
 		return
 	} else if r.Content == "抽奖" { //进入抽奖环节
 		if time.Now().Unix() > 1455465600 { //活动过期 ,过期后,这段代码要删除
@@ -174,58 +149,3 @@ func processPIdentifyMsgTxt(us *usersession, w ResponseWriter, r *Request) {
 		w.ReplyOK()
 	}
 }
-
-//处理聊天机器人消息
-func processRobotMsg(userid string, content string, w ResponseWriter, r *Request) {
-	rurl := fmt.Sprintf("%s?key=%s&info=%s&userid=%s", APIURL, APIKEY, content, userid)
-	//log.Println("robot::", rurl)
-	resp, err1 := robotclient.Get(rurl)
-	if err1 != nil {
-		w.ReplyText("我386的大脑,实在理解不了你说的话啊。")
-		return
-	}
-	defer resp.Body.Close()
-	bs, err2 := ioutil.ReadAll(resp.Body)
-	if err2 != nil {
-		w.ReplyText("对不起,我理解不了你说的话。")
-		return
-	}
-	//log.Println("robot::", string(bs))
-	var tmp map[string]interface{}
-	err3 := json.Unmarshal(bs, &tmp)
-	if err3 != nil {
-		w.ReplyText("对不起,我理解不了你说的话。")
-		return
-	}
-	code, _ := tmp["code"].(float64)
-	if code == 100000 {
-		repl, _ := tmp["text"].(string)
-		w.ReplyText(repl)
-	} else if code == 308000 { //菜谱
-		l, _ := tmp["list"].([]interface{})
-		arts := []Article{}
-		for index, item := range l {
-			if index > 5 {
-				break
-			}
-			m := item.(map[string]interface{})
-			arts = append(arts, Article{Title: m["info"].(string), PicUrl: m["icon"].(string), Url: m["detailurl"].(string)})
-		}
-		w.ReplyNews(arts)
-	} else if code == 302000 { //新闻
-		l, _ := tmp["list"].([]interface{})
-		arts := []Article{}
-		for index, item := range l {
-			if index > 5 {
-				break
-			}
-			m := item.(map[string]interface{})
-			arts = append(arts, Article{Title: m["article"].(string), Url: m["detailurl"].(string)})
-		}
-		w.ReplyNews(arts)
-	} else {
-		w.ReplyText("对不起,我理解不了你说的话。")
-		return
-	}
-}
-

+ 90 - 14
weixin/src/qfw/weixin/subscribehandler.go

@@ -8,21 +8,87 @@ import (
 	"net/http"
 	"os"
 	"qfw/util"
-	wxutil "qfw/weixin/util"
 	"qfw/util/redis"
 	"qfw/weixin/dao"
+	wxutil "qfw/weixin/util"
 	"qfw/weixinconfig"
 	"strings"
 	"time"
 )
 
+//关注事件处理
+func SubscribeHandler(w ResponseWriter, r *Request) {
+	l1 := time.Now().Unix()
+	wxutil.SubscribeInc()
+	openid := r.FromUserName
+	log.Println("user data", w.GetUserData())
+	ret,_ := w.GetUserData().(map[string]interface{})
+	var unionid, bindweixin, userphoto string
+	if ret != nil {
+		unionid = ""
+		bindweixin = "qmx-" + fmt.Sprintf("%d%d", time.Now().Local().Unix(), rand.Intn(99))
+	} else {
+		unionid, _ = ret["unionid"].(string)
+		bindweixin, _ = ret["nickname"].(string)
+		//取得用户头像
+		headimgurl, _ := ret["headimgurl"].(string)
+		log.Println("download userface :", headimgurl)
+		userphoto = downloadUserFace(headimgurl)
+	}
+	l2 := time.Now().Unix()
+	_, flag := dao.AddUser(openid, unionid, bindweixin, userphoto)
+	l2 = time.Now().Unix()
+	log.Println(",Add user", l2-l1)
+	l1 = l2
+	//保存关注日志
+	var source string
+	if len(r.EventKey) > 8 {
+		source = r.EventKey[8:]
+	} else {
+		source = ""
+	}
+	if digitreg.MatchString(source) {
+		dao.SaveSubscribeLogs(openid, unionid, bindweixin, "wangzhan", "subscribe")
+		if flag == 1 {
+			w.ReplyText(WELCOME_MSG) // 有新人关注,返回欢迎消息
+			redis.Put("sso", "new_"+source, openid, 900)
+			//TODO 处理分享(邀请)类的二维码,记录邀请关系
+			if strings.HasPrefix(source, "32") {
+				go dao.SaveInviteLink(source, r.FromUserName, false)
+				//go dao.UpdateInviteUserCoupon(source)
+			}
+		} else {
+			w.ReplyText(OWELCOME_MSG) // 有旧人关注,返回欢迎消息
+			if strings.HasPrefix(source, "32") {
+				go dao.SaveInviteLink(source, r.FromUserName, true)
+			}
+		}
+		DoLogin(source, openid)
+	} else {
+		if flag == 1 {
+			w.ReplyText(WELCOME_MSG) // 有新人关注,返回欢迎消息
+		} else {
+			w.ReplyText(OWELCOME_MSG) // 有旧人关注,返回欢迎消息
+		}
+		dao.SaveSubscribeLogs(openid, unionid, bindweixin, source, "subscribe")
+	}
 
+	l2 = time.Now().Unix()
+	log.Println(",Do save userinfo", l2-l1)
+	l1 = l2
+}
 
 //关注事件处理
-func SubscribeHandler(w ResponseWriter, r *Request) {
+func SubscribeHandlerBak(w ResponseWriter, r *Request) {
+	l1 := time.Now().Unix()
 	wxutil.SubscribeInc()
 	openid := r.FromUserName
+	log.Println("user data", w.GetUserData())
 	ret, err := w.GetUserBaseInfo(openid)
+	//ret:=w.GetUserData()
+	l2 := time.Now().Unix()
+	log.Println(",Get user baseinfo", l2-l1, " s")
+	l1 = l2
 	var unionid, bindweixin, userphoto string
 	if err != nil {
 		unionid = ""
@@ -36,6 +102,9 @@ func SubscribeHandler(w ResponseWriter, r *Request) {
 		userphoto = downloadUserFace(headimgurl)
 	}
 	_, flag := dao.AddUser(openid, unionid, bindweixin, userphoto)
+	l2 = time.Now().Unix()
+	log.Println(",Add user", l2-l1)
+	l1 = l2
 	//保存关注日志
 	var source string
 	if len(r.EventKey) > 8 {
@@ -43,7 +112,7 @@ func SubscribeHandler(w ResponseWriter, r *Request) {
 	} else {
 		source = ""
 	}
-	log.Println("source::", source, "flag:::", flag)
+	//log.Println("source::", source, "flag:::", flag)
 	if digitreg.MatchString(source) {
 		dao.SaveSubscribeLogs(openid, unionid, bindweixin, "wangzhan", "subscribe")
 		if flag == 1 {
@@ -69,6 +138,10 @@ func SubscribeHandler(w ResponseWriter, r *Request) {
 		}
 		dao.SaveSubscribeLogs(openid, unionid, bindweixin, source, "subscribe")
 	}
+
+	l2 = time.Now().Unix()
+	log.Println(",Do save userinfo", l2-l1)
+	l1 = l2
 }
 
 //取消关注事件处理
@@ -112,18 +185,21 @@ func DoLogin(key string, openid string) {
 //下载微信用户头像
 func downloadUserFace(url string) string {
 	var filename string
-	util.Try(func() {
+	
 		tn := time.Now()
 		filename = fmt.Sprintf("/upload/%s/%s/%s/%s%d.jpg", tn.Format("2006"), tn.Format("01"), tn.Format("02"), tn.Format("20060102150405"), rand.Intn(9999)+1000)
-		fi, _ := os.OpenFile(weixinconfig.SysConfig.Imgpath+filename, os.O_CREATE|os.O_TRUNC|os.O_SYNC|os.O_RDWR, 0x666)
-		defer fi.Close()
-		resp, err := http.Get(url)
-		defer resp.Body.Close()
-		if err == nil {
-			io.Copy(fi, resp.Body)
-		} else {
-			log.Println("download userface err:", err.Error())
-		}
-	}, func(e interface{}) {})
+		go func() {
+			util.Try(func() {
+			fi, _ := os.OpenFile(weixinconfig.SysConfig.Imgpath+filename, os.O_CREATE|os.O_TRUNC|os.O_SYNC|os.O_RDWR, 0x666)
+			defer fi.Close()
+			resp, err := http.Get(url)
+			defer resp.Body.Close()
+			if err == nil {
+				io.Copy(fi, resp.Body)
+			} else {
+				log.Println("download userface err:", err.Error())
+			}
+			}, func(e interface{}) {})
+		}()
 	return filename
 }

+ 4 - 1
weixin/src/qfw/weixin/txt_test.go

@@ -2,6 +2,7 @@ package weixin
 
 import (
 	"log"
+	"regexp"
 	"testing"
 	"time"
 )
@@ -13,5 +14,7 @@ func TestWeek(t *testing.T) {
 }
 
 func TestWord(t *testing.T) {
-	log.Println(len("内部报名"))
+	reg := regexp.MustCompile("^([a-z]+)(\\d.*)$")
+	s := reg.FindSubmatch([]byte("esddfdsf23s-15s"))
+	log.Println(len(s))
 }

+ 2 - 20
weixin/src/qfw/weixin/voicehandler.go

@@ -17,22 +17,7 @@ func MsgVoiceHandler(w ResponseWriter, r *Request) {
 		return
 	}
 	tmp := clear_voice_reg.ReplaceAllString(r.Recognition, "")
-	if v, ok := UserSession[r.FromUserName]; ok {
-		if v.Type == "robot" { //正在聊天
-			if len(chat_bye.FindStringIndex(tmp)) > 0 { //离开
-				delete(UserSession, r.FromUserName)
-				w.ReplyText("再见了小主人,记得想我呦。")
-				return
-			} else { //正常聊天
-				processRobotMsg(r.FromUserName, tmp, w, r)
-				return
-			}
-		}
-	} else if len(notify_xiaoxing.FindStringIndex(tmp)) > 0 {
-		UserSession[r.FromUserName] = NewUserSession("robot")
-		w.ReplyText("嗨,小星来陪你解闷。有什么开心的,不开心的说说来,大伙乐呵乐呵。\n输入q或Q离开。")
-		return
-	} else if k_index := keyword_voice_reg.FindStringIndex(tmp); len(k_index) == 2 {
+	if k_index := keyword_voice_reg.FindStringIndex(tmp); len(k_index) == 2 {
 		//不再会话中,也没有唤醒小星,并且在查企业
 		search := tmp[k_index[1]:]
 		ret, err := findEntprise(search)
@@ -48,10 +33,7 @@ func MsgVoiceHandler(w ResponseWriter, r *Request) {
 			}
 			w.ReplyNews(arts)
 		}
-	} else {
-		w.ReplyText("您说的是:" + tmp + ",小星无法识别。\n查询企业请说:\n搜索XX\n查询XX\n检索XX")
-		return
-	}
+	}  
 }
 
 //查询企业

+ 11 - 1
weixin/src/qfw/weixin/weixin.go

@@ -15,6 +15,11 @@ var WELCOME_MSG string
 var OWELCOME_MSG string
 var digitreg *regexp.Regexp = regexp.MustCompile("^\\d+$")
 
+var mids = map[string]bool{}
+var reg = regexp.MustCompile("^([a-z]+)(\\d.*)$")
+var subreg = regexp.MustCompile("^(\\d+)([smhd]{0,1})$")
+var DIR = ""
+
 func InitWeixinSdk() {
 	keyword_voice_reg, _ = regexp.Compile("查询|搜索|检索|看|找|查|搜")
 	clear_voice_reg, _ = regexp.Compile("!|!|\\s+")
@@ -23,6 +28,12 @@ func InitWeixinSdk() {
 	WELCOME_MSG = wf.SysConfig.WelcomeTip
 	OWELCOME_MSG = wf.SysConfig.OWelcomeTip
 
+	//
+	for _, v := range wf.SysConfig.Mids {
+		mids[v] = true
+	}
+	DIR = wf.SysConfig.Dir
+
 	// my-token 验证微信公众平台的Token
 	// app-id, app-secret用于高级API调用。
 	// 如果仅使用接收/回复消息,则可以不填写,使用下面语句
@@ -57,7 +68,6 @@ func InitWeixinSdk() {
 	http.HandleFunc("/"+wf.SysConfig.Appcontext+"/adv/", AdvHandle)
 
 	//执行其他一些初始化的动作
-	InitRobotHttpClient()
 	InitSSLClient()
 	util.StartSubscribeFilter(wf.SysConfig.SubscribeMonitorCyc, wf.SysConfig.SubscribeMonitorTimes)
 }

+ 330 - 0
weixin/src/qfw/weixin/wxadmin.go

@@ -0,0 +1,330 @@
+package weixin
+
+import (
+	"fmt"
+	. "gopkg.in/mgo.v2/bson"
+	"io/ioutil"
+	"log"
+	"os/exec"
+	"qfw/util"
+	"qfw/util/mongodb"
+	"qfw/util/redis"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func processWxAdmin(openid, content string, w ResponseWriter, r *Request) {
+	util.Try(func() {
+
+		if openid != "" {
+			b, cmd, qleng, unit, var1, var2 := checkContent(content)
+			if b {
+				resStr := "无结果"
+				switch cmd {
+				case "f":
+					//查看抽奖模式
+					resStr = getMode()
+				case "c":
+					//切换抽奖模式
+					if var1 >= 0 && var1 <= 3 {
+						br := redis.Put("other", "s_luckydraw_mode", fmt.Sprintf("%d", var1), 0)
+						if br {
+							resStr = "模式已切换:" + getMode()
+						}
+					}
+				case "tjr":
+					//数据库抽奖查看
+					var1, var2 = getTimes(qleng, unit, var1, var2)
+					qu1 := M{"$gte": var1}
+					if qleng == 2 { //取区间
+						qu1 = M{"$gte": var2, "$lte": var1}
+					} else {
+						w.ReplyText("指令异常,请重新输入。")
+						return
+					}
+					util.Try(func() {
+						sess := mongodb.GetMgoConn()
+						defer mongodb.DestoryMongoConn(sess)
+						var res []M
+						sess.DB("qfw").C("winningrecord").Pipe([]M{M{"$match": M{"l_timestamp": qu1}},
+							M{"$group": M{"_id": "$s_prize", "count": M{"$sum": 1}}}}).All(&res)
+						if res != nil && len(res) > 0 {
+							sum := 0
+							for _, v := range res {
+								resStr += "\n" + v["_id"].(string) + ":" + fmt.Sprintf("%x", v["count"])
+								sum += v["count"].(int)
+							}
+							resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
+						}
+					}, func(e interface{}) {})
+				case "tju":
+					//新用户查看
+					var1, var2 = getTimes(qleng, unit, var1, var2)
+					qu1 := M{"$gte": var1}
+					if qleng == 2 { //取区间
+						qu1 = M{"$gte": var2, "$lte": var1}
+					} else {
+						w.ReplyText("指令异常,请重新输入。")
+						return
+					}
+					util.Try(func() {
+						sess := mongodb.GetMgoConn()
+						defer mongodb.DestoryMongoConn(sess)
+						var res []M
+						sess.DB("qfw").C("user").Pipe([]M{M{"$match": M{"l_registedate": qu1}},
+							M{"$group": M{"_id": "$black", "count": M{"$sum": 1}}}}).All(&res)
+						if res != nil && len(res) > 0 {
+							sum := 0
+							for _, v := range res {
+								resStr += "\n" + util.If(v["_id"] == nil, "黑名单用户", "正常用户").(string) + ":" + fmt.Sprintf("%x", v["count"])
+								sum += v["count"].(int)
+							}
+							resStr += "\n" + "总数:" + fmt.Sprintf("%d", sum)
+						}
+					}, func(e interface{}) {})
+				case "ser":
+					//服务器实时统计情况
+					//各端口,及连接数
+					//总连接数
+					resStr = getServer()
+				case "man":
+					switch var1 {
+					case 1:
+						//重启core
+						cmdstr := getNewCmd(DIR, "core2016")
+						if len(cmdstr) > 0 {
+							execCmd(DIR, "core2016", cmdstr, true)
+						}
+						resStr = "重启主程序完成"
+					case 11:
+						//关闭core
+						cmdstr := getNewCmd(DIR, "core2016")
+						if len(cmdstr) > 0 {
+							execCmd(DIR, "core2016", cmdstr, false)
+						}
+						resStr = "关闭主程序完成"
+					case 2:
+						//重启weixin
+						cmdstr := getNewCmd(DIR+"/weixin", "weixin")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/weixin", "weixin", cmdstr, true)
+						}
+						resStr = "重启微信程序完成"
+					case 22:
+						//不能关闭微信
+						break
+					case 3:
+						//重启积分
+						cmdstr := getNewCmd(DIR+"/credit", "credit")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/credit", "credit", cmdstr, true)
+						}
+						resStr = "重启积分程序完成"
+					case 33:
+						cmdstr := getNewCmd(DIR+"/credit", "credit")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/credit", "credit", cmdstr, false)
+						}
+						resStr = "关闭积分程序完成"
+					//关闭积分
+					case 4:
+						//重启oauth
+						cmdstr := getNewCmd(DIR+"/proxy", "oauth")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/proxy", "oauth", cmdstr, true)
+						}
+						resStr = "重启微信程认证序完成"
+					case 44:
+						//关闭oauth
+						cmdstr := getNewCmd(DIR+"/proxy", "oauth")
+						if len(cmdstr) > 0 {
+							execCmd(DIR+"/proxy", "oauth", cmdstr, false)
+						}
+						resStr = "关闭微信程认证序完成"
+					}
+				}
+				log.Println("res str", resStr)
+				w.ReplyText(resStr)
+			} else {
+				w.ReplyText("指令不存在,请重新输入。")
+			}
+		} else {
+			w.ReplyText("用户信息不存在,请重新进入。")
+			delete(UserSession, openid)
+		}
+	}, func(e interface{}) {})
+}
+
+func getNewCmd(dir, substr string) string {
+	return getServerCmd(fmt.Sprintf(`ls -lt %s | grep %s |awk '{print $9}' |head -1`, dir, substr))
+}
+
+func execCmd(dir, subcmdstr, cmdstr string, bstart bool) bool {
+	exec.Command("/bin/sh", "-c", fmt.Sprintf(`ps -ef | grep %s | grep -v "grep" | awk '{print $2}' |xargs kill -9`, subcmdstr)).Run()
+	if bstart {
+		cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf(`cd %s&& nohup ./%s &`, dir, cmdstr))
+		err := cmd.Run()
+		if err != nil {
+			return false
+		} else {
+			return true
+		}
+	} else {
+		return true
+	}
+}
+
+//获取服务器状态
+func getServer() (str string) {
+	util.Try(func() {
+		tmpStr := getServerCmd(`lsof -i|awk '{print $1}' | uniq -c | sort -nr`)
+		str = tmpStr
+		strs := strings.Split(tmpStr, "\n")
+		n := 0
+		for _, v := range strs {
+			tmps := strings.Split(strings.TrimSpace(v), " ")
+			if len(tmps) == 2 {
+				v, _ := strconv.Atoi(tmps[0])
+				n += v
+			}
+		}
+		str += "\n总连接数:" + fmt.Sprintf("%d", n)
+	}, func(e interface{}) {})
+	return
+}
+
+func getServerCmd(c string) (str string) {
+	cmd := exec.Command("/bin/bash", "-c", c)
+	stdout, err := cmd.StdoutPipe()
+	if err != nil {
+		str = "StdoutPipe: " + err.Error()
+		return
+	}
+	stderr, err := cmd.StderrPipe()
+	if err != nil {
+		str = "StderrPipe: " + err.Error()
+		return
+	}
+	if err := cmd.Start(); err != nil {
+		str = "Start: " + err.Error()
+		return
+	}
+	bytesErr, err := ioutil.ReadAll(stderr)
+	if err != nil {
+		str = "ReadAll stderr: " + err.Error()
+		return
+	}
+	if len(bytesErr) != 0 {
+		str = fmt.Sprintf("stderr is not nil: %s", bytesErr)
+		return
+	}
+	bytes, err := ioutil.ReadAll(stdout)
+	if err != nil {
+		str = "ReadAll stdout: " + err.Error()
+		return
+	}
+	if err := cmd.Wait(); err != nil {
+		str = "Wait: " + err.Error()
+		return
+	}
+	tmpStr := string(bytes)
+	str = strings.Trim(tmpStr, "\n")
+	return
+}
+
+//根据区间算时间0没取
+func getTimes(qlen int, unit string, var1, var2 int64) (v1, v2 int64) {
+	now := time.Now().Unix()
+	switch unit {
+	case "m":
+		var1 = var1 * 60
+		var2 = var2 * 60
+	case "h":
+		var1 = var1 * 3600
+		var2 = var2 * 3600
+	case "d":
+		var1 = var1 * 86400
+		var2 = var2 * 86400
+	}
+	v1 = now - var1
+	v2 = now - var2
+	return
+
+}
+
+//取抽奖模式
+func getMode() (resStr string) {
+	mode := redis.GetStr("other", "s_luckydraw_mode")
+	if mode == "0" {
+		resStr = "自动模式"
+	} else {
+		if mode == "" {
+			mode = "3"
+		}
+		resStr = "手动模式-" + mode
+	}
+	return
+}
+
+//解析内容
+func checkContent(con string) (b bool, cmd string, qleng int, unit string, var1, var2 int64) {
+	conOne := reg.FindSubmatch([]byte(con))
+	if len(conOne) == 3 {
+		str2 := strings.Split(string(conOne[2]), "-")
+		cmd = string(conOne[1])
+		if len(str2) == 1 {
+			qleng = 1
+			conTwo := subreg.FindSubmatch([]byte(str2[0]))
+			if len(conTwo) == 2 {
+				unit = "s"
+			} else if len(conTwo) == 3 {
+				if len(conTwo[2]) > 0 {
+					unit = string(conTwo[2])
+				} else if unit == "" {
+					unit = "s"
+				}
+			} else {
+				return
+			}
+			b = true
+			vartemp, _ := strconv.Atoi(string(conTwo[1]))
+			var1 = int64(vartemp)
+		} else if len(str2) == 2 {
+			qleng = 2
+			conTwo := subreg.FindSubmatch([]byte(str2[0]))
+			if len(conTwo) == 2 {
+				unit = "s"
+			} else if len(conTwo) == 3 {
+				if len(conTwo[2]) > 0 {
+					unit = string(conTwo[2])
+				} else if unit == "" {
+					unit = "s"
+				}
+			} else {
+				return
+			}
+			vartemp, _ := strconv.Atoi(string(conTwo[1]))
+			var1 = int64(vartemp)
+
+			conTwo2 := subreg.FindSubmatch([]byte(str2[1]))
+			if len(conTwo2) == 2 && unit == "" {
+				unit = "s"
+			} else if len(conTwo2) == 3 {
+				if len(conTwo2[2]) > 0 {
+					unit = string(conTwo2[2])
+				} else if unit == "" {
+					unit = "s"
+				}
+			} else {
+				return
+			}
+			vartemp2, _ := strconv.Atoi(string(conTwo2[1]))
+			var2 = int64(vartemp2)
+			b = true
+		} else {
+			return
+		}
+	}
+	return
+}

+ 10 - 2
weixin/src/qfw/weixinconfig/config_test.go

@@ -1,8 +1,16 @@
 package weixinconfig
 
-import ()
+import (
+	"log"
+	"regexp"
+	"testing"
+)
 
 //初始化
 func TestReadConfig(t *testing.T) {
-
+	r := regexp.MustCompile("^([a-z]+)(\\d.*)$")
+	s := r.FindSubmatch([]byte("esddfdsf23s-15s"))
+	for _, v := range s {
+		log.Println(string(v))
+	}
 }

+ 32 - 30
weixin/src/qfw/weixinconfig/weixinconfig.go

@@ -2,36 +2,38 @@ package weixinconfig
 
 //微信配置文件
 type wxconfig struct {
-	Domain          string            `json:"domain"`
-	Port            string            `json:"port"`
-	Imgpath         string            `json:"imgpath"`
-	Redisservers    string            `json:"redisServers"`   //redis缓存服务器列表
-	Mongodbservers  string            `json:"mongodbServers"` //mongodb节点
-	MongodbPoolSize int               `json:"mongodbPoolSize"`
-	MongodbName     string            `json:"mongodbName"`
-	Elasticsearch   string            `json:"elasticsearch"`
-	Rpcport         string            `json:"rpcport"`
-	ServiceTip      string            `json:"serviceTip"`
-	Appcontext      string            `json:"appcontext"`
-	Appid           string            `json:"appid"`
-	Token           string            `json:"token"`
-	Appsecret       string            `json:"appsecret"`
-	Aboutmeurl      string            `json:"aboutmeurl"`
-	Conactusurl     string            `json:"conactusurl"`
-	ElasticPoolSize int               `json:"elasticPoolSize"`
-	Wsqurl          string            `json:"wsqurl"`
-	EntAuthTip      string            `json:"entAuthTip"`
-	PerAuthTip      string            `json:"perAuthTip"`
-	OthAuthTip      string            `json:"othAuthTip"`
-	MessageTpl      map[string]string `json:"messagetpl"` //消息模板配置
-	WelcomeTip      string            `json:"welcomeTip"`
-	OWelcomeTip     string            `json:"oWelcomeTip"`
-	LoginTip        string            `json:"loginTip"`
-	FreezeTip       string            `json:"freezeTip"`
-	Activity        map[string]string `json:"activity"` //活动配置
-	WeixinAutoRpl   string            `json:"weixinautorpl"`
-	SubscribeMonitorCyc int `json:"subscribemonitorcyc"`
-	SubscribeMonitorTimes int `json:"subscribemonitortimes"`
+	Domain                string            `json:"domain"`
+	Port                  string            `json:"port"`
+	Imgpath               string            `json:"imgpath"`
+	Redisservers          string            `json:"redisServers"`   //redis缓存服务器列表
+	Mongodbservers        string            `json:"mongodbServers"` //mongodb节点
+	MongodbPoolSize       int               `json:"mongodbPoolSize"`
+	MongodbName           string            `json:"mongodbName"`
+	Elasticsearch         string            `json:"elasticsearch"`
+	Rpcport               string            `json:"rpcport"`
+	ServiceTip            string            `json:"serviceTip"`
+	Appcontext            string            `json:"appcontext"`
+	Appid                 string            `json:"appid"`
+	Token                 string            `json:"token"`
+	Appsecret             string            `json:"appsecret"`
+	Aboutmeurl            string            `json:"aboutmeurl"`
+	Conactusurl           string            `json:"conactusurl"`
+	ElasticPoolSize       int               `json:"elasticPoolSize"`
+	Wsqurl                string            `json:"wsqurl"`
+	EntAuthTip            string            `json:"entAuthTip"`
+	PerAuthTip            string            `json:"perAuthTip"`
+	OthAuthTip            string            `json:"othAuthTip"`
+	MessageTpl            map[string]string `json:"messagetpl"` //消息模板配置
+	WelcomeTip            string            `json:"welcomeTip"`
+	OWelcomeTip           string            `json:"oWelcomeTip"`
+	LoginTip              string            `json:"loginTip"`
+	FreezeTip             string            `json:"freezeTip"`
+	Activity              map[string]string `json:"activity"` //活动配置
+	WeixinAutoRpl         string            `json:"weixinautorpl"`
+	SubscribeMonitorCyc   int               `json:"subscribemonitorcyc"`
+	SubscribeMonitorTimes int               `json:"subscribemonitortimes"`
+	Mids                  []string          `json:"mids"`
+	Dir                   string            `json:"dir"`
 }
 
 //系统配置