|
@@ -813,11 +813,11 @@ func BehaviorList(c *gin.Context) {
|
|
|
|
|
|
|
|
func AdRelatedList(c *gin.Context) {
|
|
func AdRelatedList(c *gin.Context) {
|
|
|
form := request.Check(c, &struct {
|
|
form := request.Check(c, &struct {
|
|
|
- //Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
|
|
- //Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
|
|
- //OpenId string `form:"search" json:"search" binding:""`
|
|
|
|
|
- Offset int `form:"offset" json:"offset" binding:""`
|
|
|
|
|
- Limit int `form:"limit" json:"limit" binding:""`
|
|
|
|
|
|
|
+ Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
|
|
+ Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
|
|
+ OpenId string `form:"search" json:"search" binding:""`
|
|
|
|
|
+ Offset int `form:"offset" json:"offset" binding:""`
|
|
|
|
|
+ Limit int `form:"limit" json:"limit" binding:""`
|
|
|
|
|
|
|
|
Pid string `form:"pid" json:"pid" binding:""`
|
|
Pid string `form:"pid" json:"pid" binding:""`
|
|
|
Aid string `form:"aid" json:"aid" binding:""`
|
|
Aid string `form:"aid" json:"aid" binding:""`
|
|
@@ -825,217 +825,95 @@ func AdRelatedList(c *gin.Context) {
|
|
|
|
|
|
|
|
CreateTime interface{} `form:"createTime" json:"createTime" binding:""`
|
|
CreateTime interface{} `form:"createTime" json:"createTime" binding:""`
|
|
|
StartNum interface{} `form:"startNum" json:"startNum" binding:""`
|
|
StartNum interface{} `form:"startNum" json:"startNum" binding:""`
|
|
|
- Revenue interface{} `form:"revenue" json:"revenue" binding:""`
|
|
|
|
|
Duration interface{} `form:"duration" json:"duration" binding:""`
|
|
Duration interface{} `form:"duration" json:"duration" binding:""`
|
|
|
ReqCount interface{} `form:"reqCount" json:"reqCount" binding:""`
|
|
ReqCount interface{} `form:"reqCount" json:"reqCount" binding:""`
|
|
|
ExpCount interface{} `form:"expCount" json:"expCount" binding:""`
|
|
ExpCount interface{} `form:"expCount" json:"expCount" binding:""`
|
|
|
}{})
|
|
}{})
|
|
|
|
|
|
|
|
- collection := global.App.MongoDB.Database("chunhao").Collection("adRelated")
|
|
|
|
|
|
|
+ query := global.App.DB.Table("user").
|
|
|
|
|
+ LeftJoin("user_behavior", "user.id = user_behavior.id").
|
|
|
|
|
+ Where("gid", form.Gid).Where("pf", form.Pf)
|
|
|
|
|
|
|
|
- ctx := context.Background()
|
|
|
|
|
- filter := bson.M{}
|
|
|
|
|
- if form.Pid != "" {
|
|
|
|
|
- filter["pid"] = form.Pid
|
|
|
|
|
- }
|
|
|
|
|
- if form.Aid != "" {
|
|
|
|
|
- filter["aid"] = form.Aid
|
|
|
|
|
|
|
+ if form.OpenId != "" {
|
|
|
|
|
+ query = query.Where("open_id", form.OpenId)
|
|
|
}
|
|
}
|
|
|
- if form.Cid != "" {
|
|
|
|
|
- filter["cid"] = form.Cid
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if form.Pid != "" {
|
|
|
|
|
+ query = query.Where("pid", form.Pid)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if form.CreateTime != nil {
|
|
if form.CreateTime != nil {
|
|
|
- marsh, _ := json.Marshal(form.CreateTime)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["createTime"] = filters
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "createdAt")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if form.StartNum != nil {
|
|
if form.StartNum != nil {
|
|
|
- marsh, _ := json.Marshal(form.StartNum)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["startNum"] = filters
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if form.Revenue != nil {
|
|
|
|
|
- marsh, _ := json.Marshal(form.Revenue)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["revenue"] = filters
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "startNum")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if form.Duration != nil {
|
|
if form.Duration != nil {
|
|
|
- marsh, _ := json.Marshal(form.Duration)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["duration"] = filters
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "duration")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if form.ReqCount != nil {
|
|
if form.ReqCount != nil {
|
|
|
- marsh, _ := json.Marshal(form.ReqCount)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["reqCount"] = filters
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "adCount")
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
if form.ExpCount != nil {
|
|
if form.ExpCount != nil {
|
|
|
- marsh, _ := json.Marshal(form.ExpCount)
|
|
|
|
|
- var totalAdEposedCount BehaviorFilter
|
|
|
|
|
- json.Unmarshal(marsh, &totalAdEposedCount)
|
|
|
|
|
-
|
|
|
|
|
- filters := bson.M{}
|
|
|
|
|
- if totalAdEposedCount.Gt != 0 {
|
|
|
|
|
- filters["$gt"] = totalAdEposedCount.Gt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Gte != 0 {
|
|
|
|
|
- filters["$gte"] = totalAdEposedCount.Gte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lte != 0 {
|
|
|
|
|
- filters["$lte"] = totalAdEposedCount.Lte
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Lt != 0 {
|
|
|
|
|
- filters["$lt"] = totalAdEposedCount.Lt
|
|
|
|
|
- }
|
|
|
|
|
- if totalAdEposedCount.Ne != 0 {
|
|
|
|
|
- filters["$ne"] = totalAdEposedCount.Ne
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if len(filters) > 0 {
|
|
|
|
|
- filter["expCount"] = filters
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "adExpCount")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- option := options.Find()
|
|
|
|
|
- option.SetLimit(int64(form.Limit))
|
|
|
|
|
- option.SetSkip(int64(form.Offset))
|
|
|
|
|
-
|
|
|
|
|
- cur, err := collection.Find(ctx, filter, option)
|
|
|
|
|
|
|
+ var count int64
|
|
|
|
|
+ err := query.Count(&count).Error
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
response.Fail(c, 1001, err.Error())
|
|
response.Fail(c, 1001, err.Error())
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- count, err := collection.CountDocuments(ctx, filter)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- response.Fail(c, 1001, err.Error())
|
|
|
|
|
- return
|
|
|
|
|
|
|
+ var res []struct {
|
|
|
|
|
+ ID int `json:"id" gorm:"not null;"`
|
|
|
|
|
+ Pf string `json:"pf" gorm:"not null;"`
|
|
|
|
|
+ Gid string `json:"gid" gorm:"not null;"`
|
|
|
|
|
+ UserId int `json:"userId" gorm:"not null;column:userId;"`
|
|
|
|
|
+ OpenId string `json:"openId" gorm:"not null;column:openId;"`
|
|
|
|
|
+ CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt;"`
|
|
|
|
|
+ Duration int `json:"duration" gorm:"not null;"`
|
|
|
|
|
+ StartNum int `json:"startNum" gorm:"not null;column:startNum;"`
|
|
|
|
|
+ AdCount int `json:"adCount" gorm:"not null;column:adCount;"`
|
|
|
|
|
+ AdExpCount int `json:"adExpCount" gorm:"not null;column:adExpCount;"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var data []AdRelated
|
|
|
|
|
- err = cur.All(ctx, &data)
|
|
|
|
|
|
|
+ err = query.Offset(form.Offset).Limit(form.Limit).Scan(&res).Error
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- response.Fail(c, 1001, err.Error())
|
|
|
|
|
|
|
+ response.Fail(c, 1002, err.Error())
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
response.Success(c, gin.H{
|
|
response.Success(c, gin.H{
|
|
|
- "data": data,
|
|
|
|
|
|
|
+ "data": res,
|
|
|
"count": count,
|
|
"count": count,
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func BuildBehaviorQuery(query *utils.WtDB, filters interface{}, field string) *utils.WtDB {
|
|
|
|
|
+ marsh, _ := json.Marshal(filters)
|
|
|
|
|
+ var filter BehaviorFilter
|
|
|
|
|
+ json.Unmarshal(marsh, &filter)
|
|
|
|
|
+
|
|
|
|
|
+ if filter.Gt > 0 {
|
|
|
|
|
+ query = query.Where(field, ">", filter.Gt)
|
|
|
|
|
+ }
|
|
|
|
|
+ if filter.Gte > 0 {
|
|
|
|
|
+ query = query.Where(field, ">=", filter.Gte)
|
|
|
|
|
+ }
|
|
|
|
|
+ if filter.Lt > 0 {
|
|
|
|
|
+ query = query.Where(field, "<", filter.Lt)
|
|
|
|
|
+ }
|
|
|
|
|
+ if filter.Lte > 0 {
|
|
|
|
|
+ query = query.Where(field, "<=", filter.Lte)
|
|
|
|
|
+ }
|
|
|
|
|
+ if filter.Ne > 0 {
|
|
|
|
|
+ query = query.Where(field, "!=", filter.Ne)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return query
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// ConversionCondition 转化条件
|
|
// ConversionCondition 转化条件
|
|
|
type ConversionCondition struct {
|
|
type ConversionCondition struct {
|
|
|
Id string `bson:"_id" json:"id"`
|
|
Id string `bson:"_id" json:"id"`
|