This commit is contained in:
aozhiwei 2024-08-17 10:41:53 +08:00
parent b32267d897
commit 21c247106c
3 changed files with 33 additions and 25 deletions

View File

@ -318,6 +318,7 @@ func (this *MailApi) DelMail(c *gin.Context) {
} }
func (this *MailApi) CheckAttachment(list []common.Attachment, c *gin.Context) bool { func (this *MailApi) CheckAttachment(list []common.Attachment, c *gin.Context) bool {
return true
if data, err := json.Marshal(list); err != nil || len(data) > 0xFF { if data, err := json.Marshal(list); err != nil || len(data) > 0xFF {
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"code": 2, "code": 2,

View File

@ -30,7 +30,7 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
}{} }{}
currencysMeta := mt.Table.Currency.GetByNetId(netId) currencysMeta := mt.Table.Currency.GetByNetId(netId)
if len(currencysMeta) <= 0 { if currencysMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
} }
@ -57,11 +57,14 @@ func (ea *RechargeApi) RechargeList(c *gin.Context) {
Name string `json:"name"` Name string `json:"name"`
Address string `json:"address"` Address string `json:"address"`
}{} }{}
for _, currency := range currencysMeta { currencysMeta.Range(
p := q5.NewSliceElement(&currencyList) func (key string, val *mt.Currency) bool {
p.Name = currency.GetCurrencyName() currency := val
p.Address = currency.GetContract().GetAddress() p := q5.NewSliceElement(&currencyList)
} p.Name = currency.GetCurrencyName()
p.Address = currency.GetContract().GetAddress()
return true
})
tmpmap["currency_list"] = currencyList tmpmap["currency_list"] = currencyList
rspObj.Rows = append(rspObj.Rows, tmpmap) rspObj.Rows = append(rspObj.Rows, tmpmap)

View File

@ -16,7 +16,7 @@ type Currency struct {
type CurrencyTable struct { type CurrencyTable struct {
f5.CustomMetaTable f5.CustomMetaTable
netIdHash *q5.ConcurrentMap[int32, *Currency] netIdHash *q5.ConcurrentMap[int32, *q5.ConcurrentMap[string, *Currency]]
} }
func (this *Currency) init(currencyName string, exchangeRate int64, currencyDecimal int64) { func (this *Currency) init(currencyName string, exchangeRate int64, currencyDecimal int64) {
@ -60,11 +60,11 @@ func (this *Currency) check() {
} }
} }
func (this *CurrencyTable) GetByNetId(netId int32) []*Currency { func (this *CurrencyTable) GetByNetId(netId int32) *q5.ConcurrentMap[string, *Currency] {
if v, ok := this.netIdHash.Load(netId); ok { if v, ok := this.netIdHash.Load(netId); ok {
return []*Currency{*v} return *v
} else { } else {
return []*Currency{} return nil
} }
} }
@ -73,7 +73,7 @@ func (this *CurrencyTable) GetByNetIdAddress(netId int32, currencyAddress string
} }
func (this *CurrencyTable) Load() { func (this *CurrencyTable) Load() {
this.netIdHash = new(q5.ConcurrentMap[int32, *Currency]) this.netIdHash = new(q5.ConcurrentMap[int32, *q5.ConcurrentMap[string, *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 {
@ -101,7 +101,7 @@ func (this *CurrencyTable) Load() {
p := new(Currency) 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)
} }
} }
} }
@ -109,20 +109,24 @@ func (this *CurrencyTable) Load() {
func (this *CurrencyTable) PostInit1() { func (this *CurrencyTable) PostInit1() {
this.netIdHash.Range( this.netIdHash.Range(
func (key int32, val *Currency) bool { func (key int32, val *q5.ConcurrentMap[string, *Currency]) bool {
netId := key netId := key
currencyMeta := val val.Range(
Table.Recharge.Traverse(func(ele *Recharge) bool { func (key2 string, val2 *Currency) bool {
if int64(ele.GetPrice()) * currencyMeta.GetExchangeRate() != int64(ele.GetDiamond()) { currencyMeta := val2
panic(fmt.Sprintf("Currency verifyerror net_id:%d id:%d", netId, ele.GetId())) Table.Recharge.Traverse(func(ele *Recharge) bool {
} if int64(ele.GetPrice()) * currencyMeta.GetExchangeRate() != int64(ele.GetDiamond()) {
return true panic(fmt.Sprintf("Currency verifyerror net_id:%d id:%d", netId, ele.GetId()))
}) }
contractMeta := Table.Contract.GetByNetIdName(netId, currencyMeta.GetCurrencyName()) return true
if contractMeta == nil { })
panic(fmt.Sprintf("currency contract not found")) contractMeta := Table.Contract.GetByNetIdName(netId, currencyMeta.GetCurrencyName())
} if contractMeta == nil {
currencyMeta.contract = contractMeta panic(fmt.Sprintf("currency contract not found"))
}
currencyMeta.contract = contractMeta
return true
});
return true return true
}) })
} }