@@ -0,0 +1,63 @@
|
||||
package useradverstatmod
|
||||
|
||||
import (
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models/commod"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type DailyRetentionSummary struct {
|
||||
ID DailyRetentionSummaryID `bson:"_id"`
|
||||
Retained int64 `bson:"retained"`
|
||||
AdClick int64 `bson:"adClick"`
|
||||
TotalClick int64 `bson:"totalClick"`
|
||||
PayCount int64 `bson:"payCount"`
|
||||
PayTotal int64 `bson:"payTotal"`
|
||||
}
|
||||
|
||||
type DailyRetentionSummaryID struct {
|
||||
RegDay time.Time `bson:"regDay"`
|
||||
AdGroup commod.AdGroup `bson:"adGroup"`
|
||||
}
|
||||
|
||||
func AggregateDailyRetention(date, regDayStart, regDayEnd time.Time) (out []*DailyRetentionSummary, err error) {
|
||||
pipeline := []bson.M{
|
||||
{
|
||||
"$match": bson.M{
|
||||
"date": date,
|
||||
"regDay": bson.M{
|
||||
"$gte": regDayStart,
|
||||
"$lte": regDayEnd,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"$group": bson.M{
|
||||
"_id": bson.M{
|
||||
"regDay": "$regDay",
|
||||
"adGroup": "$adGroup",
|
||||
},
|
||||
"retained": bson.M{"$sum": 1},
|
||||
"adClick": bson.M{"$sum": "$adClick"},
|
||||
"totalClick": bson.M{"$sum": "$totalClick"},
|
||||
"payCount": bson.M{"$sum": "$payCount"},
|
||||
"payTotal": bson.M{"$sum": "$payTotal"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
opts := options.Aggregate().SetAllowDiskUse(true)
|
||||
if err = coll(nil).Aggregate(&out, pipeline, opts); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "AggregateDailyRetention", table, "Aggregate", err),
|
||||
log.Any("date", date),
|
||||
log.Any("regDayStart", regDayStart),
|
||||
log.Any("regDayEnd", regDayEnd),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user