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,83 @@
package checkinconfigmod
import (
"fmt"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
)
const table = models.CheckinConfig
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
func initIndex() {
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "enable", Value: 1}},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
func Init() {
mdb = db.Init(table)
initIndex()
}
// FindOne 查找签到配置
func FindOne(filter primitive.M) (*CheckinConfig, error) {
var config CheckinConfig
if err := coll(nil).FindOne(&config, filter); err != nil {
log.Error(fmt.Sprintf("[checkinconfigmod:FindOne] failed: %+v", err))
return nil, err
}
if config.ID.IsZero() {
return nil, nil
}
return &config, nil
}
// UpdateOne 更新签到配置
func UpdateOne(filter primitive.M, update primitive.M) error {
result, err := coll(nil).UpdateOne(filter, update)
if err != nil {
log.Error(fmt.Sprintf("[checkinconfigmod:UpdateOne] failed: %+v", err))
return err
}
if result.MatchedCount == 0 {
return mongo.ErrNoDocuments
}
return nil
}
// InsertOne 插入签到配置
func InsertOne(config *CheckinConfig) error {
if _, err := coll(nil).InsertOne(config); err != nil {
log.Error(fmt.Sprintf("[checkinconfigmod:InsertOne] failed: %+v", err))
return err
}
return nil
}
// Count 统计数量
func Count(filter primitive.M) (int64, error) {
count, err := coll(nil).Count(filter)
if err != nil {
log.Error(fmt.Sprintf("[checkinconfigmod:Count] failed: %+v", err))
return 0, err
}
return count, nil
}