Files
huangguo_server/models/v/txnmod/discStat.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

191 lines
5.8 KiB
Go

package txnmod
import (
"fmt"
"strings"
"time"
"91porn-server/common/log"
"91porn-server/common/pageopt"
"91porn-server/common/ysinterface/disc"
"91porn-server/models/commod"
)
type DiscSeqe = commod.DiscSeqe
type DistrictStatKey struct {
DiscSeqe `bson:",inline"` //商区码
SysType string `bson:"sysType"` //系统类型 iOS Android
}
func (d DistrictStatKey) GetDiscCode() string {
return strings.ToUpper(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 DiscSeqeTransCount(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{}
if err := coll(nil).Find(&list, filter); 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
}
// DiscSeqeTransAmount
func DiscSeqeTransAmount(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"` //商区码
Amount int64 `bson:"amount"`
}{}
if err := coll(nil).Find(&list, filter); err != nil {
return nil, err
}
m := make(map[DistrictStater]int64, len(list))
for _, v := range list {
if v.String() != "" {
m[v.DistrictStatKey] += v.Amount
}
}
return m, nil
}
// DiscTransUIDSMap
func DiscTransUIDSMap(start, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) {
mats = append(mats, (&CreatedAtGTEAndLTMatch{GTE: &start, LT: &end}).New())
filter := pageopt.MergeM(mats)
list := []struct {
DistrictCode string `json:"districtCode" bson:"districtCode"` //商区码
UID uint64 `bson:"uid"`
}{}
if err := coll(nil).Find(&list, filter); err != nil {
return nil, err
}
m := make(map[DistrictStater][]uint64, len(list))
for _, v := range list {
key := DistrictStatKey{
DiscSeqe: DiscSeqe{DistrictCode: v.DistrictCode},
}
if key.String() != "" {
m[key] = append(m[key], v.UID)
}
}
return m, nil
}
// DiscSeqeTransUIDSMap
func DiscSeqeTransUIDSMap(start, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) {
mats = append(mats, (&CreatedAtGTEAndLTMatch{GTE: &start, LT: &end}).New())
filter := pageopt.MergeM(mats)
list := []struct {
DistrictStatKey `bson:",inline"` //商区码
UID uint64 `bson:"uid"`
}{}
if err := coll(nil).Find(&list, filter); err != nil {
return nil, err
}
m := make(map[DistrictStater][]uint64, len(list))
for _, v := range list {
if v.String() != "" {
m[v.DistrictStatKey] = append(m[v.DistrictStatKey], v.UID)
}
}
return m, nil
}
// DiscSeqeTransTaxAmount
func DiscSeqeTransTaxAmount(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"` //税额
}{}
if err := coll(nil).Find(&list, filter); 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
}
// DiscSeqeBuyVipCount 时间内购买VIP次数
func DiscSeqeBuyVipCount(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
payVIP := PayVIP.Key()
mats = append(mats, (&TranTypeMatch{&payVIP}).New())
return DiscSeqeTransCount(start, end, mats...)
}
// DiscSeqeBuyVipCount 时间内购买VIP金额
func DiscSeqeBuyVipAmount(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
payVIP := PayVIP.Key()
mats = append(mats, (&TranTypeMatch{&payVIP}).New())
return DiscSeqeTransAmount(start, end, mats...)
}
// DiscBuyVipUIDSMap 时间内购买用户列表
func DiscBuyVipUIDSMap(start, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) {
payVIP := PayVIP.Key()
mats = append(mats, (&TranTypeMatch{&payVIP}).New())
return DiscTransUIDSMap(start, end, mats...)
}
// DiscSeqeBuyVipUIDSMap 时间内购买用户列表
func DiscSeqeBuyVipUIDSMap(start, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) {
payVIP := PayVIP.Key()
mats = append(mats, (&TranTypeMatch{&payVIP}).New())
return DiscSeqeTransUIDSMap(start, end, mats...)
}
// DiscSeqeBuyVidCount 时间内购买VID次数
func DiscSeqeBuyVidCount(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
payVID := PayVID.Key()
mats = append(mats, (&TranTypeMatch{&payVID}).New())
return DiscSeqeTransCount(start, end, mats...)
}
// DiscSeqeBuyVidAmount 时间内购买VID金额
func DiscSeqeBuyVidAmount(start, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) {
payVID := PayVID.Key()
mats = append(mats, (&TranTypeMatch{&payVID}).New())
return DiscSeqeTransAmount(start, end, mats...)
}
// DiscSeqeWorksIncomeTaxAmount 时间内购买VID税额
func DiscSeqeWorksIncomeTaxAmount(start, end time.Time, mats ...Matcher) (map[DistrictStater]float64, error) {
worksIncome := WorksIncome.Key()
mats = append(mats, (&TranTypeMatch{&worksIncome}).New())
return DiscSeqeTransTaxAmount(start, end, mats...)
}