45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package statvidmod
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/common/pageopt"
|
|
)
|
|
|
|
type SumGroup struct {
|
|
Vid ObjectID `bson:"_id"`
|
|
Income int64 `bson:"income"` //收入
|
|
PayCount int64 `bson:"payCount"` //购买次数
|
|
PlayCount int64 `bson:"playCount"` //播放次数
|
|
PayPlayCount int64 `bson:"payPlayCount"` //付费播放次数
|
|
Tax float64 `bson:"tax"` //[未完成]税
|
|
}
|
|
|
|
// PlayCountGTMatch
|
|
type RecordAtGTEAndLTMatch struct {
|
|
GTE *time.Time
|
|
LT *time.Time
|
|
}
|
|
|
|
func (r *RecordAtGTEAndLTMatch) New() Matcher {
|
|
return pageopt.NewGTEAndLTMatch("recordAt", r.GTE, r.LT)
|
|
}
|
|
|
|
func Sum(matchs ...Matcher) ([]SumGroup, error) {
|
|
filter := pageopt.MergeM(matchs)
|
|
pipeline := []M{}
|
|
pipeline = append(pipeline, M{"$match": filter})
|
|
pipeline = append(pipeline, M{
|
|
"$group": M{
|
|
"_id": "$vid",
|
|
"income": M{"$sum": "$income"},
|
|
"payCount": M{"$sum": "$payCount"},
|
|
"playCount": M{"$sum": "$playCount"},
|
|
"payPlayCount": M{"$sum": "$payPlayCount"},
|
|
"tax": M{"$sum": "$tax"},
|
|
},
|
|
})
|
|
list := []SumGroup{}
|
|
return list, coll(nil).Aggregate(&list, pipeline)
|
|
}
|