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
+73
View File
@@ -0,0 +1,73 @@
package bannerjumpdata
import (
"time"
"91porn-server/common/cachev2"
"91porn-server/common/db"
"91porn-server/models"
"91porn-server/models/v/bannerjumpmod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ListRes struct {
List []bannerjumpmod.BannerJump
Count int64
HasNext bool
}
// GetAllFromCache 获取所有数据
func GetAllFromCache() (res []bannerjumpmod.BannerJump, err error) {
t := time.Now()
cond := bson.M{"enable": true, "startAt": bson.M{"$lte": t}, "endAt": bson.M{"$gt": t}}
sort := bson.D{{"weight", -1}, {"createdAt", -1}}
_, err = cachev2.Classes().CacheTime(8*time.Minute).AutoListKey(models.BannerJump+"-all").ResBind(&res).Cache(bannerjumpmod.GetAll, cond, sort)
return
}
// InsertData 插入数据
func InsertData(t *db.MongoTool, data bannerjumpmod.BannerJump) (primitive.ObjectID, error) {
newID, err := bannerjumpmod.Insert(t, data)
if err != nil {
return newID, err
}
// 清除缓存数据
_, err = cachev2.Classes().Table(models.BannerJump).AutoClear(true, nil)
if err != nil {
return newID, err
}
return newID, nil
}
// UpdateData 更新数据
func UpdateData(t *db.MongoTool, id string, data map[string]interface{}) (int64, error) {
objID, err := primitive.ObjectIDFromHex(id)
if err != nil {
return 0, err
}
affect, err := bannerjumpmod.UpdateByID(t, objID, data)
if err != nil {
return 0, err
}
// 清理缓存
_, _ = cachev2.Classes().Table(models.BannerJump).AutoClear(true, &id)
return affect, err
}
// DeleteData 删除数据
func DeleteData(t *db.MongoTool, id primitive.ObjectID) (err error) {
err = bannerjumpmod.DeleteByID(t, id)
if err != nil {
return
}
// 清理缓存
all := "*"
_, _ = cachev2.Classes().Table(models.BannerJump).AutoClear(true, &all)
return
}