package newactivity import ( "fmt" "time" "91porn-server/common/db" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" ) func ExistsOrder(num uint32, req WinRecords) (exists bool, err error) { conf := bson.M{ "date": req.Date, "userId": req.UserId, "modelId": req.ModelId, } if num == 0 { conf["soldOut"] = true } else { conf["serials"] = num } count, err := collSold(nil).Count(conf) return count > 0, err } func BuyPage(req BuyPageReq) (res BuyPageRes, err error) { conf := bson.M{} if req.ModelId != nil { conf["modelId"] = req.ModelId } if req.UserId != nil { conf["userId"] = req.UserId } if req.UserName != nil { conf["userName"] = bson.M{"$regex": req.UserName} } if !req.Date.IsZero() { conf["date"] = req.Date } if !req.Start.IsZero() && !req.End.IsZero() { conf["createdAt"] = bson.M{"$gte": req.Start, "$lt": req.End} } res = BuyPageRes{} opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}}) opts.SetSkip((req.Page - 1) * req.PageSize) opts.SetLimit(req.PageSize) if err = collSold(nil).Find(&res.Data, conf, opts); err != nil { return } res.Total, err = collSold(nil).Count(conf) if err != nil { return } num := struct { Num int64 `bson:"num"` }{} err = collJoin(nil).FindOne(&num, bson.M{}) res.JoinPersons = num.Num return } // 嫩模列表 func InsertSoldLog(t *db.MongoTool, log *SoldRecord) (id primitive.ObjectID, err error) { log.CreatedAt = time.Now() log.UpdatedAt = time.Now() result, err := collSold(t).InsertOne(log) if err != nil { fmt.Println("insert error", err) return } if id, ok := result.InsertedID.(primitive.ObjectID); ok { return id, nil } return }