|
@@ -1,12 +1,17 @@
|
|
|
package v1
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"designs/app/common/request"
|
|
|
"designs/app/common/response"
|
|
|
"designs/global"
|
|
|
"designs/service"
|
|
|
"designs/utils"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "go.mongodb.org/mongo-driver/v2/bson"
|
|
|
+ "go.mongodb.org/mongo-driver/v2/mongo/options"
|
|
|
"math"
|
|
|
"time"
|
|
|
)
|
|
@@ -128,7 +133,7 @@ func TimeDistributionData(c *gin.Context) {
|
|
|
}
|
|
|
} else if form.Type == 3 {
|
|
|
//启动次数
|
|
|
- todayTimeDistribution, yesterdayTimeDistribution, yesterdayCount, todayCount, yesterdayThisTimeCount, err := service.GetActiveTimeDistribution(form.Pf, form.Gid)
|
|
|
+ todayTimeDistribution, yesterdayTimeDistribution, yesterdayCount, todayCount, yesterdayThisTimeCount, err := service.GetActionDistribution(form.Pf, form.Gid)
|
|
|
if err != nil {
|
|
|
response.Fail(c, 1001, err.Error())
|
|
|
return
|
|
@@ -159,7 +164,7 @@ func MouthDistributionData(c *gin.Context) {
|
|
|
Type int `form:"type" json:"type" binding:"required"`
|
|
|
}{})
|
|
|
now := time.Now()
|
|
|
- EndTime := now.Format("2006-01-02")
|
|
|
+ EndTime := now.AddDate(0, 0, 1).Format("2006-01-02")
|
|
|
StartTime := now.AddDate(0, 0, -29).Format("2006-01-02")
|
|
|
|
|
|
data := make(map[string]interface{})
|
|
@@ -299,6 +304,9 @@ func DataTrades(c *gin.Context) {
|
|
|
Type int `form:"type" json:"type" binding:"required"`
|
|
|
}{})
|
|
|
data := make(map[string]interface{})
|
|
|
+
|
|
|
+ form.EndTime = form.EndTime + " 23:59:59"
|
|
|
+
|
|
|
if form.Type == 1 {
|
|
|
//查询新增设备趋势图
|
|
|
TimeDistribution, count, avg, err := service.GetRegisterDayDistribution(form.Pf, form.Gid, form.StartTime, form.EndTime)
|
|
@@ -379,7 +387,7 @@ func DataTradesDetail(c *gin.Context) {
|
|
|
StartTime string `form:"startTime" json:"startTime" binding:"required"`
|
|
|
EndTime string `form:"endTime" json:"endTime" binding:"required"`
|
|
|
}{})
|
|
|
-
|
|
|
+ form.EndTime = form.EndTime + " 23:59:59"
|
|
|
type dayData struct {
|
|
|
NewUser int `json:"newUser"`
|
|
|
ActiveUser int `json:"activeUser"`
|
|
@@ -389,6 +397,7 @@ func DataTradesDetail(c *gin.Context) {
|
|
|
AvgTime int `json:"avgTime"`
|
|
|
}
|
|
|
var data = make(map[string]dayData)
|
|
|
+
|
|
|
//查询新增设备趋势图
|
|
|
NewUser, _, _, err := service.GetRegisterDayDistribution(form.Pf, form.Gid, form.StartTime, form.EndTime)
|
|
|
if err != nil {
|
|
@@ -463,3 +472,300 @@ func RemainDataBydDay(c *gin.Context) {
|
|
|
"data": data,
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+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"`
|
|
|
+}
|
|
|
+
|
|
|
+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"`
|
|
|
+}
|
|
|
+
|
|
|
+type BehaviorFilter struct {
|
|
|
+ Gt int `json:"gt"`
|
|
|
+ Gte int `json:"gte"`
|
|
|
+ Lte int `json:"lte"`
|
|
|
+ Lt int `json:"lt"`
|
|
|
+ Ne int `json:"ne"`
|
|
|
+ //$gt 大于
|
|
|
+ //$gte:大于或等于
|
|
|
+ //$lt:小于
|
|
|
+ //$lte:小于或等于
|
|
|
+ //$ne:不等于
|
|
|
+}
|
|
|
+
|
|
|
+func BehaviorList(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:"search" json:"search" binding:""`
|
|
|
+ Offset int `form:"offset" json:"offset" binding:""`
|
|
|
+ Limit int `form:"limit" json:"limit" binding:""`
|
|
|
+
|
|
|
+ Reported string `form:"reported" json:"reported" binding:""` //all true false
|
|
|
+ Pid string `form:"pid" json:"pid" binding:""`
|
|
|
+ Aid string `form:"aid" json:"aid" binding:""`
|
|
|
+ Cid string `form:"cid" json:"cid" binding:""`
|
|
|
+
|
|
|
+ Duration interface{} `form:"duration" json:"duration" binding:""`
|
|
|
+ AdReqCount interface{} `form:"adReqCount" json:"adReqCount" binding:""`
|
|
|
+ AdEposedcount interface{} `form:"adEposedcount" json:"adEposedcount" binding:""`
|
|
|
+
|
|
|
+ AdFromCount interface{} `form:"adFromCount" json:"adFromCount" binding:""`
|
|
|
+ TotalDuration interface{} `form:"totalDuration" json:"totalDuration" binding:""`
|
|
|
+ TotalAdReqCount interface{} `form:"totalAdReqCount" json:"totalAdReqCount" binding:""`
|
|
|
+ TotalAdEposedCount interface{} `form:"totalAdEposedCount" json:"totalAdEposedCount" binding:""`
|
|
|
+ }{})
|
|
|
+
|
|
|
+ collection := global.App.MongoDB.Database("chunhao").Collection("userBehavior")
|
|
|
+
|
|
|
+ ctx := context.Background()
|
|
|
+ filter := bson.M{"gid": form.Gid, "pf": form.Pf}
|
|
|
+
|
|
|
+ if form.OpenId != "" {
|
|
|
+ filter["openId"] = bson.M{"$regex": form.OpenId}
|
|
|
+ }
|
|
|
+ if form.Pid != "" {
|
|
|
+ filter["adData.pid"] = form.Pid
|
|
|
+ }
|
|
|
+ if form.Aid != "" {
|
|
|
+ filter["adData.aid"] = form.Aid
|
|
|
+ }
|
|
|
+ if form.Cid != "" {
|
|
|
+ filter["adData.cid"] = form.Cid
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.AdFromCount != nil {
|
|
|
+ fmt.Println(form.AdFromCount)
|
|
|
+ marsh, _ := json.Marshal(form.AdFromCount)
|
|
|
+ var adFromCount BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &adFromCount)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if adFromCount.Gt != 0 {
|
|
|
+ filters["$gt"] = adFromCount.Gt
|
|
|
+ }
|
|
|
+ if adFromCount.Gte != 0 {
|
|
|
+ filters["$gte"] = adFromCount.Gte
|
|
|
+ }
|
|
|
+ if adFromCount.Lte != 0 {
|
|
|
+ filters["$lte"] = adFromCount.Lte
|
|
|
+ }
|
|
|
+ if adFromCount.Lt != 0 {
|
|
|
+ filters["$lt"] = adFromCount.Lt
|
|
|
+ }
|
|
|
+ if adFromCount.Lt != 0 {
|
|
|
+ filters["$ne"] = adFromCount.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["adFromCount"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.TotalDuration != nil {
|
|
|
+ marsh, _ := json.Marshal(form.TotalDuration)
|
|
|
+ var totalDuration BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &totalDuration)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if totalDuration.Gt != 0 {
|
|
|
+ filters["$gt"] = totalDuration.Gt
|
|
|
+ }
|
|
|
+ if totalDuration.Gte != 0 {
|
|
|
+ filters["$gte"] = totalDuration.Gte
|
|
|
+ }
|
|
|
+ if totalDuration.Lte != 0 {
|
|
|
+ filters["$lte"] = totalDuration.Lte
|
|
|
+ }
|
|
|
+ if totalDuration.Lt != 0 {
|
|
|
+ filters["$lt"] = totalDuration.Lt
|
|
|
+ }
|
|
|
+ if totalDuration.Lt != 0 {
|
|
|
+ filters["$ne"] = totalDuration.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["TotalDuration"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.TotalAdReqCount != nil {
|
|
|
+ marsh, _ := json.Marshal(form.TotalAdReqCount)
|
|
|
+ var totalAdReqCount BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &totalAdReqCount)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if totalAdReqCount.Gt != 0 {
|
|
|
+ filters["$gt"] = totalAdReqCount.Gt
|
|
|
+ }
|
|
|
+ if totalAdReqCount.Gte != 0 {
|
|
|
+ filters["$gte"] = totalAdReqCount.Gte
|
|
|
+ }
|
|
|
+ if totalAdReqCount.Lte != 0 {
|
|
|
+ filters["$lte"] = totalAdReqCount.Lte
|
|
|
+ }
|
|
|
+ if totalAdReqCount.Lt != 0 {
|
|
|
+ filters["$lt"] = totalAdReqCount.Lt
|
|
|
+ }
|
|
|
+ if totalAdReqCount.Lt != 0 {
|
|
|
+ filters["$ne"] = totalAdReqCount.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["totalAdReqCount"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.TotalAdEposedCount != nil {
|
|
|
+ marsh, _ := json.Marshal(form.TotalAdEposedCount)
|
|
|
+ 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.Lt != 0 {
|
|
|
+ filters["$ne"] = totalAdEposedCount.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["totalAdEposedCount"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.Duration != nil {
|
|
|
+ marsh, _ := json.Marshal(form.Duration)
|
|
|
+ var duration BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &duration)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if duration.Gt != 0 {
|
|
|
+ filters["$gt"] = duration.Gt
|
|
|
+ }
|
|
|
+ if duration.Gte != 0 {
|
|
|
+ filters["$gte"] = duration.Gte
|
|
|
+ }
|
|
|
+ if duration.Lte != 0 {
|
|
|
+ filters["$lte"] = duration.Lte
|
|
|
+ }
|
|
|
+ if duration.Lt != 0 {
|
|
|
+ filters["$lt"] = duration.Lt
|
|
|
+ }
|
|
|
+ if duration.Lt != 0 {
|
|
|
+ filters["$ne"] = duration.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["adData.duration"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.AdReqCount != nil {
|
|
|
+ marsh, _ := json.Marshal(form.AdReqCount)
|
|
|
+ var adReqCount BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &adReqCount)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if adReqCount.Gt != 0 {
|
|
|
+ filters["$gt"] = adReqCount.Gt
|
|
|
+ }
|
|
|
+ if adReqCount.Gte != 0 {
|
|
|
+ filters["$gte"] = adReqCount.Gte
|
|
|
+ }
|
|
|
+ if adReqCount.Lte != 0 {
|
|
|
+ filters["$lte"] = adReqCount.Lte
|
|
|
+ }
|
|
|
+ if adReqCount.Lt != 0 {
|
|
|
+ filters["$lt"] = adReqCount.Lt
|
|
|
+ }
|
|
|
+ if adReqCount.Lt != 0 {
|
|
|
+ filters["$ne"] = adReqCount.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["adData.adReqCount"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if form.AdEposedcount != nil {
|
|
|
+ marsh, _ := json.Marshal(form.AdEposedcount)
|
|
|
+ var adEposedcount BehaviorFilter
|
|
|
+ json.Unmarshal(marsh, &adEposedcount)
|
|
|
+
|
|
|
+ filters := bson.M{}
|
|
|
+ if adEposedcount.Gt != 0 {
|
|
|
+ filters["$gt"] = adEposedcount.Gt
|
|
|
+ }
|
|
|
+ if adEposedcount.Gte != 0 {
|
|
|
+ filters["$gte"] = adEposedcount.Gte
|
|
|
+ }
|
|
|
+ if adEposedcount.Lte != 0 {
|
|
|
+ filters["$lte"] = adEposedcount.Lte
|
|
|
+ }
|
|
|
+ if adEposedcount.Lt != 0 {
|
|
|
+ filters["$lt"] = adEposedcount.Lt
|
|
|
+ }
|
|
|
+ if adEposedcount.Lt != 0 {
|
|
|
+ filters["$ne"] = adEposedcount.Ne
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(filters) > 0 {
|
|
|
+ filter["adData.adEposedcount"] = filters
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 []UserBehavior
|
|
|
+ err = cur.All(ctx, &data)
|
|
|
+ if err != nil {
|
|
|
+ response.Fail(c, 1001, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "data": data,
|
|
|
+ "count": count,
|
|
|
+ })
|
|
|
+}
|