|
|
@@ -12,7 +12,6 @@ import (
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"github.com/pkg/errors"
|
|
|
- "go.mongodb.org/mongo-driver/v2/bson"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strconv"
|
|
|
@@ -22,9 +21,6 @@ import (
|
|
|
|
|
|
func ReceiveGameMsg(c *gin.Context) {
|
|
|
|
|
|
- //response.Success(c, gin.H{})
|
|
|
- //return
|
|
|
-
|
|
|
form := request.Check(c, &struct {
|
|
|
//Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
//Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
@@ -80,16 +76,18 @@ func ReceiveGameMsg(c *gin.Context) {
|
|
|
err = login(gid, pf, openId, form.UserId, now)
|
|
|
|
|
|
//调用接口,上传留存
|
|
|
- CheckRetention(gid, pf, openId)
|
|
|
+ //CheckRetention(gid, pf, openId)
|
|
|
} else if form.Action == "online" {
|
|
|
//活跃
|
|
|
err = online(gid, pf, openId, form.UserId, now)
|
|
|
|
|
|
+ err = SetOnline(gid, pf, 1, form.UserId, now)
|
|
|
err = SetLocalActiveLog(gid, pf, openId, form.UserId, 1, now)
|
|
|
+
|
|
|
} else if form.Action == "offline" {
|
|
|
//断开
|
|
|
err = offline(gid, pf, openId, form.UserId, now)
|
|
|
-
|
|
|
+ err = SetOnline(gid, pf, 2, form.UserId, now)
|
|
|
err = SetLocalActiveLog(gid, pf, openId, form.UserId, 2, now)
|
|
|
} else if form.Action == "seeAds" {
|
|
|
|
|
|
@@ -101,9 +99,6 @@ func ReceiveGameMsg(c *gin.Context) {
|
|
|
err = action(gid, pf, form.Action, form.UserId, now, form.Data)
|
|
|
}
|
|
|
|
|
|
- //调用接口,检测需不需要上传到巨量
|
|
|
- CheckUserActive(gid, pf, openId)
|
|
|
-
|
|
|
if err != nil {
|
|
|
response.Fail(c, 1003, err.Error())
|
|
|
return
|
|
|
@@ -149,6 +144,7 @@ func action(gid string, pf string, gameActionId string, userId int, now time.Tim
|
|
|
Gid: gid,
|
|
|
Pf: pf,
|
|
|
ActionId: gameActionId,
|
|
|
+ Date: now.Format("20060102"),
|
|
|
CreatedAt: model.XTime{Time: now},
|
|
|
}
|
|
|
|
|
|
@@ -242,10 +238,10 @@ func online(gid string, pf string, openId string, userId int, now time.Time) err
|
|
|
global.App.Log.Error("存储用户活跃信息失败", err.Error(), userOnline)
|
|
|
return err
|
|
|
}
|
|
|
- err = UpdateUserBehaviorDuration(gid, pf, openId, now, 1)
|
|
|
- if err != nil {
|
|
|
- global.App.Log.Error("存储用户在线时长mongo失败", err.Error(), userOnline)
|
|
|
- }
|
|
|
+ //err = UpdateUserBehaviorDuration(gid, pf, openId, now, 1)
|
|
|
+ //if err != nil {
|
|
|
+ // global.App.Log.Error("存储用户在线时长mongo失败", err.Error(), userOnline)
|
|
|
+ //}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
@@ -266,10 +262,10 @@ func offline(gid string, pf string, openId string, userId int, now time.Time) er
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- err = UpdateUserBehaviorDuration(gid, pf, openId, now, 2)
|
|
|
- if err != nil {
|
|
|
- global.App.Log.Error("存储用户在线时长mongo失败", err.Error(), userOnline)
|
|
|
- }
|
|
|
+ //err = UpdateUserBehaviorDuration(gid, pf, openId, now, 2)
|
|
|
+ //if err != nil {
|
|
|
+ // global.App.Log.Error("存储用户在线时长mongo失败", err.Error(), userOnline)
|
|
|
+ //}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
@@ -297,10 +293,10 @@ func seeAds(gid string, pf string, openId string, userId int, now time.Time, Ads
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- err = UpdateUserBehaviorAdInfo(gid, pf, openId, AdsState)
|
|
|
- if err != nil {
|
|
|
- global.App.Log.Error("存储用户观看广告mongo失败", err.Error(), userOnline)
|
|
|
- }
|
|
|
+ //err = UpdateUserBehaviorAdInfo(gid, pf, openId, AdsState)
|
|
|
+ //if err != nil {
|
|
|
+ // global.App.Log.Error("存储用户观看广告mongo失败", err.Error(), userOnline)
|
|
|
+ //}
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
@@ -373,59 +369,87 @@ func InitUser(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
func ReceiveAdsInfo(c *gin.Context) {
|
|
|
-
|
|
|
- //response.Success(c, gin.H{"data": "success"})
|
|
|
- //return
|
|
|
-
|
|
|
form := request.Check(c, &struct {
|
|
|
Aid string `form:"aid" json:"aid" binding:""`
|
|
|
Pid string `form:"pid" json:"pid" binding:""`
|
|
|
Cid string `form:"cid" json:"cid" binding:""`
|
|
|
}{})
|
|
|
|
|
|
- //存储参数
|
|
|
- global.App.Log.Info("ReceiveAdsInfo", form)
|
|
|
-
|
|
|
gid := c.GetString("gid")
|
|
|
pf := c.GetString("pf")
|
|
|
openId := c.GetString("openid")
|
|
|
|
|
|
- userId := gid + "|" + pf + "|" + openId
|
|
|
- global.App.Log.Info("userId", userId)
|
|
|
-
|
|
|
- id := userId + "|" + form.Aid
|
|
|
-
|
|
|
- aid, _ := strconv.Atoi(form.Aid)
|
|
|
- pid, _ := strconv.Atoi(form.Pid)
|
|
|
-
|
|
|
- collection := global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
-
|
|
|
- var adRelated model.AdRelated
|
|
|
- filter := bson.M{"_id": id}
|
|
|
- collection.FindOne(context.Background(), filter).Decode(&adRelated)
|
|
|
- if adRelated.Id == "" {
|
|
|
- //新增
|
|
|
- adData := model.AdRelated{
|
|
|
- UserId: userId,
|
|
|
- Id: id,
|
|
|
- Aid: int64(aid),
|
|
|
- Pid: int64(pid),
|
|
|
- Cid: form.Cid,
|
|
|
- Duration: 0,
|
|
|
- StartNum: 1,
|
|
|
- Revenue: 0,
|
|
|
- ReqCount: 0,
|
|
|
- ExpCount: 0,
|
|
|
- CreateTime: time.Now().Unix(),
|
|
|
- }
|
|
|
+ global.App.Log.Info(fmt.Sprintf("存入用户广告数据,用户信息:%s,%s,%s||广告信息:%s,%s,%s", gid, pf, openId, form.Aid, form.Pid, form.Cid))
|
|
|
|
|
|
- //更新到MongoDB 中
|
|
|
- _, err := collection.InsertOne(context.Background(), adData)
|
|
|
- if err != nil {
|
|
|
- response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
- return
|
|
|
+ var user model.User
|
|
|
+ global.App.DB.Table("user").
|
|
|
+ Where("gid", gid).
|
|
|
+ Where("pf", pf).
|
|
|
+ Where("openId", openId).Find(&user)
|
|
|
+
|
|
|
+ if user.ID == 0 {
|
|
|
+ global.App.Log.Info("上报广告信息时用户不存在")
|
|
|
+ response.Fail(c, 1003, "上报广告信息时用户不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //目前改为直接存储到mysql中
|
|
|
+ err := global.App.DB.Table("user").
|
|
|
+ Where("id", user.ID).
|
|
|
+ Updates(map[string]interface{}{
|
|
|
+ "aid": form.Aid,
|
|
|
+ "pid": form.Pid,
|
|
|
+ "cid": form.Cid,
|
|
|
+ }).Error
|
|
|
+ if err != nil {
|
|
|
+ global.App.Log.Error("存储用户的广告信息失败:", err.Error())
|
|
|
+ response.Fail(c, 501, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //调用接口,将激活上传到巨量
|
|
|
+ if user.Pf == "tt" {
|
|
|
+ ok := OceanReport("active", form.Cid)
|
|
|
+ if !ok {
|
|
|
+ global.App.Log.Info("上报激活数据到抖音巨量失败")
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //userId := gid + "|" + pf + "|" + openId
|
|
|
+ //
|
|
|
+ //id := userId + "|" + form.Aid
|
|
|
+ //
|
|
|
+ //aid, _ := strconv.Atoi(form.Aid)
|
|
|
+ //pid, _ := strconv.Atoi(form.Pid)
|
|
|
+ //
|
|
|
+ //collection := global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
+ //
|
|
|
+ //var adRelated model.AdRelated
|
|
|
+ //filter := bson.M{"_id": id}
|
|
|
+ //collection.FindOne(context.Background(), filter).Decode(&adRelated)
|
|
|
+ //if adRelated.Id == "" {
|
|
|
+ // //新增
|
|
|
+ // adData := model.AdRelated{
|
|
|
+ // UserId: userId,
|
|
|
+ // Id: id,
|
|
|
+ // Aid: int64(aid),
|
|
|
+ // Pid: int64(pid),
|
|
|
+ // Cid: form.Cid,
|
|
|
+ // Duration: 0,
|
|
|
+ // StartNum: 1,
|
|
|
+ // Revenue: 0,
|
|
|
+ // ReqCount: 0,
|
|
|
+ // ExpCount: 0,
|
|
|
+ // CreateTime: time.Now().Unix(),
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // //更新到MongoDB 中
|
|
|
+ // _, err := collection.InsertOne(context.Background(), adData)
|
|
|
+ // if err != nil {
|
|
|
+ // response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ //}
|
|
|
////关联到userInfo 上
|
|
|
//filter = bson.M{"_id": userId}
|
|
|
//update := bson.M{
|
|
|
@@ -445,6 +469,32 @@ func ReceiveAdsInfo(c *gin.Context) {
|
|
|
response.Success(c, gin.H{"data": "success"})
|
|
|
}
|
|
|
|
|
|
+func ReceiveGameAdsCheck(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ UserId int `form:"userId" json:"userId" binding:"required"`
|
|
|
+ Timestamp int64 `form:"timestamp" json:"timestamp" binding:"required"`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ now := time.UnixMilli(form.Timestamp)
|
|
|
+
|
|
|
+ gid := c.GetString("gid")
|
|
|
+ pf := c.GetString("pf")
|
|
|
+
|
|
|
+ err := global.App.DB.Table("user_ads_check").Create(map[string]interface{}{
|
|
|
+ "userId": form.UserId,
|
|
|
+ "gid": gid,
|
|
|
+ "pf": pf,
|
|
|
+ "createdAt": now,
|
|
|
+ "date": now.Format("20060102"),
|
|
|
+ }).Error
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 501, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{"data": "success"})
|
|
|
+}
|
|
|
+
|
|
|
func SetLocalActiveLog(gid string, pf string, openId string, userId int, types int, now time.Time) error {
|
|
|
// 生成日期目录路径(示例:./data/2024-06-15)
|
|
|
dateDir := now.Format("2006-01-02")
|