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
}
+37
View File
@@ -0,0 +1,37 @@
package exchlogmod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type ObjectID = primitive.ObjectID
// Init 初始化索引
func Init() {
mdb = db.Init(table)
initIndex()
}
type ExchangeLog struct {
ID ObjectID `json:"id" bson:"_id,omitempty"`
Code string `json:"code" bson:"code"` // 兑换码
UserID uint64 `json:"userID" bson:"userID"` // 兑换者
BatchNum string `json:"batchNum" bson:"batchNum"` // 批次号
Channel string `json:"channel" bson:"channel"` // 所属渠道
Authority string `json:"authority" bson:"authority"` // 兑换权限
Desc string `json:"desc" bson:"-"` // 说明
Reward int `json:"reward" bson:"reward"` // 奖励值
RewardCount int `json:"rewardCount" bson:"rewardCount"` // 奖励量
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间/兑换时间
}
type FilterDoc struct {
Code *string `bson:"code,omitempty"` // 兑换码
UserID *uint64 `bson:"userID,omitempty"` // 兑换者
Channel *string `bson:"channel,omitempty"` // 所属渠道
Authority *string `bson:"authority,omitempty"` // 兑换权限
}
+25
View File
@@ -0,0 +1,25 @@
package exchlogmod
import (
"time"
"91porn-server/models/commod"
)
type ListReqParam struct {
Code *string `form:"code" json:"code"` // 兑换码
UserID *uint64 `form:"userID" json:"userID"` // 兑换者
Channel *string `form:"channel" json:"channel"` // 所属渠道
Authority *string `form:"authority" json:"authority"` // 兑换权限
Page commod.Page
}
type ListResp struct {
Code string `json:"code"` // 兑换码
UserID uint64 `json:"userID"` // 兑换者
Channel string `json:"channel"` // 所属渠道
Authority string `json:"authority"` // 兑换权限
Reward int `json:"reward"` // 奖励值
RewardCount int `json:"rewardCount"` // 奖励量
CreatedAt time.Time `json:"createdAt"` // 创建时间/兑换时间
}