42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package backpackmod
|
|
|
|
import (
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type QueryAllWebCond struct {
|
|
Page int64 `form:"page" binding:"required"`
|
|
Limit int64 `form:"limit" binding:"required"`
|
|
Uid *int `form:"uid"` // 用户ID
|
|
Status *int `form:"status"` // 使用状态 1、已使用 2、未使用 3、过期
|
|
GoodsType *int `form:"goodsType"` // 类型
|
|
GoodsDesc *string `form:"goodsDesc"` // 描述
|
|
}
|
|
|
|
type QueryAllRes struct {
|
|
List []*Backpack `json:"list"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
|
|
func (receiver *QueryAllWebCond) Filter() bson.M {
|
|
var query = bson.M{}
|
|
if receiver.Uid != nil {
|
|
query["uid"] = receiver.Uid
|
|
}
|
|
if receiver.GoodsType != nil {
|
|
query["goodsType"] = receiver.GoodsType
|
|
}
|
|
if receiver.GoodsDesc != nil {
|
|
query["goodsDesc"] = receiver.GoodsDesc
|
|
}
|
|
if receiver.Status != nil {
|
|
query["status"] = receiver.Status
|
|
}
|
|
return query
|
|
}
|
|
|
|
func (receiver QueryAllWebCond) Options() *options.FindOptions {
|
|
return options.Find().SetSkip((receiver.Page - 1) * receiver.Limit).SetLimit(receiver.Limit).SetSort(bson.D{{"createTime", -1}})
|
|
}
|