ad.go
1.43 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
package apis
import (
"log"
"net/http"
. "client/icesimba.ad/models"
"github.com/gin-gonic/gin"
)
type Obj struct {
AdId string `json:"adid"`
Url string `json:"url"`
Materials []Material `json:"materials"`
}
func QueryAdMaterialApi(c *gin.Context) {
var (
code string
msg string
)
gameId := c.Request.FormValue("game_id")
positionId := c.Request.FormValue("position_id")
platform := c.Request.FormValue("platform")
channel := c.Request.FormValue("channel")
obj := Obj{}
if gameId == "" || positionId == "" {
code = "106000"
msg = "missing parameter"
} else {
sell := SellPlan{
GameId: gameId,
PositionId: positionId,
}
sells, err := sell.QueryAdIdByPositionId()
if err != nil || len(sells) <= 0 {
code = "1006001"
msg = "this position is no ads"
} else {
sell, err = SellsFilter(sells)
if err != nil {
code = "1006001"
msg = "this position is no ads"
} else {
code = "0"
obj.AdId = sell.AdId
obj.Materials, _ = sell.QueryMaterialByAdId()
obj.Url, _ = GetAdDownloadUrl(sell.AdId, platform, channel)
}
}
if err != nil {
log.Printf("QueryAdMaterialApi error:" + err.Error() + "\n")
}
}
if code == "0" {
c.JSON(http.StatusOK, gin.H{
"code": code,
"obj": obj,
})
} else {
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": msg,
})
}
log.Printf("return json \n" + "code:" + code + "\t msg:" + msg + "\n")
log.Println(obj)
}