Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

115 lines
2.9 KiB
Go

package payvidlgmod
import (
"fmt"
"strings"
"time"
"91porn-server/common/log"
"91porn-server/common/pageopt"
"91porn-server/common/ysinterface/disc"
"go.mongodb.org/mongo-driver/mongo/options"
)
type DistrictStatKey struct {
DiscSeqe `bson:",inline"` //商区码
SysType string `bson:"sysType"` //系统类型 iOS Android
}
func (d DistrictStatKey) GetDiscCode() string {
return d.DistrictCode
}
func (d DistrictStatKey) GetPromSeqe() string {
return d.PromSeqe
}
func (d DistrictStatKey) GetSysType() string {
return d.SysType
}
func (d DistrictStatKey) String() string {
if d.DiscSeqe.String() == "" {
return ""
}
return strings.ToUpper(strings.Join([]string{d.DiscSeqe.String(), d.SysType}, "-"))
}
type DistrictStater = disc.DistrictStater
// DiscSeqeTransCount
func DiscSeqeBuyVidCount(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
mats = append(mats, (&CreatedAtGTEAndLTMatch{GTE: &start, LT: &end}).New())
filter := pageopt.MergeM(mats)
list := []DistrictStatKey{}
opt := (&options.FindOptions{}).SetProjection(M{
"districtCode": 1,
"promSeqe": 1,
"sysType": 1,
})
if err := coll(nil).Find(&list, filter, opt); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DiscSeqeTransCount", table, "Find", err))
return nil, err
}
m := make(map[DistrictStater]int64)
for _, v := range list {
if v.String() != "" {
m[v] += 1
}
}
return m, nil
}
// DiscSeqeBuyVidCoins
func DiscSeqeBuyVidCoins(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
mats = append(mats, (&CreatedAtGTEAndLTMatch{GTE: &start, LT: &end}).New())
filter := pageopt.MergeM(mats)
list := []struct {
DistrictStatKey `bson:",inline"` //商区码
Coins int64 `bson:"coins"`
}{}
opt := (&options.FindOptions{}).SetProjection(M{
"districtCode": 1,
"promSeqe": 1,
"sysType": 1,
"coins": 1,
})
if err := coll(nil).Find(&list, filter, opt); err != nil {
return nil, err
}
m := make(map[DistrictStater]int64, len(list))
for _, v := range list {
if v.String() != "" {
m[v.DistrictStatKey] += v.Coins
}
}
return m, nil
}
// DiscSeqeTaxAmount
func DiscSeqeTaxAmount(start, end time.Time, mats ...Matcher) (map[DistrictStater]float64, error) {
mats = append(mats, (&CreatedAtGTEAndLTMatch{GTE: &start, LT: &end}).New())
filter := pageopt.MergeM(mats)
list := []struct {
DistrictStatKey `bson:",inline"` //商区码
TaxAmount float64 `bson:"taxAmount"` //税额
}{}
opt := (&options.FindOptions{}).SetProjection(M{
"districtCode": 1,
"promSeqe": 1,
"sysType": 1,
"taxAmount": 1,
})
if err := coll(nil).Find(&list, filter, opt); err != nil {
return nil, err
}
m := make(map[DistrictStater]float64, len(list))
for _, v := range list {
if v.String() != "" {
m[v.DistrictStatKey] += v.TaxAmount
}
}
return m, nil
}