Files
hjsq_server/web/service/deduction/deduction.go
T
2026-10-08 16:50:13 +08:00

45 lines
1.3 KiB
Go

package deduction
import (
"91jd-server/models/l/payvidlgmod"
"91jd-server/models/v/usermod"
)
func StatPublisherDeduction(arg *Query) (*PublisherDeduction, error) {
res, err := payvidlgmod.PublisherVideoDeductionRange(*arg.UID, *arg.StartTime, *arg.EndTime)
if err != nil {
return nil, err
}
publisher, err := usermod.FindUserByUIDForNoCache(*arg.UID)
if err != nil {
return nil, err
}
// 避免脏数据引起的空指针
if publisher == nil {
publisher = &usermod.User{UID: *arg.UID}
}
deduction, deductionCount, totalAmount, totalCount := int64(0), int64(0), int64(0), int64(0)
for _, stat := range res {
if stat.IsVideoDeduction {
deduction = stat.TotalAmount
deductionCount = stat.VideoCount
}
totalAmount += stat.TotalAmount
totalCount += stat.VideoCount
}
ret := PublisherDeduction{
PublisherInfo: PublisherInfo{
UID: publisher.UID,
Name: publisher.Name,
VideoDeduction: publisher.VideoDeduction,
VideoDeducitonCount: publisher.VideoDeductionCount,
VideoDeductionPayCount: publisher.VideoDeductionPayCount,
},
AfterDeduction: totalAmount - deduction,
BeforeDeduction: totalAmount,
DeductionCount: deductionCount,
NonDeductionCount: totalCount - deductionCount,
}
return &ret, err
}