ranksendreward.go
3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"client/sdkdb"
"client/sdkredis"
"common"
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
"time"
)
func main() {
log.Printf("---------------------------ranksendreward begin--------------------------------")
configPath := flag.String("config", "./sdkRoute.conf", "config path")
flag.Parse()
fmt.Printf("config[%v]", *configPath)
config := common.NewConfig(*configPath)
// db初始化
sdkdb.DBInit()
// 连接数据库
dberr := sdkdb.DBRegis(config.DBMysql)
if dberr != nil {
log.Printf("DBRegis err[%v]\n", dberr)
return
}
// 设置数据库日志
sdkdb.SetLogDebug(true, os.Stdout)
// redis 初始化
sdkredis.RedisInit(config)
// 连接redis
redisConn := sdkredis.RedisClient.GetConn()
defer sdkredis.RedisClose(redisConn)
// 获得所有的排行
log.Printf("get all ranks ...")
/*
keys, err := sdkredis.RedisGetKeys(redisConn, "ice_gametopset:*gtname")
if err != nil {
sdkredis.RedisClose(redisConn)
log.Printf("RedisGetKeys keys[%s] err[%v]\n", keys, err)
return
}
*/
keys, err := sdkdb.IceGameTopSetQueryTotal()
if err != nil {
log.Printf("IceGameTopSetQueryTotal keys[%s] err[%v]\n", keys, err)
}
log.Printf("ranks num[%d]", len(keys))
if len(keys) == 0 {
return
}
for _, key := range keys {
/*
index0 := strings.Index(key, ":gtid:")
index1 := strings.Index(key, ":gid:")
index2 := strings.Index(key, ":toptype:")
index3 := strings.Index(key, ":gtname")
gtid := common.Substr2(key, index0+6, index1)
gid := common.Substr2(key, index1+5, index2)
toptype := common.Substr2(key, index2+9, index3)
*/
gtid := key.GTID
gid := key.GID
toptype := key.TOPTYPE
// 获得奖励ID
log.Printf("get rank reward id---gid[%v] gtid[%v] toptype[%v]", gid, gtid, toptype)
iceReward, _ := sdkdb.IceRewardQueryIDWithRank(gtid, gid, toptype)
if iceReward == nil {
log.Printf("this rank has no reward---gid[%v] gtid[%v] toptype[%v]", gid, gtid, toptype)
continue
}
for _, v := range iceReward {
log.Printf("iceReward rewardId[%v] title[%v] content[%v] UserFilter[%v]", v.Id, v.Title, v.Content, v.UserFilter)
// 判断奖励是否失效 update time :2017年9月4日11:22:27 update by 徐振浩
// update start
nowTime := time.Now().UnixNano() / 1e6
if v.StartTime > nowTime || v.EndTime < nowTime {
log.Printf("this rank reward has been expired-----rewardId[%v] nowtime[%d] starttime[%d] endtime[%d]", v.Id, nowTime, v.StartTime, v.EndTime)
continue
}
// update end
seIndex := strings.Index(v.UserFilter, ",")
start, _ := strconv.Atoi(common.Substr2(v.UserFilter, 0, seIndex))
end, _ := strconv.Atoi(common.Substr2(v.UserFilter, seIndex+1, len(v.UserFilter)))
// 待发放奖励的用户列表
log.Printf("get rank user--gtid[%v] gid[%v] toptype[%v] start[%d] end[%d]", gtid, gid, toptype, start, end)
igts := sdkredis.IceGametopRedisSort(gtid, gid, toptype, start, end)
rank := start
log.Printf("send to user begin...")
if igts != nil {
for _, igt := range igts {
userID := igt.UID
nowTime := time.Now().UnixNano() / 1e6
invalidTime := nowTime + v.ValidTime
// 发放奖励
srErr := sdkdb.IceRewardUserSendReward(userID, v.Id, 1, 0, nowTime, invalidTime, rank, v.Title, v.Content, v.GTName)
if srErr != nil {
sdkredis.RedisClose(redisConn)
return
}
log.Printf("send to user[%v]", userID)
rank++
}
}
log.Printf("send to user end...")
}
}
sdkredis.RedisRPush(redisConn, "IsRankClean", "clean")
log.Printf("send rankclean command")
log.Printf("---------------------------ranksendreward end--------------------------------")
}