This commit is contained in:
aozhiwei 2024-08-07 14:30:48 +08:00
parent a9fa18e747
commit 4b9489d0b9
3 changed files with 25 additions and 12 deletions

View File

@ -53,7 +53,20 @@ func (this *RechargeApi) Buy(c *gin.Context) {
f5.RspErr(c, 1, err.Error()) f5.RspErr(c, 1, err.Error())
return return
} }
currencyContractMeta := mt.Table.Contract.GetByNetIdName(reqJson.NetId, "TestToken") currencyMeta := mt.Table.RechargeCurrency.Get()
if currencyMeta == nil {
f5.RspErr(c, 2, "server internal error")
return
}
if currencyMeta.GetExchangeRate() <= 0 || currencyMeta.GetExchangeRate() > 1000 {
f5.RspErr(c, 2, "server internal error")
return
}
if currencyMeta.GetCurrencyDecimal() <= 0 || currencyMeta.GetCurrencyDecimal() > 10 {
f5.RspErr(c, 2, "server internal error")
return
}
currencyContractMeta := mt.Table.Contract.GetByNetIdName(reqJson.NetId, currencyMeta.GetCurrencyName())
if currencyContractMeta == nil { if currencyContractMeta == nil {
f5.RspErr(c, 2, "server internal error") f5.RspErr(c, 2, "server internal error")
return return
@ -88,7 +101,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
return return
} }
} }
price := "1" price := currencyMeta.GetCurrencyDecimal() * q5.ToInt64(reqJson.Num)
params := map[string]string{ params := map[string]string{
"c": "BcService", "c": "BcService",
"a": "recharge", "a": "recharge",
@ -96,7 +109,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
"order_id": orderId, "order_id": orderId,
"account_address": reqJson.AccountAddress, "account_address": reqJson.AccountAddress,
"passport_address": passportAddress, "passport_address": passportAddress,
"amount": price, "amount": q5.ToString(price),
"currency_name": currencyContractMeta.GetName(), "currency_name": currencyContractMeta.GetName(),
"currency_address": currencyContractMeta.GetAddress(), "currency_address": currencyContractMeta.GetAddress(),
} }
@ -105,8 +118,8 @@ func (this *RechargeApi) Buy(c *gin.Context) {
ErrMsg string `json:"errmsg"` ErrMsg string `json:"errmsg"`
Calls []jccommon.ContractCall `json:"calls"` Calls []jccommon.ContractCall `json:"calls"`
}{} }{}
var itemNum int32 = 1 var itemNum int32 = reqJson.Num
var diamond int64 = 1 var diamond int64 = currencyMeta.GetExchangeRate() * int64(1)
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3SignCluster.RandElement().GetUrl()) url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Web3SignCluster.RandElement().GetUrl())
f5.GetHttpCliMgr().SendGoStyleRequest( f5.GetHttpCliMgr().SendGoStyleRequest(
url, url,
@ -134,7 +147,7 @@ func (this *RechargeApi) Buy(c *gin.Context) {
currencyContractMeta.GetAddress(), currencyContractMeta.GetAddress(),
goodsMeta.GetId(), goodsMeta.GetId(),
itemNum, itemNum,
price, q5.ToString(price),
diamond) { diamond) {
f5.RspErr(c, 500, "server internal error") f5.RspErr(c, 500, "server internal error")
return return

View File

@ -62,8 +62,8 @@ type Config struct {
type RechargeCurrency struct { type RechargeCurrency struct {
currency_name string currency_name string
exchange_rate int32 exchange_rate int64
currency_decimal int32 currency_decimal int64
_flags1_ uint64 _flags1_ uint64
_flags2_ uint64 _flags2_ uint64
@ -330,7 +330,7 @@ func (this *RechargeCurrency) HasCurrencyName() bool {
return (this._flags1_ & (uint64(1) << 1)) > 0 return (this._flags1_ & (uint64(1) << 1)) > 0
} }
func (this *RechargeCurrency) GetExchangeRate() int32 { func (this *RechargeCurrency) GetExchangeRate() int64 {
return this.exchange_rate return this.exchange_rate
} }
@ -338,7 +338,7 @@ func (this *RechargeCurrency) HasExchangeRate() bool {
return (this._flags1_ & (uint64(1) << 2)) > 0 return (this._flags1_ & (uint64(1) << 2)) > 0
} }
func (this *RechargeCurrency) GetCurrencyDecimal() int32 { func (this *RechargeCurrency) GetCurrencyDecimal() int64 {
return this.currency_decimal return this.currency_decimal
} }

View File

@ -51,8 +51,8 @@ message Config
message RechargeCurrency message RechargeCurrency
{ {
optional string currency_name = 1; optional string currency_name = 1;
optional int32 exchange_rate = 2; optional int64 exchange_rate = 2;
optional int32 currency_decimal = 3; optional int64 currency_decimal = 3;
} }
message Item message Item