Files
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

52 lines
1.4 KiB
Go

package currencyser
import (
"fmt"
"strconv"
"91porn-server/common/db"
"91porn-server/common/log"
"91porn-server/models/v/currencymod"
"91porn-server/models/v/rchgordmod"
"91porn-server/models/v/txnmod"
"91porn-server/models/v/walletmod"
)
func BuyGold(r rchgordmod.RechargeOrder, payMoney int64) (func(*db.MongoTool) error, error) {
var gold = payMoney / 10
// 查询金币配置
currency, err := currencymod.Get(r.ProductID)
if err != nil {
log.Error(fmt.Sprintf("充值金币-产品ID[%v]查询异常[%v]", r.ProductID, err))
return nil, err
}
if currency.ID.IsZero() {
log.Error(fmt.Sprintf("充值金币-产品ID[%v]不存在", r.ProductID))
return nil, fmt.Errorf("充值金币-产品ID[%v]不存在", r.ProductID)
}
if currency.GiveGold > 0 {
gold += currency.GiveGold
}
return func(t *db.MongoTool) error {
w, err := walletmod.Credit(t, walletmod.CreditPlan{
Amount: &gold,
Consumption: &payMoney,
}, r.UID)
if err != nil {
return err
}
return txnmod.InsertTransactionLog(t, &txnmod.TransactionLog{
TransNo: r.ID,
UID: r.UID,
FruitCoin: gold,
TranType: txnmod.FruitCoinRecharge.Key(),
TranTypeInt: int64(txnmod.FruitCoinRecharge),
ChannelType: r.RechargeType,
Desc: "官方充值-到账" + strconv.FormatInt(gold, 10) + "金币",
DiscDoc: r.DiscDoc,
SysType: r.DevType,
RealAmount: w.RealAmount(),
})
}, nil
}