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
+56
View File
@@ -0,0 +1,56 @@
package questionnremod
import (
"fmt"
"time"
"91porn-server/common/db"
"91porn-server/models"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const table = models.Questionnaire
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// initIndex 索引设置
func initIndex() {
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
{
Keys: bson.D{{Key: "uid", Value: 1}},
},
{
Keys: bson.D{{Key: "level", Value: 1}},
},
{
Keys: bson.D{{Key: "uid", Value: 1}, {Key: "level", Value: 1}, {Key: "questionnaireId", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
}
if _, err := coll(nil).CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
func Insert(q Questionnaire) error {
q.CreatedAt = time.Now()
_, err := coll(nil).InsertOne(q)
return err
}
func GetByUID(uid uint64) ([]Questionnaire, error) {
data := make([]Questionnaire, 0)
f := bson.M{"uid": uid}
return data, coll(nil).Find(&data, f)
}
+36
View File
@@ -0,0 +1,36 @@
package questionnremod
import (
"time"
"91porn-server/common/db"
)
var mdb *db.MongoDB
type Questionnaire struct {
QuestionId uint64 `json:"questionId" bson:"_id"`
QuestionnaireId uint64 `json:"questionnaireId" bson:"questionnaireId"`
Level int `json:"level" bson:"level"`
Questions []Question `json:"questions" bson:"questions"` //答案
Codes []string `json:"codes" bson:"codes"`
UID uint64 `json:"uid" bson:"uid"` //用户id
Gold int `json:"gold" bson:"gold"` //金币
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
}
type Question struct {
Question int `json:"question" bson:"question"` //问题序号
Answer string `json:"answer" bson:"answer"` //答案序号
}
func Init() {
mdb = db.Init(table)
initIndex()
}
type SubmitRes struct {
QuestionId uint64 `json:"questionId"`
Gold int `json:"gold" bson:"gold"` //金币
Codes []string `json:"codes" bson:"codes"`
}