This commit is contained in:
aozhiwei 2024-08-08 09:50:27 +08:00
parent 91c45259b5
commit 01add69d2c
3 changed files with 23 additions and 23 deletions

View File

@ -27,7 +27,7 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
Rows []interface{} `json:"rows"` Rows []interface{} `json:"rows"`
}{} }{}
currencyMeta := mt.Table.RechargeCurrency.Get(netId) currencyMeta := mt.Table.Currency.Get(netId)
if currencyMeta == nil { if currencyMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
@ -60,7 +60,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
f5.RspErr(c, 1, err.Error()) f5.RspErr(c, 1, err.Error())
return return
} }
currencyMeta := mt.Table.RechargeCurrency.Get(reqJson.NetId) currencyMeta := mt.Table.Currency.Get(reqJson.NetId)
if currencyMeta == nil { if currencyMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return

View File

@ -7,55 +7,55 @@ import (
"main/constant" "main/constant"
) )
type RechargeCurrency struct { type Currency struct {
currencyName string currencyName string
exchangeRate int64 exchangeRate int64
currencyDecimal int64 currencyDecimal int64
} }
type RechargeCurrencyTable struct { type CurrencyTable struct {
f5.CustomMetaTable f5.CustomMetaTable
netIdHash *q5.ConcurrentMap[int32, *RechargeCurrency] netIdHash *q5.ConcurrentMap[int32, *Currency]
} }
func (this *RechargeCurrency) init(currencyName string, exchangeRate int64, currencyDecimal int64) { func (this *Currency) init(currencyName string, exchangeRate int64, currencyDecimal int64) {
this.currencyName = currencyName this.currencyName = currencyName
this.exchangeRate = exchangeRate this.exchangeRate = exchangeRate
this.currencyDecimal = currencyDecimal this.currencyDecimal = currencyDecimal
} }
func (this *RechargeCurrency) GetCurrencyName() string { func (this *Currency) GetCurrencyName() string {
return this.currencyName return this.currencyName
} }
func (this *RechargeCurrency) GetExchangeRate() int64 { func (this *Currency) GetExchangeRate() int64 {
return this.exchangeRate return this.exchangeRate
} }
func (this *RechargeCurrency) GetCurrencyDecimal() int64 { func (this *Currency) GetCurrencyDecimal() int64 {
return this.currencyDecimal return this.currencyDecimal
} }
func (this *RechargeCurrency) check() { func (this *Currency) check() {
if this.GetExchangeRate() <= 0 { if this.GetExchangeRate() <= 0 {
panic("RechargeCurrency exchange_rate <= 0") panic("Currency exchange_rate <= 0")
return return
} }
if this.GetExchangeRate() != constant.RECHARGE_CURRENCY_MAX_EXCHANGE_RAET { if this.GetExchangeRate() != constant.RECHARGE_CURRENCY_MAX_EXCHANGE_RAET {
panic("RechargeCurrency exchange_rate > uplimit") panic("Currency exchange_rate > uplimit")
return return
} }
if this.GetCurrencyDecimal() <= 0 { if this.GetCurrencyDecimal() <= 0 {
panic("RechargeCurrency currency_decimal <= 0") panic("Currency currency_decimal <= 0")
return return
} }
if this.GetCurrencyDecimal() != constant.RECHARGE_CURRENCY_MAX_DECIMAL { if this.GetCurrencyDecimal() != constant.RECHARGE_CURRENCY_MAX_DECIMAL {
panic("RechargeCurrency exchange_rate > uplimit") panic("Currency exchange_rate > uplimit")
return return
} }
} }
func (this *RechargeCurrencyTable) Get(netId int32) *RechargeCurrency { func (this *CurrencyTable) Get(netId int32) *Currency {
if v, ok := this.netIdHash.Load(netId); ok { if v, ok := this.netIdHash.Load(netId); ok {
return *v return *v
} else { } else {
@ -63,8 +63,8 @@ func (this *RechargeCurrencyTable) Get(netId int32) *RechargeCurrency {
} }
} }
func (this *RechargeCurrencyTable) Load() { func (this *CurrencyTable) Load() {
this.netIdHash = new(q5.ConcurrentMap[int32, *RechargeCurrency]) this.netIdHash = new(q5.ConcurrentMap[int32, *Currency])
nets := []int32{} nets := []int32{}
{ {
if jsonStr, err := f5.ReadJsonFile("../config/nets.json"); err == nil { if jsonStr, err := f5.ReadJsonFile("../config/nets.json"); err == nil {
@ -89,7 +89,7 @@ func (this *RechargeCurrencyTable) Load() {
if err := q5.DecodeJson(jsonStr, &currencyCfg); err != nil { if err := q5.DecodeJson(jsonStr, &currencyCfg); err != nil {
panic(fmt.Sprintf("load metafile json decode error %s %s", "currency.json", err)) panic(fmt.Sprintf("load metafile json decode error %s %s", "currency.json", err))
} }
p := new(RechargeCurrency) p := new(Currency)
p.init(currencyCfg.CurrencyName, currencyCfg.ExchangeRate, currencyCfg.CurrencyDecimal) p.init(currencyCfg.CurrencyName, currencyCfg.ExchangeRate, currencyCfg.CurrencyDecimal)
p.check() p.check()
this.netIdHash.Store(netId, p) this.netIdHash.Store(netId, p)
@ -98,14 +98,14 @@ func (this *RechargeCurrencyTable) Load() {
} }
} }
func (this *RechargeCurrencyTable) PostInit1() { func (this *CurrencyTable) PostInit1() {
this.netIdHash.Range( this.netIdHash.Range(
func (key int32, val *RechargeCurrency) bool { func (key int32, val *Currency) bool {
netId := key netId := key
currencyMeta := val currencyMeta := val
Table.Recharge.Traverse(func(ele *Recharge) bool { Table.Recharge.Traverse(func(ele *Recharge) bool {
if int64(ele.GetPrice()) * currencyMeta.GetExchangeRate() != int64(ele.GetDiamond()) { if int64(ele.GetPrice()) * currencyMeta.GetExchangeRate() != int64(ele.GetDiamond()) {
panic(fmt.Sprintf("RechargeCurrency verifyerror net_id:%d id:%d", netId, ele.GetId())) panic(fmt.Sprintf("Currency verifyerror net_id:%d id:%d", netId, ele.GetId()))
} }
return true return true
}) })

View File

@ -16,7 +16,7 @@ type table struct {
Web3ServiceCluster *Web3ServiceClusterTable Web3ServiceCluster *Web3ServiceClusterTable
Web3SignCluster *Web3SignClusterTable Web3SignCluster *Web3SignClusterTable
Recharge *RechargeTable Recharge *RechargeTable
RechargeCurrency *RechargeCurrencyTable Currency *CurrencyTable
} }
var Table = f5.New(func(this *table) { var Table = f5.New(func(this *table) {
@ -67,7 +67,7 @@ var Table = f5.New(func(this *table) {
this.PrimKey = "" this.PrimKey = ""
}) })
this.RechargeCurrency = new(RechargeCurrencyTable) this.Currency = new(CurrencyTable)
this.Recharge = f5.New(func(this *RechargeTable) { this.Recharge = f5.New(func(this *RechargeTable) {
this.FileName = "../res/recharge@recharge.json" this.FileName = "../res/recharge@recharge.json"