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
+121
View File
@@ -0,0 +1,121 @@
package exchlogmod
import (
"fmt"
"91porn-server/common"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models"
"91porn-server/models/commod"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var mdb *db.MongoDB
const table = models.ExchLog
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
func initIndex() {
many := []mongo.IndexModel{ //batch set indexes //value is the type 1 or -1
{
Keys: bson.D{{Key: "code", Value: 1}, {Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "userID", Value: 1}, {Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "userID", Value: 1}, {Key: "batchNum", Value: 1}},
},
{
Keys: bson.D{{Key: "channel", Value: 1}, {Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "authority", Value: 1}, {Key: "createdAt", Value: 1}},
},
{
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(doc ExchangeLog) error {
if _, err := coll(nil).InsertOne(doc); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Insert", table, "InsertOne", err),
log.Any("doc", doc),
)
return err
}
return nil
}
func GetExchangeLogList(filterParams FilterDoc, page commod.Page) (total int64, data []ExchangeLog, err error) {
filter, _ := common.ToBsonM(filterParams)
var skip = int64((page.PageNumber - 1) * page.PageSize)
var limit = int64(page.PageSize)
var opts = options.Find()
opts.SetSort(bson.D{{Key: "createdAt", Value: -1}}).SetSkip(skip).SetLimit(limit)
if err = coll(nil).Find(&data, filter, opts); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetExchangeLogList", table, "Find", err),
log.Any("filterParams", filterParams),
log.Any("page", page),
)
return
}
if total, err = coll(nil).Count(filter); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetExchangeLogList", table, "Count", err),
log.Any("filterParams", filterParams),
log.Any("page", page),
)
return
}
return
}
// 获取用户兑换日志
func GetLogByUIDAndBatchNum(uid uint64, batchNum string) (data ExchangeLog, err error) {
if err = coll(nil).FindOne(&data, bson.M{"userID": uid, "batchNum": batchNum}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetExchangeLogList", table, "Find", err),
log.Any("uid", uid),
log.Any("batchNum", batchNum),
)
return
}
return
}
// 获取用户兑换日志
func GetLogByUIDAndAuthority(uid uint64, authority string) (data ExchangeLog, err error) {
if err = coll(nil).FindOne(&data, bson.M{"userID": uid, "authority": authority}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetExchangeLogList", table, "Find", err),
log.Any("uid", uid),
log.Any("authority", authority),
)
return
}
return
}
// 获取用户兑换
func GetLogByUIDAndCode(uid uint64, code string) (data ExchangeLog, err error) {
if err = coll(nil).FindOne(&data, bson.M{"userID": uid, "code": code}); err != nil {
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetLogByUIDAndCode", table, "Find", err),
log.Any("uid", uid),
log.Any("code", code),
)
return
}
return
}