|
@@ -2,133 +2,111 @@ package v1
|
|
|
|
|
|
import (
|
|
import (
|
|
"context"
|
|
"context"
|
|
- "designs/app/common/request"
|
|
|
|
"designs/app/common/response"
|
|
"designs/app/common/response"
|
|
|
|
+ "designs/config"
|
|
"designs/global"
|
|
"designs/global"
|
|
|
|
+ "designs/model"
|
|
"designs/service"
|
|
"designs/service"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"errors"
|
|
"errors"
|
|
|
|
+ "fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/gin-gonic/gin"
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
"strconv"
|
|
"strconv"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-type AdData struct {
|
|
|
|
- Pid string `json:"pid" bson:"pid"`
|
|
|
|
- Aid string `json:"aid" bson:"aid"`
|
|
|
|
- Cid string `json:"cid" bson:"cid"`
|
|
|
|
- //ReportUrl string `json:"reportUrl" bson:"reportUrl"`
|
|
|
|
- Reported bool `json:"reported" bson:"reported"`
|
|
|
|
- Duration int64 `json:"duration" bson:"duration"`
|
|
|
|
- AdReqCount uint8 `json:"adReqCount" bson:"adReqCount"`
|
|
|
|
- AdEposedcount uint8 `json:"adEposedcount" bson:"adEposedcount"`
|
|
|
|
- CreateTime int `json:"createTime" bson:"createTime"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-type UserBehavior struct {
|
|
|
|
- Id string `bson:"_id,omitempty"`
|
|
|
|
- Gid string `bson:"gid" json:"gid"`
|
|
|
|
- Pf string `bson:"pf" json:"pf"`
|
|
|
|
- OpenId string `bson:"openId" json:"openId"`
|
|
|
|
- AdData interface{} `bson:"adData" json:"adData"`
|
|
|
|
- AdFromCount int `bson:"adFromCount" json:"adFromCount"`
|
|
|
|
- TotalDuration int `bson:"totalDuration" json:"totalDuration"`
|
|
|
|
- TotalAdReqCount int `bson:"totalAdReqCount" json:"totalAdReqCount"`
|
|
|
|
- TotalAdEposedCount int `bson:"totalAdEposedCount" json:"totalAdEposedCount"`
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func ReceiveUserBehavior(c *gin.Context) {
|
|
|
|
- form := request.Check(c, &struct {
|
|
|
|
- Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
|
- Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
|
- OpenId string `form:"openId" json:"openId" binding:"required"`
|
|
|
|
- AdData interface{} `form:"adData" json:"adData" binding:""`
|
|
|
|
- AdFromCount int `form:"adFromCount" json:"adFromCount" binding:""`
|
|
|
|
- TotalDuration int `form:"totalDuration" json:"totalDuration" binding:""`
|
|
|
|
- TotalAdReqCount int `form:"totalAdReqCount" json:"totalAdReqCount" binding:""`
|
|
|
|
- TotalAdEposedCount int `form:"totalAdEposedCount" json:"totalAdEposedCount" binding:""`
|
|
|
|
- }{})
|
|
|
|
-
|
|
|
|
- //if form.AdData != nil {
|
|
|
|
- // var AdData map[string]interface{}
|
|
|
|
- //}
|
|
|
|
- behavior := UserBehavior{
|
|
|
|
- Id: form.Gid + "|" + form.Pf + "|" + form.OpenId,
|
|
|
|
- Gid: form.Gid,
|
|
|
|
- Pf: form.Pf,
|
|
|
|
- OpenId: form.OpenId,
|
|
|
|
- AdData: form.AdData,
|
|
|
|
- AdFromCount: form.AdFromCount,
|
|
|
|
- TotalDuration: form.TotalDuration,
|
|
|
|
- TotalAdReqCount: form.TotalAdReqCount,
|
|
|
|
- TotalAdEposedCount: form.TotalAdEposedCount,
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
|
-
|
|
|
|
- filter := bson.M{"_id": behavior.Id}
|
|
|
|
- result := make(map[string]interface{})
|
|
|
|
- err := collection.FindOne(context.Background(), filter).Decode(&result)
|
|
|
|
-
|
|
|
|
- if len(result) == 0 {
|
|
|
|
- //新增
|
|
|
|
- _, err = collection.InsertOne(context.Background(), behavior)
|
|
|
|
- if err != nil {
|
|
|
|
- response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- var newAdData AdData
|
|
|
|
- adData, _ := json.Marshal(form.AdData)
|
|
|
|
- json.Unmarshal(adData, &newAdData)
|
|
|
|
-
|
|
|
|
- var oldAdData AdData
|
|
|
|
- oldAdDatas, _ := json.Marshal(result["adData"])
|
|
|
|
- json.Unmarshal(oldAdDatas, &oldAdData)
|
|
|
|
-
|
|
|
|
- newAdData.Reported = oldAdData.Reported
|
|
|
|
-
|
|
|
|
- //更新到MongoDB 中
|
|
|
|
- update := bson.M{
|
|
|
|
- "$set": struct {
|
|
|
|
- Gid string `bson:"gid" json:"gid"`
|
|
|
|
- Pf string `bson:"pf" json:"pf"`
|
|
|
|
- OpenId string `bson:"openId" json:"openId"`
|
|
|
|
- AdData interface{} `bson:"adData" json:"adData"`
|
|
|
|
- AdFromCount int `bson:"adFromCount" json:"adFromCount"`
|
|
|
|
- TotalDuration int `bson:"totalDuration" json:"totalDuration"`
|
|
|
|
- TotalAdReqCount int `bson:"totalAdReqCount" json:"totalAdReqCount"`
|
|
|
|
- TotalAdEposedCount int `bson:"totalAdEposedCount" json:"totalAdEposedCount"`
|
|
|
|
- }{
|
|
|
|
- Gid: behavior.Gid,
|
|
|
|
- Pf: behavior.Pf,
|
|
|
|
- OpenId: behavior.OpenId,
|
|
|
|
- AdData: newAdData,
|
|
|
|
- AdFromCount: behavior.AdFromCount,
|
|
|
|
- TotalDuration: behavior.TotalDuration,
|
|
|
|
- TotalAdReqCount: behavior.TotalAdReqCount,
|
|
|
|
- TotalAdEposedCount: behavior.TotalAdEposedCount,
|
|
|
|
- },
|
|
|
|
- }
|
|
|
|
- _, err = collection.UpdateOne(context.Background(), filter, update)
|
|
|
|
- if err != nil {
|
|
|
|
- response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //如果是从广告获取进来的用户,则需要检测是否上传
|
|
|
|
- if form.AdData != nil {
|
|
|
|
- res := service.OceanReportAction(behavior.Id)
|
|
|
|
- if res.Code != 0 {
|
|
|
|
- //上传出现了问题,或者并没有上传
|
|
|
|
- global.App.Log.Error(res.Code, res.Message)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- response.Success(c, gin.H{})
|
|
|
|
-}
|
|
|
|
|
|
+//func ReceiveUserBehavior(c *gin.Context) {
|
|
|
|
+// form := request.Check(c, &struct {
|
|
|
|
+// Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
|
+// Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
|
+// OpenId string `form:"openId" json:"openId" binding:"required"`
|
|
|
|
+// AdData interface{} `form:"adData" json:"adData" binding:""`
|
|
|
|
+// AdFromCount int `form:"adFromCount" json:"adFromCount" binding:""`
|
|
|
|
+// TotalDuration int `form:"totalDuration" json:"totalDuration" binding:""`
|
|
|
|
+// TotalAdReqCount int `form:"totalAdReqCount" json:"totalAdReqCount" binding:""`
|
|
|
|
+// TotalAdEposedCount int `form:"totalAdEposedCount" json:"totalAdEposedCount" binding:""`
|
|
|
|
+// }{})
|
|
|
|
+//
|
|
|
|
+// //if form.AdData != nil {
|
|
|
|
+// // var AdData map[string]interface{}
|
|
|
|
+// //}
|
|
|
|
+// behavior := UserBehavior{
|
|
|
|
+// Id: form.Gid + "|" + form.Pf + "|" + form.OpenId,
|
|
|
|
+// Gid: form.Gid,
|
|
|
|
+// Pf: form.Pf,
|
|
|
|
+// OpenId: form.OpenId,
|
|
|
|
+// AdData: form.AdData,
|
|
|
|
+// AdFromCount: form.AdFromCount,
|
|
|
|
+// TotalDuration: form.TotalDuration,
|
|
|
|
+// TotalAdReqCount: form.TotalAdReqCount,
|
|
|
|
+// TotalAdEposedCount: form.TotalAdEposedCount,
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
|
+//
|
|
|
|
+// filter := bson.M{"_id": behavior.Id}
|
|
|
|
+// result := make(map[string]interface{})
|
|
|
|
+// err := collection.FindOne(context.Background(), filter).Decode(&result)
|
|
|
|
+//
|
|
|
|
+// if len(result) == 0 {
|
|
|
|
+// //新增
|
|
|
|
+// _, err = collection.InsertOne(context.Background(), behavior)
|
|
|
|
+// if err != nil {
|
|
|
|
+// response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// } else {
|
|
|
|
+// var newAdData AdData
|
|
|
|
+// adData, _ := json.Marshal(form.AdData)
|
|
|
|
+// json.Unmarshal(adData, &newAdData)
|
|
|
|
+//
|
|
|
|
+// var oldAdData AdData
|
|
|
|
+// oldAdDatas, _ := json.Marshal(result["adData"])
|
|
|
|
+// json.Unmarshal(oldAdDatas, &oldAdData)
|
|
|
|
+//
|
|
|
|
+// newAdData.Reported = oldAdData.Reported
|
|
|
|
+//
|
|
|
|
+// //更新到MongoDB 中
|
|
|
|
+// update := bson.M{
|
|
|
|
+// "$set": struct {
|
|
|
|
+// Gid string `bson:"gid" json:"gid"`
|
|
|
|
+// Pf string `bson:"pf" json:"pf"`
|
|
|
|
+// OpenId string `bson:"openId" json:"openId"`
|
|
|
|
+// AdData interface{} `bson:"adData" json:"adData"`
|
|
|
|
+// AdFromCount int `bson:"adFromCount" json:"adFromCount"`
|
|
|
|
+// TotalDuration int `bson:"totalDuration" json:"totalDuration"`
|
|
|
|
+// TotalAdReqCount int `bson:"totalAdReqCount" json:"totalAdReqCount"`
|
|
|
|
+// TotalAdEposedCount int `bson:"totalAdEposedCount" json:"totalAdEposedCount"`
|
|
|
|
+// }{
|
|
|
|
+// Gid: behavior.Gid,
|
|
|
|
+// Pf: behavior.Pf,
|
|
|
|
+// OpenId: behavior.OpenId,
|
|
|
|
+// AdData: newAdData,
|
|
|
|
+// AdFromCount: behavior.AdFromCount,
|
|
|
|
+// TotalDuration: behavior.TotalDuration,
|
|
|
|
+// TotalAdReqCount: behavior.TotalAdReqCount,
|
|
|
|
+// TotalAdEposedCount: behavior.TotalAdEposedCount,
|
|
|
|
+// },
|
|
|
|
+// }
|
|
|
|
+// _, err = collection.UpdateOne(context.Background(), filter, update)
|
|
|
|
+// if err != nil {
|
|
|
|
+// response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
|
+// return
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// //如果是从广告获取进来的用户,则需要检测是否上传
|
|
|
|
+// if form.AdData != nil {
|
|
|
|
+// res := service.OceanReportAction(behavior.Id)
|
|
|
|
+// if res.Code != 0 {
|
|
|
|
+// //上传出现了问题,或者并没有上传
|
|
|
|
+// global.App.Log.Error(res.Code, res.Message)
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// response.Success(c, gin.H{})
|
|
|
|
+//}
|
|
|
|
|
|
func CheckUserBehavior(c *gin.Context) {
|
|
func CheckUserBehavior(c *gin.Context) {
|
|
gid := c.GetString("gid")
|
|
gid := c.GetString("gid")
|
|
@@ -214,9 +192,9 @@ func UpdateUserBehavior(c *gin.Context) {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-func FindUserBehavior(id string) *UserBehavior {
|
|
|
|
|
|
+func FindUserBehavior(id string) *model.UserBehavior {
|
|
filter := bson.M{"_id": id}
|
|
filter := bson.M{"_id": id}
|
|
- var result UserBehavior
|
|
|
|
|
|
+ var result model.UserBehavior
|
|
collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
err := collection.FindOne(context.Background(), filter).Decode(&result)
|
|
err := collection.FindOne(context.Background(), filter).Decode(&result)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -227,53 +205,81 @@ func FindUserBehavior(id string) *UserBehavior {
|
|
}
|
|
}
|
|
|
|
|
|
// 新建UserBehavior
|
|
// 新建UserBehavior
|
|
-func CreateUserBehavior(gid string, pf string, openId string) error {
|
|
|
|
|
|
+func CreateUserBehavior(gid string, pf string, openId string, now time.Time) error {
|
|
id := gid + "|" + pf + "|" + openId
|
|
id := gid + "|" + pf + "|" + openId
|
|
|
|
|
|
Behavior := FindUserBehavior(id)
|
|
Behavior := FindUserBehavior(id)
|
|
if Behavior != nil {
|
|
if Behavior != nil {
|
|
- return errors.New("该用户数据已经存在")
|
|
|
|
- }
|
|
|
|
|
|
+ //更新start_num参数
|
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
|
+ filter := bson.M{"_id": id}
|
|
|
|
+ update := bson.M{"$inc": bson.M{"startNum": 1}}
|
|
|
|
|
|
- behavior := UserBehavior{
|
|
|
|
- Id: id,
|
|
|
|
- Gid: gid,
|
|
|
|
- Pf: pf,
|
|
|
|
- OpenId: openId,
|
|
|
|
- AdData: nil,
|
|
|
|
- AdFromCount: 0,
|
|
|
|
- TotalDuration: 0,
|
|
|
|
- TotalAdReqCount: 0,
|
|
|
|
- TotalAdEposedCount: 0,
|
|
|
|
- }
|
|
|
|
- //新增
|
|
|
|
- collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
|
- _, err := collection.InsertOne(context.Background(), behavior)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
|
|
+ _, err := collection.UpdateOne(context.Background(), filter, update)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //更新关联的广告数据
|
|
|
|
+ filter = bson.M{"userId": id}
|
|
|
|
+ collection = global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
|
+ update = bson.M{"$inc": bson.M{"startNum": 1}}
|
|
|
|
+ _, err = collection.UpdateMany(context.Background(), filter, update)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+ } else {
|
|
|
|
+ behavior := model.UserBehavior{
|
|
|
|
+ Id: id,
|
|
|
|
+ Gid: gid,
|
|
|
|
+ Pf: pf,
|
|
|
|
+ OpenId: openId,
|
|
|
|
+ TotalDuration: 0,
|
|
|
|
+ TotalAdReqCount: 0,
|
|
|
|
+ TotalAdEposedCount: 0,
|
|
|
|
+ RelatedAid: 0,
|
|
|
|
+ StartNum: 1,
|
|
|
|
+ CreateTime: int(now.Unix()),
|
|
|
|
+ CreateDate: now.Format("20060102"),
|
|
|
|
+ ActiveStatus: false,
|
|
|
|
+ ConversionStatus: false,
|
|
|
|
+ RemainData: nil,
|
|
|
|
+ }
|
|
|
|
+ //新增
|
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
|
+ _, err := collection.InsertOne(context.Background(), behavior)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //存储在线数据到redis中
|
|
|
|
+ global.App.Redis.Set(context.Background(), id+"|online", now.Unix(), time.Second*300)
|
|
|
|
+
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
// 更新UserBehavior 在线时间
|
|
// 更新UserBehavior 在线时间
|
|
func UpdateUserBehaviorDuration(gid string, pf string, openId string, now time.Time, types int) error {
|
|
func UpdateUserBehaviorDuration(gid string, pf string, openId string, now time.Time, types int) error {
|
|
id := gid + "|" + pf + "|" + openId
|
|
id := gid + "|" + pf + "|" + openId
|
|
|
|
+
|
|
|
|
+ fmt.Println(now.Format("2006-01-02 15:04:05"))
|
|
Behavior := FindUserBehavior(id)
|
|
Behavior := FindUserBehavior(id)
|
|
if Behavior == nil {
|
|
if Behavior == nil {
|
|
return errors.New("该用户数据未保存,无法计算在线时间")
|
|
return errors.New("该用户数据未保存,无法计算在线时间")
|
|
}
|
|
}
|
|
|
|
|
|
- lastTime, err := global.App.Redis.Get(context.Background(), id+"|online").Result()
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
|
|
+ lastTime, _ := global.App.Redis.Get(context.Background(), id+"|online").Result()
|
|
|
|
|
|
//当状态为在线时,刷新redis数据,状态为2是离线,不刷新
|
|
//当状态为在线时,刷新redis数据,状态为2是离线,不刷新
|
|
if types == 1 {
|
|
if types == 1 {
|
|
- global.App.Redis.Set(context.Background(), id+"|online", now.Unix(), 300)
|
|
|
|
|
|
+ global.App.Redis.Set(context.Background(), id+"|online", now.Unix(), time.Second*300)
|
|
} else {
|
|
} else {
|
|
global.App.Redis.Del(context.Background(), id+"|online")
|
|
global.App.Redis.Del(context.Background(), id+"|online")
|
|
}
|
|
}
|
|
|
|
+ //fmt.Println("types", types)
|
|
|
|
|
|
//如果redis中没有查到在线状态,那就视为刚刚登录,不增加时间
|
|
//如果redis中没有查到在线状态,那就视为刚刚登录,不增加时间
|
|
if lastTime == "" {
|
|
if lastTime == "" {
|
|
@@ -284,30 +290,28 @@ func UpdateUserBehaviorDuration(gid string, pf string, openId string, now time.T
|
|
lastTimeUnix, _ := strconv.ParseInt(lastTime, 10, 64)
|
|
lastTimeUnix, _ := strconv.ParseInt(lastTime, 10, 64)
|
|
duration := now.Unix() - lastTimeUnix
|
|
duration := now.Unix() - lastTimeUnix
|
|
|
|
|
|
- var adData interface{}
|
|
|
|
- if Behavior.AdData != nil {
|
|
|
|
- //存在adData
|
|
|
|
- var newAdData AdData
|
|
|
|
- oldAdDatas, _ := json.Marshal(Behavior.AdData)
|
|
|
|
- json.Unmarshal(oldAdDatas, &newAdData)
|
|
|
|
-
|
|
|
|
- newAdData.Duration = newAdData.Duration + duration
|
|
|
|
- adData = newAdData
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//更新到MongoDB 中
|
|
//更新到MongoDB 中
|
|
update := bson.M{
|
|
update := bson.M{
|
|
"$set": struct {
|
|
"$set": struct {
|
|
- AdData interface{} `bson:"adData" json:"adData"`
|
|
|
|
- TotalDuration int `bson:"duration" json:"duration"`
|
|
|
|
|
|
+ TotalDuration int `bson:"totalDuration" json:"totalDuration"`
|
|
}{
|
|
}{
|
|
- AdData: adData,
|
|
|
|
TotalDuration: Behavior.TotalDuration + int(duration),
|
|
TotalDuration: Behavior.TotalDuration + int(duration),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
filter := bson.M{"_id": id}
|
|
filter := bson.M{"_id": id}
|
|
collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
- _, err = collection.UpdateOne(context.Background(), filter, update)
|
|
|
|
|
|
+ _, err := collection.UpdateOne(context.Background(), filter, update)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //更新到当日数据中 todo
|
|
|
|
+
|
|
|
|
+ //更新到广告关联数据中
|
|
|
|
+ filter = bson.M{"userId": id}
|
|
|
|
+ collection = global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
|
+ update = bson.M{"$inc": bson.M{"duration": int(duration)}}
|
|
|
|
+ _, err = collection.UpdateMany(context.Background(), filter, update)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -324,51 +328,28 @@ func UpdateUserBehaviorAdInfo(gid string, pf string, openId string, adsState int
|
|
|
|
|
|
Behavior := FindUserBehavior(id)
|
|
Behavior := FindUserBehavior(id)
|
|
if Behavior == nil {
|
|
if Behavior == nil {
|
|
- return errors.New("该用户数据未保存,无法计算在线时间")
|
|
|
|
- }
|
|
|
|
- var adData interface{}
|
|
|
|
- if Behavior.AdData != nil {
|
|
|
|
- //存在adData
|
|
|
|
- var newAdData AdData
|
|
|
|
- oldAdDatas, _ := json.Marshal(Behavior.AdData)
|
|
|
|
- json.Unmarshal(oldAdDatas, &newAdData)
|
|
|
|
-
|
|
|
|
- newAdData.AdReqCount++
|
|
|
|
- if adsState == 2 {
|
|
|
|
- newAdData.AdEposedcount++
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- adData = newAdData
|
|
|
|
|
|
+ return errors.New("该用户数据未保存,无法累加看广告数据")
|
|
}
|
|
}
|
|
|
|
|
|
var AdReqCount int
|
|
var AdReqCount int
|
|
var AdEposedcount int
|
|
var AdEposedcount int
|
|
- var AdFormCount int
|
|
|
|
if adsState == 0 {
|
|
if adsState == 0 {
|
|
//展示不成功
|
|
//展示不成功
|
|
- AdReqCount = 1
|
|
|
|
- AdFormCount = 1
|
|
|
|
} else if adsState == 1 {
|
|
} else if adsState == 1 {
|
|
//展示成功
|
|
//展示成功
|
|
AdReqCount = 1
|
|
AdReqCount = 1
|
|
- AdFormCount = 1
|
|
|
|
} else if adsState == 2 {
|
|
} else if adsState == 2 {
|
|
//展示成功并且看完
|
|
//展示成功并且看完
|
|
AdReqCount = 1
|
|
AdReqCount = 1
|
|
- AdFormCount = 1
|
|
|
|
AdEposedcount = 1
|
|
AdEposedcount = 1
|
|
}
|
|
}
|
|
|
|
|
|
- //更新到MongoDB 中
|
|
|
|
|
|
+ //更新到总数据中
|
|
update := bson.M{
|
|
update := bson.M{
|
|
"$set": struct {
|
|
"$set": struct {
|
|
- AdData interface{} `bson:"adData" json:"adData"`
|
|
|
|
- AdFromCount int `bson:"adFromCount" json:"adFromCount"`
|
|
|
|
- TotalAdReqCount int `bson:"totalAdReqCount" json:"totalAdReqCount"`
|
|
|
|
- TotalAdEposedCount int `bson:"totalAdEposedCount" json:"totalAdEposedCount"`
|
|
|
|
|
|
+ TotalAdReqCount int `bson:"totalAdReqCount" json:"totalAdReqCount"`
|
|
|
|
+ TotalAdEposedCount int `bson:"totalAdEposedCount" json:"totalAdEposedCount"`
|
|
}{
|
|
}{
|
|
- AdData: adData,
|
|
|
|
- AdFromCount: Behavior.AdFromCount + AdFormCount,
|
|
|
|
TotalAdReqCount: Behavior.TotalAdReqCount + AdReqCount,
|
|
TotalAdReqCount: Behavior.TotalAdReqCount + AdReqCount,
|
|
TotalAdEposedCount: Behavior.TotalAdEposedCount + AdEposedcount,
|
|
TotalAdEposedCount: Behavior.TotalAdEposedCount + AdEposedcount,
|
|
},
|
|
},
|
|
@@ -378,5 +359,38 @@ func UpdateUserBehaviorAdInfo(gid string, pf string, openId string, adsState int
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //更新到当日数据中 todo
|
|
|
|
+
|
|
|
|
+ //更新到广告关联数据中
|
|
|
|
+ filter = bson.M{"userId": id}
|
|
|
|
+ collection = global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
|
+ update = bson.M{"$inc": bson.M{"req_count": AdReqCount, "exp_count": AdEposedcount}}
|
|
|
|
+ _, err = collection.UpdateMany(context.Background(), filter, update)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 上报给巨量对接系统
|
|
|
|
+func CheckUserActive(gid string, pf string, openId string) {
|
|
|
|
+ request := map[string]interface{}{
|
|
|
|
+ "gid": gid,
|
|
|
|
+ "platform": pf,
|
|
|
|
+ "openId": openId,
|
|
|
|
+ }
|
|
|
|
+ data, err := service.CurlPost(config.Get("app.check_user_active"), request, nil)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.App.Log.Error("CheckUserActive err: ", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ res := make(map[string]interface{})
|
|
|
|
+ err = json.Unmarshal([]byte(data), &res)
|
|
|
|
+ if err != nil {
|
|
|
|
+ global.App.Log.Error("解析返回json错误: ", err)
|
|
|
|
+ }
|
|
|
|
+ fmt.Println(res)
|
|
|
|
+}
|