Files
web_huangguo_web/app/api/web/ads_click.go
T
2026-10-29 16:39:28 +07:00

75 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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,
})
}