|
|
@@ -818,7 +818,7 @@ func AdRelatedList(c *gin.Context) {
|
|
|
Where("gid", form.Gid).Where("pf", form.Pf)
|
|
|
|
|
|
if form.OpenId != "" {
|
|
|
- query = query.Where("open_id", form.OpenId)
|
|
|
+ query = query.Where("openId", form.OpenId)
|
|
|
}
|
|
|
|
|
|
if form.Pid != "" {
|
|
|
@@ -826,11 +826,12 @@ func AdRelatedList(c *gin.Context) {
|
|
|
}
|
|
|
|
|
|
if form.Aid != "" {
|
|
|
- query = query.Where("pid", form.Aid)
|
|
|
+ query = query.Where("aid", form.Aid)
|
|
|
}
|
|
|
|
|
|
if form.CreateTime != nil {
|
|
|
- query = BuildBehaviorQuery(query, form.CreateTime, "createdAt")
|
|
|
+ //时间戳转化为YMD
|
|
|
+ query = BuildBehaviorQuery(query, form.CreateTime, "UNIX_TIMESTAMP(createdAt)")
|
|
|
}
|
|
|
if form.StartNum != nil {
|
|
|
query = BuildBehaviorQuery(query, form.StartNum, "startNum")
|
|
|
@@ -1053,251 +1054,116 @@ func BehaviorListCake(c *gin.Context) {
|
|
|
Gid string `form:"gid" json:"gid" binding:"required"`
|
|
|
Pf string `form:"pf" json:"pf" binding:"required"`
|
|
|
|
|
|
- ActiveStatus string `form:"activeStatus" json:"activeStatus" binding:""` //all true false
|
|
|
- ConversionStatus string `form:"conversionStatus" json:"conversionStatus" binding:""` //all true false
|
|
|
TotalDuration string `form:"totalDuration" json:"totalDuration" binding:""`
|
|
|
TotalAdReqCount string `form:"totalAdReqCount" json:"totalAdReqCount" binding:""`
|
|
|
TotalAdEposedCount string `form:"totalAdEposedCount" json:"totalAdEposedCount" binding:""`
|
|
|
- CreateTime string `json:"createTime" bson:"createTime"`
|
|
|
-
|
|
|
- //AdFromCount string `form:"adFromCount" json:"adFromCount" binding:""`
|
|
|
- //StartNum string `form:"startNum" json:"startNum" binding:""`
|
|
|
+ CreateTime string `form:"createTime" json:"createTime"`
|
|
|
}{})
|
|
|
- collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
-
|
|
|
- ctx := context.Background()
|
|
|
- filter := bson.M{"gid": form.Gid}
|
|
|
|
|
|
- if form.Pf != "" {
|
|
|
- filter["pf"] = form.Pf
|
|
|
- }
|
|
|
+ //根据过滤条件分组统计
|
|
|
+ if form.TotalDuration != "" {
|
|
|
+ group := BehaviorCakeQuery(form.Gid, form.Pf, form.CreateTime, form.TotalDuration, "duration", "用户时长")
|
|
|
|
|
|
- if form.ActiveStatus == "true" {
|
|
|
- filter["activeStatus"] = true
|
|
|
- } else if form.ActiveStatus == "false" {
|
|
|
- filter["activeStatus"] = false
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": group,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
+ if form.TotalAdReqCount != "" {
|
|
|
+ group := BehaviorCakeQuery(form.Gid, form.Pf, form.CreateTime, form.TotalAdReqCount, "adCount", "广告次数")
|
|
|
|
|
|
- if form.ActiveStatus == "true" {
|
|
|
- filter["activeStatus"] = true
|
|
|
- } else if form.ActiveStatus == "false" {
|
|
|
- filter["activeStatus"] = false
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": group,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- if form.CreateTime != "" {
|
|
|
- createTime := strings.Split(strings.Replace(form.CreateTime, ",", ",", -1), ",")
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"], _ = strconv.Atoi(createTime[0])
|
|
|
- filters["$lte"], _ = strconv.Atoi(createTime[1])
|
|
|
- filter["createTime"] = filters
|
|
|
- }
|
|
|
+ if form.TotalAdEposedCount != "" {
|
|
|
+ group := BehaviorCakeQuery(form.Gid, form.Pf, form.CreateTime, form.TotalAdEposedCount, "adExpCount", "广告完播次数")
|
|
|
|
|
|
- type resData struct {
|
|
|
- Count int `json:"count"`
|
|
|
- Name string `json:"name"`
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": group,
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- filterListTotalDuration := make(map[string]bson.M)
|
|
|
+ response.Success(c, gin.H{})
|
|
|
+}
|
|
|
|
|
|
- filterList := make(map[string]bson.M)
|
|
|
+type cakeRes struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+ Count int64 `json:"count"`
|
|
|
+}
|
|
|
|
|
|
- var data []resData
|
|
|
- if form.TotalDuration != "" {
|
|
|
- totalDuration := strings.Split(strings.Replace(form.TotalDuration, ",", ",", -1), ",")
|
|
|
- for k, _ := range totalDuration {
|
|
|
- var gt, lte int
|
|
|
- if k == 0 {
|
|
|
- gt = 0
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- } else {
|
|
|
- gt, _ = strconv.Atoi(totalDuration[k-1])
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- }
|
|
|
+func BehaviorCakeQuery(gid, pf, createTime, filter, filterRow, filterName string) []cakeRes {
|
|
|
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"] = gt
|
|
|
- filters["$lte"] = lte
|
|
|
+ var group []cakeRes
|
|
|
|
|
|
- filter1 := utils.DeepCopyMap(filter)
|
|
|
+ totalDuration := CakeFilter(filter)
|
|
|
|
|
|
- filter1["totalDuration"] = filters
|
|
|
+ for k, v := range totalDuration {
|
|
|
+ var count int64
|
|
|
+ if k == 0 {
|
|
|
+ query := SetCakeQuery(gid, pf, createTime)
|
|
|
+ query.Where(filterRow, "<=", v).Count(&count)
|
|
|
|
|
|
- name := "在线时长:" + strconv.Itoa(gt) + "-" + strconv.Itoa(lte)
|
|
|
+ group = append(group, cakeRes{
|
|
|
+ Name: fmt.Sprintf("%s<=%v", filterName, v),
|
|
|
+ Count: count,
|
|
|
+ })
|
|
|
|
|
|
- filterListTotalDuration[name] = filter1
|
|
|
}
|
|
|
+ if k == len(totalDuration)-1 {
|
|
|
+ query := SetCakeQuery(gid, pf, createTime)
|
|
|
+ query.Where(filterRow, ">=", v).Count(&count)
|
|
|
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"], _ = strconv.Atoi(totalDuration[len(totalDuration)-1])
|
|
|
- filter["totalDuration"] = filters
|
|
|
-
|
|
|
- name := "在线时长:" + totalDuration[len(totalDuration)-1] + "-" + "∞"
|
|
|
-
|
|
|
- filterListTotalDuration[name] = filter
|
|
|
- }
|
|
|
-
|
|
|
- if form.TotalAdReqCount != "" && form.TotalAdEposedCount == "" {
|
|
|
- totalDuration := strings.Split(strings.Replace(form.TotalAdReqCount, ",", ",", -1), ",")
|
|
|
-
|
|
|
- for k, _ := range totalDuration {
|
|
|
- var gt, lte int
|
|
|
- if k == 0 {
|
|
|
- gt = 0
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- } else {
|
|
|
- gt, _ = strconv.Atoi(totalDuration[k-1])
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- }
|
|
|
-
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"] = gt
|
|
|
- filters["$lte"] = lte
|
|
|
-
|
|
|
- if len(filterListTotalDuration) != 0 {
|
|
|
- for nameD, filterD := range filterListTotalDuration {
|
|
|
- filterE := utils.DeepCopyMap(filterD)
|
|
|
-
|
|
|
- filterE["totalAdReqCount"] = filters
|
|
|
-
|
|
|
- name := nameD + "&&" + "广告观看次数:" + strconv.Itoa(gt) + "-" + strconv.Itoa(lte)
|
|
|
-
|
|
|
- filterList[name] = filterE
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- filter1 := utils.DeepCopyMap(filter)
|
|
|
-
|
|
|
- filter1["totalAdReqCount"] = filters
|
|
|
- name := "广告观看次数:" + strconv.Itoa(gt) + "-" + strconv.Itoa(lte)
|
|
|
-
|
|
|
- filterList[name] = filter1
|
|
|
- }
|
|
|
+ group = append(group, cakeRes{
|
|
|
+ Name: fmt.Sprintf("%s>=%v", filterName, v),
|
|
|
+ Count: count,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"], _ = strconv.Atoi(totalDuration[len(totalDuration)-1])
|
|
|
- filter["totalAdReqCount"] = filters
|
|
|
-
|
|
|
- if len(filterListTotalDuration) != 0 {
|
|
|
- for nameD, filterD := range filterListTotalDuration {
|
|
|
-
|
|
|
- filterD["totalAdReqCount"] = filters
|
|
|
-
|
|
|
- name := nameD + "&&" + "广告观看次数:" + totalDuration[len(totalDuration)-1] + "-" + "∞"
|
|
|
+ if k-1 >= 0 {
|
|
|
+ query := SetCakeQuery(gid, pf, createTime)
|
|
|
+ query.Where(filterRow, ">=", totalDuration[k-1]).Where(filterRow, "<", totalDuration[k]).Count(&count)
|
|
|
|
|
|
- filterList[name] = filterD
|
|
|
- }
|
|
|
- } else {
|
|
|
- filter1 := utils.DeepCopyMap(filter)
|
|
|
- filter["totalAdReqCount"] = filters
|
|
|
- name := "广告观看次数:" + totalDuration[len(totalDuration)-1] + "-" + "∞"
|
|
|
-
|
|
|
- filterList[name] = filter1
|
|
|
+ group = append(group, cakeRes{
|
|
|
+ Name: fmt.Sprintf("%s>=%v,且<%v", filterName, totalDuration[k-1], v),
|
|
|
+ Count: count,
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- //count, err := collection.CountDocuments(ctx, filter)
|
|
|
- //if err != nil {
|
|
|
- // response.Fail(c, 1001, err.Error())
|
|
|
- // return
|
|
|
- //}
|
|
|
- //data = append(data, resData{
|
|
|
- // Count: int(count),
|
|
|
- // Name: totalDuration[len(totalDuration)-1] + "-" + "∞",
|
|
|
- //})
|
|
|
}
|
|
|
|
|
|
- if form.TotalAdEposedCount != "" && form.TotalAdReqCount == "" {
|
|
|
- totalDuration := strings.Split(strings.Replace(form.TotalAdEposedCount, ",", ",", -1), ",")
|
|
|
-
|
|
|
- for k, _ := range totalDuration {
|
|
|
- var gt, lte int
|
|
|
- if k == 0 {
|
|
|
- gt = 0
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- } else {
|
|
|
- gt, _ = strconv.Atoi(totalDuration[k-1])
|
|
|
- lte, _ = strconv.Atoi(totalDuration[k])
|
|
|
- }
|
|
|
-
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"] = gt
|
|
|
- filters["$lte"] = lte
|
|
|
-
|
|
|
- if len(filterListTotalDuration) != 0 {
|
|
|
- for nameD, filterD := range filterListTotalDuration {
|
|
|
- filterE := utils.DeepCopyMap(filterD)
|
|
|
-
|
|
|
- filterE["TotalAdEposedCount"] = filters
|
|
|
-
|
|
|
- name := nameD + "&&" + "广告看完次数:" + strconv.Itoa(gt) + "-" + strconv.Itoa(lte)
|
|
|
-
|
|
|
- filterList[name] = filterE
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- filter1 := utils.DeepCopyMap(filter)
|
|
|
-
|
|
|
- filter1["TotalAdEposedCount"] = filters
|
|
|
- name := "广告看完次数:" + strconv.Itoa(gt) + "-" + strconv.Itoa(lte)
|
|
|
-
|
|
|
- filterList[name] = filter1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- filters := bson.M{}
|
|
|
- filters["$gt"], _ = strconv.Atoi(totalDuration[len(totalDuration)-1])
|
|
|
- filter["TotalAdEposedCount"] = filters
|
|
|
-
|
|
|
- if len(filterListTotalDuration) != 0 {
|
|
|
- for nameD, filterD := range filterListTotalDuration {
|
|
|
-
|
|
|
- filterD["TotalAdEposedCount"] = filters
|
|
|
-
|
|
|
- name := nameD + "&&" + "广告看完次数:" + totalDuration[len(totalDuration)-1] + "-" + "∞"
|
|
|
-
|
|
|
- filterList[name] = filterD
|
|
|
- }
|
|
|
- } else {
|
|
|
- filter1 := utils.DeepCopyMap(filter)
|
|
|
- filter["TotalAdEposedCount"] = filters
|
|
|
- name := "广告看完次数:" + totalDuration[len(totalDuration)-1] + "-" + "∞"
|
|
|
+ return group
|
|
|
+}
|
|
|
+func SetCakeQuery(Gid, Pf, CreateTime string) *utils.WtDB {
|
|
|
+ query := global.App.DB.Table("user").
|
|
|
+ LeftJoin("user_behavior", "user.id = user_behavior.id").Where("gid", Gid).Where("pf", Pf)
|
|
|
|
|
|
- filterList[name] = filter1
|
|
|
- }
|
|
|
+ if CreateTime != "" {
|
|
|
+ timeSlice := strings.Split(CreateTime, ",")
|
|
|
|
|
|
- //count, err := collection.CountDocuments(ctx, filter)
|
|
|
- //if err != nil {
|
|
|
- // response.Fail(c, 1001, err.Error())
|
|
|
- // return
|
|
|
- //}
|
|
|
- //data = append(data, resData{
|
|
|
- // Count: int(count),
|
|
|
- // Name: totalDuration[len(totalDuration)-1] + "-" + "∞",
|
|
|
- //})
|
|
|
- }
|
|
|
+ start, _ := strconv.Atoi(timeSlice[0])
|
|
|
+ end, _ := strconv.Atoi(timeSlice[1])
|
|
|
+ startTime := time.Unix(int64(start), 0)
|
|
|
+ endTime := time.Unix(int64(end), 0)
|
|
|
|
|
|
- if form.TotalAdEposedCount != "" && form.TotalAdReqCount != "" {
|
|
|
- response.Fail(c, 1002, "筛选条件无效")
|
|
|
- return
|
|
|
- }
|
|
|
+ query = query.WhereRaw("createdAt >= ?", startTime).WhereRaw("createdAt <= ?", endTime)
|
|
|
|
|
|
- if len(filterList) == 0 {
|
|
|
- filterList = filterListTotalDuration
|
|
|
}
|
|
|
|
|
|
- for k, filterC := range filterList {
|
|
|
- count, _ := collection.CountDocuments(ctx, filterC)
|
|
|
+ return query
|
|
|
+}
|
|
|
+func CakeFilter(filter string) []int {
|
|
|
+ totalDuration := strings.Split(strings.Replace(filter, ",", ",", -1), ",")
|
|
|
|
|
|
- data = append(data, resData{
|
|
|
- Name: k,
|
|
|
- Count: int(count),
|
|
|
- })
|
|
|
+ var result []int
|
|
|
+ for _, v := range totalDuration {
|
|
|
+ ints, _ := strconv.Atoi(v)
|
|
|
+ result = append(result, ints)
|
|
|
}
|
|
|
-
|
|
|
- response.Success(c, gin.H{
|
|
|
- "data": data,
|
|
|
- })
|
|
|
-
|
|
|
+ return result
|
|
|
}
|
|
|
|
|
|
func SplitOnlineData(c *gin.Context) {
|