Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

140 lines
2.6 KiB
Go

package newactivity
import (
"time"
"91porn-server/common/timeutil"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func BulkAddModels(insertSqls []mongo.WriteModel) error {
if len(insertSqls) > 0 {
_, err := collModel(nil).Bulk(insertSqls)
return err
}
return nil
}
// 嫩模列表
func ModelList() (res ListRes, err error) {
res = ListRes{}
if err = collModel(nil).Aggregate(&res.Models, []bson.M{
{
"$group": bson.M{
"_id": "$location",
"models": bson.M{
"$push": bson.M{
"id": "$id",
"name": "$name",
"location": "$location",
"bgImg": "$bgImg",
"video": "$video",
},
},
},
},
{
"$project": bson.M{
"location": "$_id",
"models": 1,
"_id": 0,
},
},
{
"$sort": bson.M{
"models.id": 1,
},
},
}); err != nil {
return
}
num := struct {
JoinPersons int64 `bson:"num"` //参与人数
}{}
err = collJoin(nil).FindOne(&num, bson.M{})
res.JoinPersons = num.JoinPersons
return
}
// 单个嫩模
func FindOne(modelId uint32) (res FindOneRes, err error) {
res = FindOneRes{}
date := timeutil.BeginningOfDay(time.Now())
if time.Now().Hour() >= 20 {
date = date.Add(24 * time.Hour)
}
if err = collModel(nil).AggregateDecode(&res, []bson.M{
{
"$match": bson.M{
"id": modelId,
},
},
{
"$lookup": bson.M{
"from": "activity_gift_stock",
"pipeline": []bson.M{
{
"$match": bson.M{
"modelId": modelId,
"date": date,
},
},
{"$project": bson.M{
"_id": 0,
"giftLeft": 1,
"soldOut": 1,
}},
},
"as": "gift_stock",
},
},
{
"$unwind": bson.M{
"path": "$gift_stock",
"preserveNullAndEmptyArrays": true,
},
},
{
"$project": bson.M{
"_id": 0,
"id": 1,
"name": 1,
"bgImg": 1,
"location": 1,
"video": 1,
"giftLeft": "$gift_stock.giftLeft",
"soldOut": "$gift_stock.soldOut",
},
},
}); err != nil {
return
}
opts := options.Find().SetSort(bson.D{{Key: "createdAt", Value: -1}})
conf := bson.M{
"modelId": modelId,
"date": date,
}
if res.SoldOut {
conf["soldOut"] = true
}
err = collSold(nil).Find(&res.SoldList, conf, opts)
return
}
// 嫩模列表
func UpdateJoinNum(num int64) error {
_, err := collJoin(nil).UpsertOne(bson.M{}, bson.M{"$set": bson.M{"num": num}})
return err
}
// 获取参与人数
func GetJoinNum() (int64, error) {
num := struct {
JoinPersons int64 `bson:"num"` //参与人数
}{}
return num.JoinPersons, collJoin(nil).FindOne(&num, bson.M{})
}