@@ -0,0 +1,128 @@
|
||||
package statvidmod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/maths"
|
||||
"91porn-server/models/v/usermod"
|
||||
"91porn-server/models/v/vidmod"
|
||||
"91porn-server/web/vidhelp"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type Video struct {
|
||||
ID *primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title *string `json:"title" bson:"title,omitempty"` //视频标题
|
||||
PublisherID *uint64 `json:"publisherID" bson:"publisherID,omitempty"` //上传者ID
|
||||
PublisherName *string `json:"publisherName"` //上传者姓名
|
||||
Day *float64 `json:"day"` //售卖天数
|
||||
Coins *int64 `json:"coins" bson:"coins,omitempty"` //定价
|
||||
}
|
||||
|
||||
type VideoStatRecord struct {
|
||||
SumDate *time.Time `json:"sumDate" bson:"sumDate,omitempty"`
|
||||
Video Video `json:"video" bson:"video"` //视屏
|
||||
Income *int64 `json:"income" bson:"income,omitempty"` //当日收入
|
||||
Tax *float64 `json:"tax" bson:"tax,omitempty"` //税
|
||||
PayCount *int64 `json:"payCount" bson:"payCount,omitempty"` //购买数
|
||||
CreatedAt *time.Time `json:"createdAt" bson:"createdAt,omitempty"` //日志创建时间
|
||||
}
|
||||
|
||||
type VideoStatExport struct {
|
||||
SumDate time.Time `json:"sumDate" bson:"sumDate,omitempty"`
|
||||
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
|
||||
Title string `json:"title" bson:"title,omitempty"` //视频标题
|
||||
PublisherID uint64 `json:"publisherID" bson:"publisherID,omitempty"` //上传者ID
|
||||
Coins int64 `json:"coins" bson:"coins,omitempty"` //定价
|
||||
Income int64 `json:"income" bson:"income,omitempty"` //当日收入
|
||||
Tax float64 `json:"tax" bson:"tax,omitempty"` //税
|
||||
PayCount int64 `json:"payCount" bson:"payCount,omitempty"` //购买数
|
||||
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` //日志创建时间
|
||||
}
|
||||
|
||||
type VideoStatPage struct {
|
||||
Total int64 `json:"total" bson:"total"`
|
||||
List []VideoStatRecord `json:"list" bson:"list"`
|
||||
}
|
||||
|
||||
var payCountMin int64 = 0
|
||||
|
||||
// VideoStatPages
|
||||
func VideoStatPages(skip, limit int64,
|
||||
sumDateGTEAndLTMatch SumDateGTEAndLTMatch,
|
||||
vidMatch VidMatch,
|
||||
vidInMatch VidInMatch,
|
||||
) (VideoStatPage, error) {
|
||||
matList := []Matcher{
|
||||
(&PayCountGTMatch{&payCountMin}).New(),
|
||||
sumDateGTEAndLTMatch.New(),
|
||||
vidMatch.New(),
|
||||
vidInMatch.New(),
|
||||
}
|
||||
sort := bson.D{{Key: "sumDate", Value: -1}}
|
||||
statList, err := List(sort, skip, limit, matList...)
|
||||
if err != nil {
|
||||
return VideoStatPage{}, err
|
||||
}
|
||||
vidList := make([]ObjectID, len(statList))
|
||||
for i, v := range statList {
|
||||
vidList[i] = v.Vid
|
||||
}
|
||||
videoMap, err := vidmod.VideoMap(vidList)
|
||||
if err != nil {
|
||||
return VideoStatPage{}, err
|
||||
}
|
||||
//用户id
|
||||
statListLen := len(statList)
|
||||
userIds := make([]uint64, 0, statListLen)
|
||||
recordList := make([]VideoStatRecord, statListLen)
|
||||
for i, stat := range statList {
|
||||
_stat := stat
|
||||
vid := _stat.Vid
|
||||
videoInfo := Video{
|
||||
ID: &vid,
|
||||
}
|
||||
if video, ok := videoMap[vid]; ok {
|
||||
videoInfo.Title = &video.Title
|
||||
videoInfo.PublisherID = &video.PublisherID
|
||||
videoInfo.Coins = &video.Coins
|
||||
d := vidhelp.CalculateVideoSellDays(video.ReviewAt)
|
||||
videoInfo.Day = &d
|
||||
userIds = append(userIds, video.PublisherID)
|
||||
}
|
||||
tax := maths.ToFloat64_b2(_stat.Tax)
|
||||
recordList[i] = VideoStatRecord{
|
||||
SumDate: &_stat.SumDate,
|
||||
Video: videoInfo,
|
||||
Income: &_stat.Income,
|
||||
Tax: &tax,
|
||||
PayCount: &_stat.PayCount,
|
||||
CreatedAt: &_stat.CreatedAt,
|
||||
}
|
||||
}
|
||||
//查询用户信息
|
||||
userMap, err := usermod.UserMap(userIds)
|
||||
if err == nil {
|
||||
for _, r := range recordList {
|
||||
if r.Video.PublisherID == nil {
|
||||
log.Warn(fmt.Sprintf("视频[%v]信息异常==>缺少上传者ID", r.Video.ID))
|
||||
continue
|
||||
}
|
||||
if u, ok := userMap[*r.Video.PublisherID]; ok {
|
||||
r.Video.PublisherName = &u.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
count, err := Count(matList...)
|
||||
if err != nil {
|
||||
return VideoStatPage{}, err
|
||||
}
|
||||
return VideoStatPage{
|
||||
Total: count,
|
||||
List: recordList,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user