广告点击添加

This commit is contained in:
谢宇宁
2026-10-29 16:39:28 +07:00
parent 3879f5a71c
commit bfc26aa5ab
12 changed files with 209 additions and 3 deletions
+74
View File
@@ -0,0 +1,74 @@
package web
import (
"net/http"
"videoweb/app/service/configser"
"videoweb/pub/common/log"
"github.com/gin-gonic/gin"
)
type adsClickBody struct {
AdsID int64 `json:"adsId"`
Location int64 `json:"location"`
}
// AdsClick 代理上游 POST /api/app/ads/click;appId 由服务端固定填写。
func AdsClick(c *gin.Context) {
var body adsClickBody
if err := c.ShouldBindJSON(&body); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "参数错误",
"data": nil,
})
return
}
if body.AdsID <= 0 || body.Location <= 0 {
c.JSON(http.StatusOK, gin.H{
"code": 1001,
"msg": "参数错误",
"tip": "缺少 adsId 或 location",
"data": nil,
})
return
}
env, err := configser.AdsClick(c, configser.AdsClickReq{
AdsID: body.AdsID,
Location: body.Location,
})
if err != nil {
log.Error("ads click upstream failed", log.E(err))
c.JSON(http.StatusOK, gin.H{
"code": 500,
"msg": "ads click failed",
"tip": "上报失败",
"data": nil,
})
return
}
if env == nil || env.Code != 200 {
code := 500
msg := ""
if env != nil {
code = env.Code
msg = env.Msg
}
c.JSON(http.StatusOK, gin.H{
"code": code,
"msg": msg,
"tip": firstNonEmpty(msg, "上报失败"),
"data": nil,
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"msg": env.Msg,
"tip": firstNonEmpty(env.Msg, "success"),
"data": nil,
})
}