handler.go
2.78 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
package handler
import (
"net/http"
"client/gift/common"
"client/gift/db"
"client/gift/model"
"client/gift/utils"
"client/gift/utils/render"
"errors"
"log"
)
func TestGetGiftFunc(w http.ResponseWriter, r *http.Request) {
gameCode := r.URL.Query().Get("gift_code")
userID := r.URL.Query().Get("user_id")
gameID := r.URL.Query().Get("game_id")
if len(gameID) == 0 || len(gameCode) == 0 || len(userID) == 0 {
render.BindError(w, r, errors.New("获取参数错误"))
return
}
giftResults, err := model.GetGiftPropid(db.Mysql, gameCode, gameID)
if err != nil {
render.InternalError(w, r, err)
return
}
if len(giftResults.Gifts) == 0 {
render.InternalError(w, r, errors.New("查询结果为空"))
return
}
render.JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.OK,
"obj": giftResults,
})
return
}
func PingHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
return
}
func GetGiftContent(w http.ResponseWriter, r *http.Request) {
var giftReq GiftReq
giftReq.GiftCode = r.PostFormValue("gift_code")
giftReq.GameID = r.PostFormValue("game_id")
giftReq.User = r.PostFormValue("user_id")
giftReq.ChannelName = r.PostFormValue("channel")
giftReq.PlatformName = r.PostFormValue("platform")
log.Print("parameters:", giftReq)
if !utils.CheckParam(giftReq.GiftCode) {
render.BindError(w, r, errors.New("建议检查礼包码"))
return
}
if giftReq.GiftCode == "" || giftReq.GameID == "" || giftReq.User == "" {
render.BindError(w, r, errors.New("缺少"))
return
}
//检查同一task是否领过。
gained, err := model.CheckTaskRepeat(db.Mysql, giftReq.GiftCode, giftReq.User)
if err != nil {
render.InternalError(w, r, errors.New("检出task重复时出错:"+err.Error()))
return
}
if gained {
render.TaskRepeatError(w, r, nil)
return
}
//查到propid 和 account,,,time,code as parameters
giftResults, err := model.GetGiftPropid(db.Mysql, giftReq.GiftCode, giftReq.GameID)
if err != nil {
render.InternalError(w, r, err)
return
}
log.Println("result:", giftResults.Gifts)
//上边为空,不调用。
if len(giftResults.Gifts) > 0 {
_, err := model.SetCheckStatus(db.Mysql, giftReq.User, giftReq.GiftCode)
if err != nil {
render.InternalError(w, r, errors.New(" 设置用户时出错"))
return
}
render.JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.OK,
"obj": giftResults,
})
return
}
if len(giftResults.Gifts) == 0 {
checkErr := model.CheckNullReason(db.Mysql, giftReq.GiftCode)
if checkErr != nil {
checkErr = errors.New(" 未获取到内容" + checkErr.Error())
render.InternalNullError(w, r, checkErr)
return
}
render.InternalNullError(w, r, errors.New(" 建议检查gameID"))
return
}
render.InternalNullError(w, r, errors.New(" "))
return
}