reward.go
3.97 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package models
import (
"common"
"database/sql"
"fmt"
"time"
db "client/icesimba.mail/database"
)
type Reward struct {
Id string //奖励id
Title string //奖励标题
Content string //奖励消息内容
TrigType int64 //触发类型 0,开启应用
EndTime int64 //结束时间
ValidTime int64
}
type RewardDB struct {
Id sql.NullString //奖励id
Title sql.NullString //奖励标题
Content sql.NullString //奖励消息内容
TrigType sql.NullInt64 //触发类型 0,开启应用
EndTime sql.NullInt64 //结束时间
ValidTime sql.NullInt64
}
type Rewards struct {
//游戏id
GameReward []Reward
}
func (in *Rewards) QueryRewardByGameId(gameId, platform string, version int64) (out Rewards, err error) {
currTime := time.Now().UnixNano() / 1e6
common.Printf("select * from ice_reward where gameid=%s\n", gameId)
sqlQue := "select id,title,content,trigtype,endtime,validtime from ice_reward" +
" where" +
" gameid=? AND" +
" (ACTTYPE=1 OR (STARTTIME < ? AND ENDTIME > ?)) AND" +
" USERFILTER='' AND (PLATFILTER=? or PLATFILTER='all') AND" +
" VERSIONFILTER<? AND" +
" ISDEL=0"
rows, err := db.SqlDB.Query(sqlQue, gameId, currTime, currTime, platform, version)
if err != nil {
common.Println(err)
return
}
for rows.Next() {
reward := Reward{}
rewarddb := RewardDB{}
err = rows.Scan(
&rewarddb.Id,
&rewarddb.Title,
&rewarddb.Content,
&rewarddb.TrigType,
&rewarddb.EndTime,
&rewarddb.ValidTime,
)
if rewarddb.Id.Valid {
reward.Id = rewarddb.Id.String
}
if rewarddb.Title.Valid {
reward.Title = rewarddb.Title.String
}
if rewarddb.Content.Valid {
reward.Content = rewarddb.Content.String
}
if rewarddb.TrigType.Valid {
reward.TrigType = rewarddb.TrigType.Int64
}
if rewarddb.EndTime.Valid {
reward.EndTime = rewarddb.EndTime.Int64
}
if rewarddb.ValidTime.Valid {
reward.ValidTime = rewarddb.ValidTime.Int64
}
out.GameReward = append(out.GameReward, reward)
}
if err != nil {
common.Println(err)
return
}
return
}
/*通过 reward_id获得 reward 的title和content,返回奖励的title 和 content 以及奖励icon*/
func (in *Reward) QueryReward(gameID string) (out Reward, icon string, err error) {
fmt.Printf("select * from ice_reward where id=%s\n", in.Id)
sqlQue := "select title,content from ice_reward where id=? and gameid=? limit 1"
row := db.SqlDB.QueryRow(sqlQue, in.Id, gameID)
rewarddb := RewardDB{}
err = row.Scan(
&rewarddb.Title,
&rewarddb.Content,
)
if err != nil {
return
}
if rewarddb.Title.Valid {
out.Title = rewarddb.Title.String
}
if rewarddb.Content.Valid {
out.Content = rewarddb.Content.String
}
icon = QueryRPIcon(in.Id)
return
}
//func (in *Reward) InsertOrUpdateGiftSet() (code int, out Reward, err error) {
// code, out, err = in.QueryReward()
// if err != nil {
// sqlIn := "insert into ice_giftset(gsid,gid,cftype,gtitle,gcontent,pushtype,startdata,enddata,userfilter,versionfilter,platfilter) values (?,?,?,?,?,?,?,?,?,?,?)"
// _, err = db.SqlDB.Exec(
// sqlIn,
// &in.GSId,
// &in.GameId,
// &in.TrigType,
// &in.Title,
// &in.Content,
// &in.ActType,
// &in.StartTime,
// &in.EndTime,
// &in.UserFilter,
// &in.VersionFilter,
// &in.PlatFilter,
// )
// if err != nil {
// err = errors.New("插入数据失败")
// code = 400
// return
// }
// code = 200
// } else {
// // sqlIn = "update ice_giftset set gid= cftype,gtitle,gcontent,pushtype,startdata,enddata,userfilter,versionfilter,platfilter) values (?,?,?,?,?,?,?,?,?,?,?)"
// // _, err = db.SqlDB.Exec(
// // sqlIn,
// // &in.GSId,
// // &in.GameId,
// // &in.TriggerType,
// // &in.GiftTitle,
// // &in.GiftContent,
// // &in.PushType,
// // &in.StartTime,
// // &in.EndTime,
// // &in.UserFilter,
// // &in.VersionFilter,
// // &in.PlatFilter,
// // )
// // if err != nil {
// // err = errors.New("插入数据失败")
// // code = 400
// // return
// // }
// // code = 200
// }
// return
//}