package txnmod import ( "91porn-server/common/log" "91porn-server/common/pageopt" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo/options" ) type Matcher = pageopt.Matcher // TranTypeMatch type TranTypeMatch struct { TransType *string } func (s *TranTypeMatch) New() Matcher { return pageopt.NewAssignMatch("tranType", s.TransType) } // DistrictCodeMatch type DistrictCodeMatch struct { DistrictCode *string } func (s *DistrictCodeMatch) New() Matcher { return pageopt.NewAssignMatch("districtCode", s.DistrictCode) } // DistrictCodeINMatch type DistrictCodeINMatch struct { DistrictCodeList []string } func (d *DistrictCodeINMatch) New() Matcher { return pageopt.NewInMatch("districtCode", d.DistrictCodeList) } // PromSeqeMatch type PromSeqeMatch struct { Seqe *string } func (d *PromSeqeMatch) New() Matcher { return pageopt.NewAssignMatch("promSeqe", d.Seqe) } // SysTypeMatch type SysTypeMatch struct { SysType *string } func (d *SysTypeMatch) New() Matcher { return pageopt.NewAssignMatch("sysType", d.SysType) } // IsDirectMatch type IsDirectMatch struct { IsDirect *bool } func (b *IsDirectMatch) New() Matcher { return pageopt.NewAssignMatch("isDirect", b.IsDirect) } // CreatedAtGTEAndLTMatch type CreatedAtGTEAndLTMatch = pageopt.CreatedAtGTEAndLTMatch // UIDMatch type UIDMatch = pageopt.UIDMatch // UIDInMatch type UIDInMatch = pageopt.UIDInMatch // IDMatch type IDMatch = pageopt.IDMatch type Sort = bson.D var Sort_CreatedAt_n1 = Sort{{Key: "createdAt", Value: -1}} func List(sort Sort, skip, limit *int64, matchers ...Matcher) ([]TransactionLog, error) { filter := pageopt.MergeM(matchers) opt := (&options.FindOptions{}) if len(sort) != 0 { opt.SetSort(sort) } if skip != nil { opt.SetSkip(*skip) } if limit != nil { opt.SetLimit(*limit) } list := []TransactionLog{} if err := coll(nil).Find(&list, filter, opt); err != nil { log.Error("txnmod List error", log.E(err)) return nil, err } return list, nil } func Count(matchers ...Matcher) (int64, error) { filter := pageopt.MergeM(matchers) count, err := coll(nil).Count(filter) if err != nil { log.Error("txnmod Count error", log.E(err)) return 0, err } return count, nil } func AmountSum(matchers ...Matcher) (int64, error) { filter := pageopt.MergeM(matchers) pipeline := []M{} pipeline = append(pipeline, M{"$match": filter}) pipeline = append(pipeline, M{"$group": M{"_id": nil, "amount": M{"$sum": "$amount"}, }}) var amount struct { Amount int64 `bson:"amount"` //金币 } if err := coll(nil).AggregateDecode(&amount, pipeline); err != nil { log.Error("txnmod Sum error", log.E(err)) return 0, err } return amount.Amount, nil }