Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
@@ -0,0 +1,115 @@
package discount_area_video_mod
import (
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var mdb *db.MongoDB
const table = models.DiscountAreaVideo
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// initIndex 初始化索引
func initIndex() {
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "discountAreaId", Value: 1}, {Key: "createdAt", Value: -1}},
},
{
// 根据视频筛选
Keys: bson.D{{Key: "videoID", Value: 1}},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
// BatchAdd 折扣专区批量添加视频
func BatchAdd(list []DiscountAreaVideo) (err error) {
if len(list) == 0 {
return
}
if _, err = coll(nil).InsertMany(list); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "BatchAdd", table, "InsertMany", err))
return err
}
return
}
// GetListByCond 条件获取专区视频列表
func GetListByCond(filter primitive.M, opts ...*options.FindOptions) (list []DiscountAreaVideo, total int64, err error) {
// 获取数量
total, err = coll(nil).Count(filter)
if err != nil {
log.Error(fmt.Sprintf("[METHOD-GetListByCond]==> Model %s Count fail error:%+v:", table, err),
log.Any("filter", filter),
)
return
}
if err = coll(nil).Find(&list, filter, opts...); err != nil {
log.Error(fmt.Sprintf("[METHOD-GetListByCond]==> Model %s Find fail error:%+v:", table, err),
log.Any("filter", filter),
)
return
}
return
}
func GetDiscountAreaVideoByVids(vids []primitive.ObjectID) (list []DiscountAreaVideo, err error) {
filter := bson.M{
"videoID": bson.M{"$in": vids},
}
if err = coll(nil).Find(&list, filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-GetDiscountAreaVideo]==> Model %s Find fail error:%+v:", table, err),
log.Any("filter", filter),
)
return
}
return
}
func GetDiscountAreaVideoByIds(ids []primitive.ObjectID) (list []DiscountAreaVideo, err error) {
if len(ids) == 0 {
return
}
filter := bson.M{
"_id": bson.M{"$in": ids},
}
if err = coll(nil).Find(&list, filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-GetDiscountAreaVideoByIds]==> Model %s Find fail error:%+v:", table, err),
log.Any("filter", filter),
)
return
}
return
}
func DeleteDiscountAreaVideoByIds(ids []primitive.ObjectID) (err error) {
if len(ids) == 0 {
return
}
filter := bson.M{
"_id": bson.M{"$in": ids},
}
if _, err = coll(nil).DeleteMany(filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-DeleteDiscountAreaVideoByIds]==> Model %s DeleteMany fail error:%+v:", table, err),
log.Any("filter", filter),
)
return
}
return
}
+21
View File
@@ -0,0 +1,21 @@
package discount_area_video_mod
import (
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
// DiscountAreaVideo 折扣区视频
type DiscountAreaVideo struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"` // ID
DiscountAreaId primitive.ObjectID `json:"discountAreaId" bson:"discountAreaId" binding:"required"` // 折扣区id
VideoID primitive.ObjectID `json:"videoID" bson:"videoID" binding:"required"` // 视频id
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` // 创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` // 刷新时间
}
func Init() {
mdb = db.Init(table)
initIndex()
}