package usermod import ( "fmt" "strings" "time" "91porn-server/common/log" "91porn-server/common/pageopt" "91porn-server/common/ysinterface/disc" "91porn-server/models/commod" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) // DistrictStatKey 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}, "-")) } // DistrictStater type DistrictStater = disc.DistrictStater var emptyString string // DiscSeqeUserCountMap 时间内商区/序列注册数 func DiscSeqeUserCountMap(mats ...Matcher) (map[DistrictStater]int64, error) { mats = append(mats, (&DistrictCodeGtMatch{&emptyString}).New()) filter := pageopt.MergeM(mats) if len(filter) == 0 { log.Warn("DiscSeqeUserCountMap not have filter") return make(map[DistrictStater]int64), nil } opt := (&options.FindOptions{}).SetProjection(bson.M{ "districtCode": 1, "promSeqe": 1, "sysType": 1, }) list := []DistrictStatKey{} if err := coll(nil).Find(&list, filter, opt); err != nil { log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DiscNewUserCountByTime", table, "Find", err)) return nil, err } m := make(map[DistrictStater]int64) for _, v := range list { if v.String() != "" { m[v] += 1 } } return m, nil } // DiscSeqeNewUserCountByTime 时间内商区/序列注册数 func DiscSeqeNewUserCountByTime(start time.Time, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) { mats = append(mats, (&commod.DiscBindAtGTEAndLTMatch{GTE: &start, LT: &end}).New()) return DiscSeqeUserCountMap(mats...) } // DiscSeqeNewUIDSMap 时间内商区注册用户 func DiscSeqeNewUIDSMap(mats ...Matcher) (map[DistrictStater][]uint64, error) { filter := pageopt.MergeM(mats) opt := (&options.FindOptions{}).SetProjection(bson.M{ "districtCode": 1, "promSeqe": 1, "sysType": 1, "uid": 1, }) list := []struct { DistrictStatKey `bson:",inline"` //商区码 UID uint64 `bson:"uid"` }{} if err := coll(nil).Find(&list, filter, opt); 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 } // DiscSeqeNewUIDSMapByTime 时间内商区/序列注册用户 func DiscSeqeNewUIDSMapByTime(start time.Time, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) { mats = append(mats, (&commod.DiscBindAtGTEAndLTMatch{GTE: &start, LT: &end}).New()) return DiscSeqeNewUIDSMap(mats...) } // DiscNewUIDSMap 商区注册用户 func DiscNewUIDSMap(mats ...Matcher) (map[DistrictStater][]uint64, error) { filter := pageopt.MergeM(mats) opt := (&options.FindOptions{}).SetProjection(bson.M{ "districtCode": 1, "uid": 1, }) list := []struct { DistrictCode string `bson:"districtCode"` //商区码 UID uint64 `bson:"uid"` }{} if err := coll(nil).Find(&list, filter, opt); 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 } // DiscNewUIDSMapByTime 时间内商区注册用户 func DiscNewUIDSMapByTime(start time.Time, end time.Time, mats ...Matcher) (map[DistrictStater][]uint64, error) { mats = append(mats, (&commod.DiscBindAtGTEAndLTMatch{GTE: &start, LT: &end}).New()) return DiscNewUIDSMap(mats...) } // DiscNewCountMapByTime 时间内商区/序列注册数 func DiscNewCountMapByTime(start time.Time, end time.Time, mats ...Matcher) (map[DistrictStater]int64, error) { mats = append(mats, (&commod.DiscBindAtGTEAndLTMatch{GTE: &start, LT: &end}).New()) filter := pageopt.MergeM(mats) opt := (&options.FindOptions{}).SetProjection(bson.M{ "districtCode": 1, "uid": 1, }) list := []struct { DistrictCode string `bson:"districtCode"` //商区码 }{} if err := coll(nil).Find(&list, filter, opt); err != nil { return nil, err } m := make(map[DistrictStater]int64, len(list)) for _, v := range list { key := DistrictStatKey{DiscSeqe: DiscSeqe{DistrictCode: v.DistrictCode}} if key.String() != "" { m[key] += 1 } } return m, nil }