checkreward.go
1.81 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
package models
import (
"fmt"
db "client/icesimba.mail/database"
)
/**
* 查询是否有奖励未被阅读
* @userId: 用户的id
* @funcType: 是否将未阅读修改成阅读
*/
func CheckRewards(rewardIn RewardIn, funcType string) (result string, err error, out RewardOut) {
rewardIn.InsertRewardUser()
userId := rewardIn.UserId
sqlQue := "select REWARDID from ice_reward_user where USERID=? and ISREAD=0 order by STARTTIME desc"
rows, err := db.SqlDB.Query(sqlQue, userId)
if err != nil {
// fmt.Println("sele ct rewardid err")
return
}
var rewardid string
//如果有返回结果,根据funcType来决定是否update
for rows.Next() {
err = rows.Scan(
&rewardid,
)
if err != nil {
// fmt.Println("scan err")
return
}
fmt.Println(rewardid)
out, err = getRewardContent(rewardid, userId)
if err != nil {
// fmt.Println("get rewardcontent err")
return
}
result = "true"
if funcType == "true" {
sqlQue = "update ice_reward_user set ISREAD=1 where USERID=? and ISREAD=0"
_, err = db.SqlDB.Exec(sqlQue, userId)
if err != nil {
// fmt.Println("update isread err")
return
}
}
return
}
result = "false"
return
}
func getRewardContent(rewardid string, userId string) (out RewardOut, err error) {
var (
title string
content string
starttime int64
)
icon := QueryRPIcon(rewardid)
sqlQue := "select TITLE,CONTENT,STARTTIME from ice_reward where ID=?"
err = db.SqlDB.QueryRow(sqlQue, rewardid).Scan(
&title,
&content,
&starttime,
)
if err != nil {
return
}
rewardJson := RewardJson{
RUId: userId,
Title: title,
Content: content,
Createtime: starttime,
Icon: icon,
}
out.RewardJsons = append(out.RewardJsons, rewardJson)
return
}