|
|
@@ -5,32 +5,34 @@ import (
|
|
|
"designs/app/common/request"
|
|
|
"designs/app/common/response"
|
|
|
"designs/global"
|
|
|
+ "designs/service"
|
|
|
+ "encoding/json"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
|
)
|
|
|
|
|
|
type AdData struct {
|
|
|
- Pid string `json:"pid"`
|
|
|
- Aid string `json:"aid"`
|
|
|
- Cid string `json:"cid"`
|
|
|
- ReportUrl string `json:"reportUrl"`
|
|
|
- Reported bool `json:"reported"`
|
|
|
- Duration int64 `json:"duration"`
|
|
|
- AdReqCount uint8 `json:"adReqCount"`
|
|
|
- AdEposedcount uint8 `json:"adEposedcount"`
|
|
|
- CreateTime int `json:"createTime"`
|
|
|
+ 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"`
|
|
|
- Pf string `bson:"pf"`
|
|
|
- OpenId string `bson:"openId"`
|
|
|
- AdData interface{} `bson:"adData"`
|
|
|
- AdFromCount int `bson:"adFromCount"`
|
|
|
- TotalDuration int `bson:"totalDuration"`
|
|
|
- TotalAdReqCount int `bson:"totalAdReqCount"`
|
|
|
- TotalAdEposedCount int `bson:"totalAdEposedCount"`
|
|
|
+ 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) {
|
|
|
@@ -45,6 +47,9 @@ func ReceiveUserBehavior(c *gin.Context) {
|
|
|
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,
|
|
|
@@ -56,8 +61,9 @@ func ReceiveUserBehavior(c *gin.Context) {
|
|
|
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)
|
|
|
@@ -70,22 +76,32 @@ func ReceiveUserBehavior(c *gin.Context) {
|
|
|
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"`
|
|
|
- Pf string `bson:"pf"`
|
|
|
- OpenId string `bson:"openId"`
|
|
|
- AdData interface{} `bson:"adData"`
|
|
|
- AdFromCount int `bson:"adFromCount"`
|
|
|
- TotalDuration int `bson:"totalDuration"`
|
|
|
- TotalAdReqCount int `bson:"totalAdReqCount"`
|
|
|
- TotalAdEposedCount int `bson:"totalAdEposedCount"`
|
|
|
+ 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: behavior.AdData,
|
|
|
+ AdData: newAdData,
|
|
|
AdFromCount: behavior.AdFromCount,
|
|
|
TotalDuration: behavior.TotalDuration,
|
|
|
TotalAdReqCount: behavior.TotalAdReqCount,
|
|
|
@@ -99,6 +115,15 @@ func ReceiveUserBehavior(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //如果是从广告获取进来的用户,则需要检测是否上传
|
|
|
+ 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{})
|
|
|
}
|
|
|
|
|
|
@@ -123,3 +148,65 @@ func CheckUserBehavior(c *gin.Context) {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func UpdateUserBehavior(c *gin.Context) {
|
|
|
+ //查出所有需要更新的数据
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+
|
|
|
+ filters["adData"] = bson.M{"$exists": true}
|
|
|
+ var result []map[string]interface{}
|
|
|
+ cur, err := collection.Find(context.Background(), filters)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ err = cur.All(context.Background(), &result)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range result {
|
|
|
+ var adData map[string]interface{}
|
|
|
+ oldAdDatas, _ := json.Marshal(v["adData"])
|
|
|
+ json.Unmarshal(oldAdDatas, &adData)
|
|
|
+ if adData["createtime"] != nil {
|
|
|
+ //错误数据,需要修正
|
|
|
+ filter := bson.M{"_id": v["_id"]}
|
|
|
+
|
|
|
+ //
|
|
|
+ adData["createTime"] = adData["createtime"]
|
|
|
+ adData["adReqCount"] = adData["adreqcount"]
|
|
|
+ adData["adEposedcount"] = adData["adeposedcount"]
|
|
|
+ adData["reportUrl"] = adData["reporturl"]
|
|
|
+
|
|
|
+ delete(adData, "createtime")
|
|
|
+ delete(adData, "adreqcount")
|
|
|
+ delete(adData, "adeposedcount")
|
|
|
+ delete(adData, "reporturl")
|
|
|
+
|
|
|
+ //更新到MongoDB 中
|
|
|
+ update := bson.M{
|
|
|
+ "$set": struct {
|
|
|
+ AdData map[string]interface{} `bson:"adData" json:"adData"`
|
|
|
+ }{
|
|
|
+ AdData: adData,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _, err = collection.UpdateOne(context.Background(), filter, update)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1003, "写入数据失败"+err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ defer cur.Close(context.Background())
|
|
|
+
|
|
|
+ //更新成正确的数据
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": result,
|
|
|
+ })
|
|
|
+}
|