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
+151
View File
@@ -0,0 +1,151 @@
package rchgamtmod
import (
"encoding/json"
"errors"
"fmt"
"91porn-server/app/appg"
"91porn-server/common/constant/redisconst"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/common/redis"
"91porn-server/models"
"91porn-server/web/webg"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const table = models.Gold
func initIndex() {
coll := coll(nil)
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "coins", Value: 1}, {Key: "price", Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := coll.CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
var trueActiveList = "trueActiveList"
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// InsertOne 插入一条数据
func InsertGold(g *Gold) error {
defer redisCachDel(trueActiveList)
if _, err := coll(nil).InsertOne(g); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertGold", table, "InsertOne", err), log.Any("g", g))
return err
}
return nil
}
// Delete 删除数据
func DeleteGold(cond bson.M) (int64, error) {
defer redisCachDel(trueActiveList)
result, err := coll(nil).DeleteMany(cond)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DeleteGold", table, "DeleteMany", err), log.Any("cond", cond))
return 0, err
}
return result.DeletedCount, err
}
// Update 金币配置更新
func UpdateGold(cond bson.M, updt bson.M) (int64, error) {
defer redisCachDel(trueActiveList)
result, err := coll(nil).UpdateMany(cond, bson.M{"$set": updt})
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdateGold", table, "UpdateMany", err),
log.Any("cond", cond),
log.Any("updt", updt),
)
return 0, err
}
return result.ModifiedCount, nil
}
// GetGoldListByActiveTrue 条件获取金币配置表
func GetGoldByID(id primitive.ObjectID) (*Gold, error) {
var g Gold
if err := coll(nil).FindOneByID(&g, id); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetGoldByID", table, "FindOneByID", err), log.Any("id", id))
return nil, err
}
return &g, nil
}
// GetGoldListByActiveTrue 条件获取金币配置表
func GetGoldListByActiveTrue() ([]*Gold, error) {
var back []*Gold
redisKey := redisconst.DataCachKey(table, trueActiveList)
var redisc *redis.Client
if redisc == nil || !redisc.Exists(redisKey) {
opts := options.FindOptions{}
opts.SetSort(bson.D{{Key: "coins", Value: 1}})
err := coll(nil).Find(&back, bson.M{"active": true}, &opts)
if err != nil {
log.ZapLog.Warn("recharge GetGoldListByActiveTrue Find fail", log.E(err))
return nil, err
}
if redisc == nil {
return back, err
}
jsonBytes, err := json.Marshal(back)
if err != nil {
return back, err
}
_ = redisc.Set(redisKey, string(jsonBytes), redisconst.DataCachExpire)
return back, err
}
str, err := redisc.Get(redisKey)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetGoldListByActiveTrue", table, "Find", err))
return nil, err
}
if str == nil {
return back, errors.New("redis key is null")
}
return back, json.Unmarshal([]byte(*str), &back)
}
// GetGoldList 条件获取金币配置表
func GetGoldList() ([]*Gold, error) {
opts := options.FindOptions{}
opts.SetSort(bson.M{"coins": 1})
var back []*Gold
err := coll(nil).Find(&back, bson.M{}, &opts)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetGoldList", table, "Find", err))
return nil, err
}
return back, nil
}
func redisCachDel(m string) {
redisKey := redisconst.DataCachKey(table, m)
_, _ = getRedis().Del(redisKey)
}
func getRedis() *redis.Client {
if appg.Redis != nil {
return appg.Redis
}
if webg.Redis != nil {
return webg.Redis
}
return nil
}
+64
View File
@@ -0,0 +1,64 @@
package rchgamtmod
import (
"time"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
var mdb *db.MongoDB
// Gold 金币配置表
type Gold struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
Name string `json:"name" bson:"name"` //金币名称
Coins int64 `json:"coins" bson:"coins"` //购买金币数
Price int64 `json:"price" bson:"price"` //价格
Active bool `json:"active" bson:"active"` //是否激活
CreatedAt time.Time `json:"createdAt" bson:"createdAt,omitempty"` //创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //刷新时间
}
type PayChannelRes struct {
//充值方式
Type string `bson:"type" json:"type"`
//类型名称:支付宝,微信,银联
TypeName string `form:"typeName" json:"typeName" bson:"typeName" binding:"required"`
//渠道类型 鲨鱼 金鱼
Channel string `form:"channel" json:"channel" bson:"channel"`
//增加的优惠额度
IncrAmount int64 `json:"incrAmount,omitempty" bson:"incrAmount,omitempty"`
//按比率增加额外优惠额 0-1之间 ,如果 incrAmount 与 incrTax 同时存在 以 incrAmount 为准
IncTax float64 `json:"incTax,omitempty" bson:"incTax,omitempty"`
}
// GoldRes 充值金额列表
type GoldRes struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` //表id
Amount int64 `json:"amount" bson:"amount" binding:"required"` //货币数量
Money int64 `json:"money" bson:"money"` //货币价格
TypeName string `json:"typeName" bson:"typeName" binding:"required"` //类型名称
RechargeType []PayChannelRes `json:"rchgType" bson:"rchgType"` //充值方式
}
// GoldRes 游戏充值金额列表
type GameGoldRes struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id"` //表id
Amount int64 `json:"amount" bson:"amount" binding:"required"` //货币数量
Money int64 `json:"money" bson:"money"` //货币价格
CouponDesc string `json:"couponDesc" bson:"couponDesc"` //优惠描述
GiveVipDays int `json:"giveVipDays" bson:"giveVipDays"` //赠送vip天数
LouFengUnlockTimes int `json:"louFengUnlockTimes" bson:"louFengUnlockTimes"` //赠送楼凤解锁次数
GiveGameCoin int64 `json:"giveGameCoin" bson:"giveGameCoin"` //赠送游戏金币
TypeName string `json:"typeName" bson:"typeName" binding:"required"` //类型名称
RechargeType []PayChannelRes `json:"rchgType" bson:"rchgType"` //充值方式
}
func Init() {
mdb = db.Init(table)
initIndex()
}
const RedisKey = "rchgamtmod"
+28
View File
@@ -0,0 +1,28 @@
package rchgamtmod
import "time"
// DelReq 删除请求
type DelReq struct {
IDs []string `form:"ids" json:"ids"`
}
// OpeResp 操作应答
type OpeResp struct {
Count int64 `json:"count"`
}
// GoldReq 金币配置添加
type GoldReq struct {
Name string `form:"name" json:"name"` //金币名称
Coins int64 `form:"coins" json:"coins"` //购买金币数
Price int64 `form:"price" json:"price"` //价格
Active bool `form:"active" json:"active"` //是否激活
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}
// EditGoldReq 金币编辑请求
type EditGoldReq struct {
ID string `form:"id" json:"id"`
GoldReq
}