Explorar o código

Merge branch 'dev2.10.8' of ssh://192.168.3.207:10022/qmx/jy into dev2.10.8

wangchuanjin %!s(int64=5) %!d(string=hai) anos
pai
achega
4ae7ec03e8

+ 7 - 7
src/jfw/modules/pushLiveAct/src/buynum/buynum.go

@@ -19,16 +19,20 @@ var liveactiveRTB = "liveactiveRTB"
 // 23~7 -9
 func Buynum() {
 	log.Println("开始生成:", time.Now().Format(util.Date_Full_Layout))
-	log.Println("预计结束时间:", time.Unix(config.Conf.Endlive, 0).Format(util.Date_Full_Layout))
+	log.Println("预计结束时间:", time.Unix(config.Conf.Endtime, 0).Format(util.Date_Full_Layout))
 	i := util.If(redis.GetInt("other", liveactiveRTB) > 0, redis.GetInt("other", liveactiveRTB), 1)
 	for {
+		if time.Now().Unix() >= config.Conf.Endtime {
+			log.Println("结束。。。", time.Now().Format(util.Date_Full_Layout), "人数:", redis.Get("other", liveactiveRTB))
+			return
+		}
 		hour := time.Now().Hour()
 		if hour < 8 || hour >= 23 {
 			if time.Now().Minute() == 13 {
 				i = redis.GetInt("other", liveactiveRTB) + 1
 			}
 		} else {
-			start := time.Unix(config.Conf.Endlive, 0).AddDate(0, 0, -4)
+			start := time.Unix(config.Conf.Endtime, 0).AddDate(0, 0, -4)
 			random := big.NewInt(8)
 			if time.Now().Day() < start.Day() {
 				random = big.NewInt(11)
@@ -37,12 +41,8 @@ func Buynum() {
 			log.Println("新增:", result)
 			i = redis.GetInt("other", liveactiveRTB) + int(result.Int64())
 		}
-		timeout := config.Conf.Endlive + 60*60*24*30 - time.Now().Unix()
+		timeout := config.Conf.Endtime + 60*60*24*30 - time.Now().Unix()
 		redis.Put("other", liveactiveRTB, i, int(timeout))
-		if time.Now().Unix() >= config.Conf.Endlive {
-			log.Println("结束。。。", time.Now().Format(util.Date_Full_Layout), "人数:", redis.Get("other", liveactiveRTB))
-			return
-		}
 		time.Sleep(time.Second * 60)
 	}
 }

+ 3 - 9
src/jfw/modules/pushLiveAct/src/config.json

@@ -5,7 +5,7 @@
 	"weixinrpc": "127.0.0.1:8083",
 	"pushPoolSize":5,
 	"wxTplMsg":{
-		"id":"NTYrV-yHFjHzlmH_gM3rDTAYl3DPJO-EXZY1C3Ntr94",
+		"id":"qC-HuigdtVQ6hAILuC6r5nS1ARSYoLkxsBV1Oi3Vy9I",
 		"first":{
 			"value":"VIP订阅6折活动将于20:00开始,抖音/快手搜索剑鱼标讯参与直播,抢最高388元延期码!",
 			"color":"#686868"
@@ -35,12 +35,6 @@
 		"maxIdleConns":200
     },
     "redisaddrs":"other=192.168.3.128:1712",
-    "starttime":1594123200,
-    "secondtime":1594256400,
-    "thirdtime":1594688400,
-    "first_cron": "0 47 11 24 * ?",
-    "second_cron": "0 38 10 24 * ?",
-    "third_cron":"0 38 10 24 * ?",
-    "redis_cron":"0 5 15 24 * ?",
-    "endlive":1594728000
+    "starttime":1593073102,
+    "endtime":1593073342
 }

+ 1 - 2
src/jfw/modules/pushLiveAct/src/config/config.go

@@ -32,8 +32,7 @@ type SysConfig struct {
 	First_cron  string                 `json:"first_cron"` //定时任务
 	Second_cron string                 `json:"second_cron"`
 	Third_cron  string                 `json:"third_cron"`
-	Redis_cron  string                 `json:"redis_cron"` //生成人数
-	Endlive     int64                  `json:"endlive"`    //活动结束时间
+	Endtime     int64                  `json:"endtime"` //活动结束时间
 }
 
 func init() {

+ 21 - 20
src/jfw/modules/pushLiveAct/src/main.go

@@ -3,12 +3,14 @@ package main
 import (
 	"buynum"
 	"config"
+	"fmt"
 	"log"
 	"push"
 	qu "qfw/util"
 	"qfw/util/mongodb"
 	"qfw/util/mysql"
 	"qfw/util/redis"
+	"time"
 
 	"github.com/robfig/cron"
 )
@@ -17,8 +19,8 @@ func main() {
 	mongodb.InitMongodbPool(config.Conf.MongodbPoolSize, config.Conf.MongodbServers, "qfw")
 	InitMysql(config.Conf.MysqlCfg)
 	redis.InitRedis(config.Conf.RedisAddrs)
-	go task()
-	//go buynum.Buynum()
+	go timetask()
+	// go buynum.Buynum()
 	//start(2)
 
 	chan bool(nil) <- true
@@ -42,22 +44,21 @@ func InitMysql(mysql_m map[string]interface{}) {
 	config.Mysql.Init()
 }
 
-func task() {
-	c := cron.New()
-	// c.AddFunc(config.Conf.First_cron, func() {
-	// 	log.Println("--")
-	// 	start(1)
-	// })
-	// c.AddFunc(config.Conf.Second_cron, func() {
-	// 	start(2)
-	// })
-	// c.AddFunc(config.Conf.Third_cron, func() {
-	// 	start(3)
-	// })
-	c.AddFunc(config.Conf.Redis_cron, func() {
-		buynum.Buynum()
-	})
-	c.Start()
-	defer c.Stop()
-	select {}
+func timetask() {
+	if time.Now().Unix() >= config.Conf.Starttime {
+		if time.Now().Unix() < config.Conf.Endtime {
+			buynum.Buynum()
+		}
+	} else {
+		c := cron.New()
+		crontime := time.Unix(config.Conf.Starttime, 0)
+		crontime_ := fmt.Sprintf("0 %v %v %v * ?", crontime.Minute(), crontime.Hour(), crontime.Day())
+		log.Println(crontime_)
+		c.AddFunc(crontime_, func() {
+			buynum.Buynum()
+		})
+		c.Start()
+		defer c.Stop()
+		select {}
+	}
 }

+ 1 - 1
src/jfw/modules/pushLiveAct/src/push/push.go

@@ -17,7 +17,7 @@ var se = util.SimpleEncrypt{Key: "topnet"}
 func PushLive(typ int) {
 	user := []map[string]interface{}{}
 	query := map[string]interface{}{
-		"s_m_openid": "o8-2pwEmWuBjojzw5Q8IIBQSf9Bw",
+		"s_m_openid": "o043a5hr4gD9e1Yy8DSNjy9BX3U4",
 	}
 	all := mongodb.Find("user", query, nil, `{"_id":1,"s_nickname":1,"o_vipjy":1,"a_jpushid":1,"s_jpushid":1,"s_opushid":1,"s_m_openid":1,"s_appponetype":1,"i_applystatus":1}`, false, 0, 0)
 	for _, v := range *all {