package deduction import ( "91porn-server/models/l/payvidlgmod" "91porn-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 }