ad_event_record.go 1.55 KB
package apis

import (
	"log"
	"net/http"

	. "client/icesimba.ad/models"
	"github.com/gin-gonic/gin"
)

func PostAdEventApi(c *gin.Context) {

	var (
		code string
		msg  string
	)

	adId := c.Request.FormValue("ad_id")
	gameId := c.Request.FormValue("game_id")
	eventCode := c.Request.FormValue("event_code")
	positionId := c.Request.FormValue("position_id")
	positionVersion := c.Request.FormValue("versionCode")
	iceVersion := c.Request.FormValue("iceVersion")
	channel := c.Request.FormValue("channel")
	platform := c.Request.FormValue("platform")
	model := c.Request.FormValue("model")
	deviceId := c.Request.FormValue("deviceId")
	ip := c.Request.RemoteAddr

	if gameId == "" || eventCode == "" {
		code = "106100"
		msg = "missing parameter"
	} else {
		if eventCode == "icead_active" {
			err := PostAdEventActiveRecord(
				adId,
				positionId,
				gameId,
				positionVersion,
				iceVersion,
				channel,
				platform,
				model,
				deviceId,
				ip,
				eventCode,
			)
			if err != nil {
				code = "106101"
				msg = "create ad event record fail"
			}
			log.Println(err)
		} else {
			err := PostAdEventRecord(
				adId,
				positionId,
				gameId,
				positionVersion,
				iceVersion,
				channel,
				platform,
				model,
				deviceId,
				ip,
				eventCode,
			)
			if err != nil {
				code = "106101"
				msg = "create ad event record fail"
			}
			log.Println(err)
		}
	}

	if code == "0" {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"obj":  nil,
		})
	} else {
		c.JSON(http.StatusOK, gin.H{
			"code": code,
			"msg":  msg,
		})
	}
	log.Println(msg)
}