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
+190
View File
@@ -0,0 +1,190 @@
package rchgchanmod
import (
"encoding/json"
"errors"
"fmt"
"time"
"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.PayChannel
var rchgChansCach = "rchgChansCach:%s"
// initIndex 设置index
func initIndex() {
coll := coll(nil)
many := []mongo.IndexModel{
{
Keys: bson.D{{Key: "cid", Value: 1}, {Key: "payType", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "active", Value: 1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "updatedAt", Value: 1}},
},
}
if _, err := coll.CreateIndex(many); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", table, err))
}
}
func coll(t *db.MongoTool) *db.MongoTool {
if t == nil {
return mdb.Coll(table)
}
return t.Coll(table)
}
// InsertOne 插入一条数据
func InsertPayChannel(p *PayChannel) error {
defer redisCachDel(rchgChansCach)
if _, err := coll(nil).InsertOne(p); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "InsertPayChannel", table, "InsertOne", err))
return err
}
return nil
}
// Delete 删除数据
func DeletePayChannel(ids []string) (int64, error) {
defer redisCachDel(rchgChansCach)
objIDs := make([]primitive.ObjectID, len(ids))
for i, v := range ids {
objIDs[i], _ = primitive.ObjectIDFromHex(v)
}
result, err := coll(nil).DeleteMany(bson.M{"_id": bson.M{"$in": objIDs}})
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "DeletePayChannel", table, "DeleteMany", err))
return 0, err
}
return result.DeletedCount, err
}
// UpdateAmountTypesByCID
func UpdateAmountTypesByCID(cid string, amountTypes []int64) (int64, error) {
defer redisCachDel(rchgChansCach)
result, err := coll(nil).UpdateOne(bson.M{"cid": cid}, bson.M{"$set": bson.M{"amountTypes": amountTypes, "updatedAt": time.Now()}})
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdatePayChannelBaseOnCID", table, "UpdateOne", err),
log.Any("cid", cid),
log.Any("amountTypes", amountTypes),
)
return 0, err
}
return result.ModifiedCount, nil
}
// Update
func UpdatePayChannel(id string, set EditInfo) (int64, error) {
defer redisCachDel(rchgChansCach)
set.UpdatedAt = time.Now()
objID, err := primitive.ObjectIDFromHex(id)
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdatePayChannel", table, "ObjectIDFromHex", err),
log.Any("id", id),
log.Any("set", set),
)
return 0, err
}
result, err := coll(nil).UpdateOne(bson.M{"_id": objID}, bson.M{"$set": set})
if err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "UpdatePayChannel", table, "UpdateOne", err),
log.Any("id", id),
log.Any("set", set),
)
return 0, err
}
return result.ModifiedCount, nil
}
// GetPayChannels 条件获取支付渠道列表
func GetPayChannels() ([]*PayChannel, error) {
opts := options.FindOptions{}
opts.SetSort(bson.D{{Key: "active", Value: -1}, {Key: "updatedAt", Value: -1}})
var back []*PayChannel
if err := coll(nil).Find(&back, bson.M{}, &opts); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetPayChannels", table, "Find", err))
return nil, err
}
return back, nil
}
// GetPayChannelsByMoney 条件获取支付渠道列表
func GetPayChannelsByMoney(money int64, payType string) ([]*PayChannel, error) {
var back []*PayChannel
if err := coll(nil).Aggregate(&back, []bson.M{
{"$match": bson.M{"payType": payType}},
{"$match": bson.M{"maxMoney": bson.M{"$gte": money}}},
{"$match": bson.M{"minMoney": bson.M{"$lte": money}}},
{"$match": bson.M{"active": true}},
}); err != nil {
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetPayChannelsByMoney", table, "Aggregate", err))
return nil, err
}
return back, nil
}
// GetPayChannelsByMoney 条件获取支付渠道列表
func GetActiveTruePayChannels(mode string) ([]PayChannel, error) {
var back []PayChannel
redisKey := redisconst.DataCachKey(table, fmt.Sprintf(rchgChansCach, mode))
redisc := getRedis()
if redisc == nil || !redisc.Exists(redisKey) {
modeSet := getModeSet(mode)
if err := coll(nil).Find(&back, bson.M{"active": true, "model_sup": bson.M{"$bitsAnySet": modeSet}}); err != nil {
log.ZapLog.Warn("recharge GetPayChannel Find fail", log.E(err))
return nil, err
}
if redisc == nil {
return back, nil
}
jsonBytes, err := json.Marshal(back)
if err != nil {
return back, err
}
_ = redisc.Set(redisKey, string(jsonBytes), redisconst.DataCachExpire)
return back, nil
}
str, err := redisc.Get(redisKey)
if err != nil {
return back, err
}
if str == nil {
return back, errors.New("redis key is null")
}
return back, json.Unmarshal([]byte(*str), &back)
}
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
}
+77
View File
@@ -0,0 +1,77 @@
package rchgchanmod
import (
"time"
"91porn-server/common/constant"
"91porn-server/common/db"
"go.mongodb.org/mongo-driver/bson/primitive"
)
var mdb *db.MongoDB
type CATTEGORY string
const (
CATTEGORY_FIXED CATTEGORY = "fixed" //固定
CATTEGORY_ACTIVE CATTEGORY = "active" //活动
)
// PayChannel 支付渠道
type PayChannel struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
ChannelName string `json:"channelName" bson:"channelName"` //支付渠道名字
CID string `json:"cid" bson:"cid"` //渠道id
PayType string `json:"payType" bson:"payType"` //支付方式
MinMoney int `json:"minMoney" bson:"minMoney,omitempty"` //支持最小支付金额
MaxMoney int `json:"maxMoney" bson:"maxMoney,omitempty"` //支持最大支付金额
Weight int `json:"weight" bson:"weight"` //权重
Active bool `json:"active" bson:"active"` //是否激活
Rate string `json:"rate" bson:"rate"` //渠道费率
ActivePeriod string `json:"activePeriod" bson:"activePeriod"` //激活时间段 6-23,7-5
Category CATTEGORY `json:"category" bson:"category"` //金额类别 固定 fixed 活动 active
AmountTypes []int64 `json:"amountTypes" bson:"amountTypes,omitempty"` //金额种类
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"` //渠道类型 鲨鱼 金鱼
}
func Init() {
mdb = db.Init(table)
initIndex()
}
const (
_ int = iota
modelSup_URL
modelSup_SDK
)
type modelSet int64
func getModelBit(mode uint) int64 {
return int64(1 << (mode - 1))
}
func (this *modelSet) setMode(model int) {
temp := getModelBit(uint(model))
*this |= modelSet(temp)
}
func getModeSet(mode string) modelSet {
var modeSet modelSet = 0
if mode == "" {
modeSet.setMode(modelSup_URL)
}
if mode == constant.RCHG_Mode_SDK {
modeSet.setMode(modelSup_URL)
modeSet.setMode(modelSup_SDK)
}
temp := getModelBit(uint(modeSet))
modeSet |= modelSet(temp)
return modeSet
}
+51
View File
@@ -0,0 +1,51 @@
package rchgchanmod
import "time"
// ChannelReq 新增支付渠道
type ChannelReq struct {
ChannelName string `form:"channelName" json:"channelName"` //支付渠道名字
CID string `form:"cid" json:"cid"` //渠道id
PayType string `form:"payType" json:"payType"` //支付方式
MinMoney int `form:"minMoney,omitempty" json:"minMoney,omitempty"` //支持最小支付金额
MaxMoney int `form:"maxMoney,omitempty" json:"maxMoney,omitempty"` //支持最大支付金额
Weight int `form:"weight" json:"weight"` //权重
Active bool `json:"active" bson:"active"` //是否激活
Rate string `json:"rate" bson:"rate"` //渠道费率
ActivePeriod string `json:"activePeriod" bson:"activePeriod"` //激活时间段 6-23,7-5
Category CATTEGORY `json:"category,omitempty" bson:"category,omitempty"` //金额类别 固定 fixed 活动 active
AmountTypes []int64 `json:"amountTypes,omitempty" bson:"amountTypes,omitempty"` //金额种类
}
// EditInfo 支付渠道编辑
type EditInfo struct {
ChannelName *string `json:"channelName,omitempty" bson:"channelName,omitempty"` //支付渠道名字
CID *string `json:"cid,omitempty" bson:"cid,omitempty"` //渠道id
PayType *string `bson:"payType,omitempty" json:"payType,omitempty"` //支付方式
MinMoney *int `bson:"minMoney,omitempty" json:"minMoney,omitempty"` //支持最小支付金额
MaxMoney *int `bson:"maxMoney,omitempty" json:"maxMoney,omitempty"` //支持最大支付金额
Weight *int `bson:"weight,omitempty" json:"weight,omitempty"` //权重
Active *bool `json:"active,omitempty" bson:"active,omitempty"` //是否激活
Rate *string `json:"rate,omitempty" bson:"rate,omitempty"` //通道费率
ActivePeriod *string `json:"activePeriod,omitempty" bson:"activePeriod,omitempty"` //激活时间段 6-23,7-5
Category *CATTEGORY `json:"category,omitempty" bson:"category,omitempty"` //金额类别 固定 fixed 活动 active
AmountTypes *([]int64) `json:"amountTypes,omitempty" bson:"amountTypes,omitempty"` //金额种类
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
}
// EditReq 渠道编辑请求
type EditReq struct {
ID string `form:"id" json:"id"`
EditInfo
}
// DelReq 删除请求
type DelReq struct {
IDs []string `form:"ids" json:"ids"`
}
// OpeResp 操作应答
type OpeResp struct {
Count int64 `json:"count"`
}