92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package statuser
|
|
|
|
import (
|
|
"time"
|
|
|
|
"91porn-server/common/timeutil/timerange"
|
|
"91porn-server/models/l/payvidlgmod"
|
|
"91porn-server/models/s/statusermod"
|
|
"91porn-server/models/v/vidmod"
|
|
)
|
|
|
|
type TimeRange = timerange.TimeRange
|
|
|
|
type IncDoc = statusermod.IncDoc
|
|
|
|
type SetDoc = statusermod.SetDoc
|
|
|
|
type Itemtype = statusermod.Itemtype
|
|
|
|
const (
|
|
SetType string = "set"
|
|
IncType string = "inc"
|
|
)
|
|
|
|
type Method struct {
|
|
MethodType string
|
|
GetIncDocListMethod func(timeRange TimeRange) ([]IncDoc, error)
|
|
GetSetDocListMethod func(timeRange TimeRange) ([]SetDoc, error)
|
|
IncCommitMethod func(incDocList []IncDoc, name string, recordAt time.Time) error
|
|
SetCommitMethod func(setDocList []SetDoc, name string, recordAt time.Time) error
|
|
}
|
|
|
|
var methodMap = map[Itemtype]Method{
|
|
//视频收益
|
|
statusermod.VidIncome: {MethodType: IncType, GetIncDocListMethod: getIncomneDocList, IncCommitMethod: commitIncDoc},
|
|
//上传数量
|
|
statusermod.UploadCount: {MethodType: SetType, GetSetDocListMethod: getUploadCountDocList, SetCommitMethod: commitSetDoc},
|
|
}
|
|
|
|
func getIncomneDocList(timeRange TimeRange) ([]IncDoc, error) {
|
|
m, err := payvidlgmod.PublisherIncomeMapByTime(timeRange.Head, timeRange.Tail)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]IncDoc, len(m))
|
|
i := 0
|
|
for uid, income := range m {
|
|
list[i] = IncDoc{
|
|
UID: uid,
|
|
Item: statusermod.VidIncome,
|
|
Count: income,
|
|
RecordAt: timeRange.Tail,
|
|
}
|
|
i++
|
|
}
|
|
return list, nil
|
|
}
|
|
|
|
func getUploadCountDocList(timeRange TimeRange) ([]SetDoc, error) {
|
|
mats := []vidmod.Matcher{
|
|
(&vidmod.StatusMatch{Status: vidmod.CheckPass}).New(),
|
|
(&vidmod.ReviewAtGTEAndLTMatch{GTE: &timeRange.Head, LT: &timeRange.Tail}).New(),
|
|
}
|
|
publisherIDs, err := vidmod.PublisherIDList(mats...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(publisherIDs) == 0 {
|
|
return nil, nil
|
|
}
|
|
mats = []vidmod.Matcher{
|
|
(&vidmod.StatusMatch{Status: vidmod.CheckPass}).New(),
|
|
(&vidmod.PublisherIDInMatch{PublisherIDList: publisherIDs}).New(),
|
|
}
|
|
m, err := vidmod.CountMapByPublisherID(mats...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
list := make([]SetDoc, len(m))
|
|
i := 0
|
|
for uid, uploadCount := range m {
|
|
list[i] = SetDoc{
|
|
UID: uid,
|
|
Item: statusermod.UploadCount,
|
|
Count: uploadCount,
|
|
RecordAt: timeRange.Tail,
|
|
}
|
|
i++
|
|
}
|
|
return list, nil
|
|
}
|