|
@@ -13,6 +13,7 @@ import (
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
|
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
|
|
"math"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
@@ -435,7 +436,6 @@ func DataTradesDetail(c *gin.Context) {
|
|
|
response.Fail(c, 1001, err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
for k := range AvgTime {
|
|
|
data[k] = dayData{
|
|
|
NewUser: NewUser[k],
|
|
@@ -769,3 +769,142 @@ func BehaviorList(c *gin.Context) {
|
|
|
"count": count,
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+// ConversionCondition 转化条件
|
|
|
+type ConversionCondition struct {
|
|
|
+ Id string `bson:"_id" json:"id"`
|
|
|
+ Gid string `bson:"gid" json:"gid"`
|
|
|
+ Pid int64 `bson:"pid" json:"pid"`
|
|
|
+ Aid int64 `bson:"aid" json:"aid"`
|
|
|
+ Type string `bson:"type" json:"type"`
|
|
|
+ StartNum int `bson:"start_num" json:"start_num"` //启动次数
|
|
|
+ EstimatedRevenue float32 `bson:"revenue" json:"revenue"` //当日预估收益
|
|
|
+ Duration int64 `bson:"duration" json:"duration"` //当日在线时长
|
|
|
+ ReqRewardedAd int `bson:"req_count" json:"req_count"` //当日的激励视频广告请求次数
|
|
|
+ ExpRewardedAd int `bson:"exp_count" json:"exp_count"` //当日的激励视频广告曝光次数
|
|
|
+}
|
|
|
+
|
|
|
+func SetGameCondition(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
+ Pid int64 `form:"pid" json:"pid" binding:""`
|
|
|
+ Aid int64 `form:"aid" json:"aid" binding:"required"`
|
|
|
+ Type string `form:"type" json:"type" binding:"required"`
|
|
|
+ StartNum int `form:"start_num" json:"start_num" binding:""`
|
|
|
+ EstimatedRevenue float32 `form:"revenue" json:"revenue" binding:""`
|
|
|
+ Duration int64 `form:"duration" json:"duration" binding:""`
|
|
|
+ ReqRewardedAd int `form:"req_count" json:"req_count" binding:""`
|
|
|
+ ExpRewardedAd int `form:"exp_count" json:"exp_count" binding:""`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ id := fmt.Sprintf("%s|%s|%s|%s", form.Gid, strconv.Itoa(int(form.Pid)), strconv.Itoa(int(form.Aid)), form.Type)
|
|
|
+
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("conversionCondition")
|
|
|
+ filter := bson.M{"_id": id}
|
|
|
+
|
|
|
+ var conversionCondition ConversionCondition
|
|
|
+ err := collection.FindOne(context.TODO(), filter).Decode(&conversionCondition)
|
|
|
+ //if err != nil {
|
|
|
+ // response.Fail(c, 1002, err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ if conversionCondition.Id != "" {
|
|
|
+ //存在,更新
|
|
|
+ update := bson.M{
|
|
|
+ "$set": struct {
|
|
|
+ StartNum int `bson:"start_num"` //启动次数
|
|
|
+ EstimatedRevenue float32 `bson:"revenue"` //当日预估收益
|
|
|
+ Duration int64 `bson:"duration"` //当日在线时长
|
|
|
+ ReqRewardedAd int `bson:"req_count"` //当日的激励视频广告请求次数
|
|
|
+ ExpRewardedAd int `bson:"exp_count"` //当日的激励视频广告曝光次数
|
|
|
+ }{
|
|
|
+ StartNum: form.StartNum,
|
|
|
+ EstimatedRevenue: form.EstimatedRevenue,
|
|
|
+ Duration: form.Duration,
|
|
|
+ ReqRewardedAd: form.ReqRewardedAd,
|
|
|
+ ExpRewardedAd: form.ExpRewardedAd,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ _, err = collection.UpdateOne(context.TODO(), filter, update)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1003, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //不存在,新增
|
|
|
+ insert := ConversionCondition{
|
|
|
+ Id: id,
|
|
|
+ Pid: form.Pid,
|
|
|
+ Aid: form.Aid,
|
|
|
+ Gid: form.Gid,
|
|
|
+ Type: form.Type,
|
|
|
+ StartNum: form.StartNum,
|
|
|
+ EstimatedRevenue: form.EstimatedRevenue,
|
|
|
+ Duration: form.Duration,
|
|
|
+ ReqRewardedAd: form.ReqRewardedAd,
|
|
|
+ ExpRewardedAd: form.ExpRewardedAd,
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = collection.InsertOne(context.TODO(), insert)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{})
|
|
|
+}
|
|
|
+
|
|
|
+func GameConditionList(c *gin.Context) {
|
|
|
+ form := request.Check(c, &struct {
|
|
|
+ Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
+ Pid int64 `form:"pid" json:"pid" binding:""`
|
|
|
+ Aid int64 `form:"aid" json:"aid" binding:""`
|
|
|
+ Type string `form:"type" json:"type" binding:""`
|
|
|
+ Offset int `form:"offset" json:"offset" binding:""`
|
|
|
+ Limit int `form:"limit" json:"limit" binding:"required"`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("conversionCondition")
|
|
|
+
|
|
|
+ filter := bson.M{"gid": form.Gid, "type": form.Type}
|
|
|
+ if form.Type != "" {
|
|
|
+ filter["type"] = form.Type
|
|
|
+ }
|
|
|
+ if form.Pid != 0 {
|
|
|
+ filter["pid"] = form.Pid
|
|
|
+ }
|
|
|
+ if form.Aid != 0 {
|
|
|
+ filter["aid"] = form.Aid
|
|
|
+ }
|
|
|
+
|
|
|
+ ctx := context.Background()
|
|
|
+ option := options.Find()
|
|
|
+ option.SetLimit(int64(form.Limit))
|
|
|
+ option.SetSkip(int64(form.Offset))
|
|
|
+
|
|
|
+ cur, err := collection.Find(ctx, filter, option)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ count, err := collection.CountDocuments(ctx, filter)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var data []ConversionCondition
|
|
|
+ err = cur.All(ctx, &data)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": data,
|
|
|
+ "count": count,
|
|
|
+ })
|
|
|
+}
|