@@ -0,0 +1,95 @@
|
||||
package statordermod
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/pageopt"
|
||||
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
type (
|
||||
Matcher = pageopt.Matcher
|
||||
|
||||
// ChannelMatch
|
||||
ChannelMatch struct {
|
||||
Type *string
|
||||
}
|
||||
)
|
||||
|
||||
func (t *ChannelMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("channel", t.Type)
|
||||
}
|
||||
|
||||
// TypeMatch
|
||||
type TypeMatch struct {
|
||||
Type *OrderType
|
||||
}
|
||||
|
||||
func (t *TypeMatch) New() Matcher {
|
||||
return pageopt.NewAssignMatch("type", t.Type)
|
||||
}
|
||||
|
||||
// SumDateGTEAndLTMatch
|
||||
type SumDateGTEAndLTMatch struct {
|
||||
GTE *time.Time
|
||||
LT *time.Time
|
||||
}
|
||||
|
||||
func (s *SumDateGTEAndLTMatch) New() Matcher {
|
||||
return pageopt.NewGTEAndLTMatch("sumDate", s.GTE, s.LT)
|
||||
}
|
||||
|
||||
var Sort_SumDate_n1 = Sort{{Key: "sumDate", Value: -1}}
|
||||
|
||||
func List(sort Sort, skip, limit *int64, matchers ...Matcher) ([]OrderState, 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 := []OrderState{}
|
||||
if err := coll(nil).Find(&list, filter, opt); err != nil {
|
||||
log.Error("statordermod 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("statordermod Count error", log.E(err))
|
||||
return 0, err
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Sum
|
||||
func Sum(matchers ...Matcher) (Items, error) {
|
||||
filter := pageopt.MergeM(matchers)
|
||||
pipeline := []M{}
|
||||
pipeline = append(pipeline, M{"$match": filter})
|
||||
pipeline = append(pipeline, M{"$group": M{"_id": nil,
|
||||
"orderCount": M{"$sum": "$orderCount"},
|
||||
"completeOrderCount": M{"$sum": "$completeOrderCount"},
|
||||
"orderAmount": M{"$sum": "$orderAmount"},
|
||||
"completeOrderAmount": M{"$sum": "$completeOrderAmount"},
|
||||
"paidOrderCount": M{"$sum": "$paidOrderCount"},
|
||||
"paidAmount": M{"$sum": "$paidAmount"},
|
||||
}})
|
||||
items := Items{}
|
||||
if err := coll(nil).AggregateDecode(&items, pipeline); err != nil {
|
||||
log.Error("statordermod Sum error", log.E(err))
|
||||
return Items{}, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user