修复货币精度问题

This commit is contained in:
aozhiwei 2024-08-23 17:19:55 +08:00
parent 993bc9bbe7
commit be3ec0ef5c
2 changed files with 12 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import (
"q5" "q5"
"strings" "strings"
"math/big"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -165,8 +166,13 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
} }
} }
srcPrice := q5.ToInt64(goodsMeta.GetPrice()) * q5.ToInt64(goodsNum) srcPrice := q5.ToInt64(goodsMeta.GetPrice()) * q5.ToInt64(goodsNum)
price := q5.PowInt64(10, currencyMeta.GetCurrencyDecimal()) * srcPrice bnPrice := big.NewInt(0)
if price <= 0 || price < q5.ToInt64(goodsMeta.GetPrice()) { {
var i, e = big.NewInt(10), big.NewInt(currencyMeta.GetCurrencyDecimal())
i.Exp(i, e, nil)
bnPrice = i.Mul(i, big.NewInt(srcPrice))
}
if bnPrice.Cmp(big.NewInt(0)) < 0 || bnPrice.Cmp(big.NewInt(q5.ToInt64(goodsMeta.GetPrice()))) < 0 {
f5.RspErr(c, 3, "server internal error") f5.RspErr(c, 3, "server internal error")
return return
} }
@ -184,7 +190,7 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
"order_id": orderId, "order_id": orderId,
"account_address": accountAddress, "account_address": accountAddress,
"passport_address": passportAddress, "passport_address": passportAddress,
"amount": q5.ToString(price), "amount": bnPrice.String(),
"currency_name": currencyContractMeta.GetName(), "currency_name": currencyContractMeta.GetName(),
"currency_address": currencyContractMeta.GetAddress(), "currency_address": currencyContractMeta.GetAddress(),
} }
@ -223,7 +229,7 @@ func (this *RechargeApi) internalBuy(c *gin.Context,
currencyContractMeta.GetAddress(), currencyContractMeta.GetAddress(),
goodsMeta.GetId(), goodsMeta.GetId(),
itemNum, itemNum,
price, bnPrice.String(),
srcPrice, srcPrice,
diamond, diamond,
presentDiamond, presentDiamond,

View File

@ -10,7 +10,7 @@ import (
func AddRechargeOrder(orderId string, shortOrderId string, func AddRechargeOrder(orderId string, shortOrderId string,
netId int32, accountAddress string, passportAddress string, netId int32, accountAddress string, passportAddress string,
currencyAddress string, currencyName string, itemId int32, itemNum int32, currencyAddress string, currencyName string, itemId int32, itemNum int32,
price int64, srcPrice int64, diamond int64, presentDiamond int64, email string) bool { price string, srcPrice int64, diamond int64, presentDiamond int64, email string) bool {
ok := false ok := false
nowTime := f5.GetApp().GetRealSeconds() nowTime := f5.GetApp().GetRealSeconds()
fields := [][]string{ fields := [][]string{
@ -23,7 +23,7 @@ func AddRechargeOrder(orderId string, shortOrderId string,
{"currency_address", currencyAddress}, {"currency_address", currencyAddress},
{"item_id", q5.ToString(itemId)}, {"item_id", q5.ToString(itemId)},
{"item_num", q5.ToString(itemNum)}, {"item_num", q5.ToString(itemNum)},
{"price", q5.ToString(price)}, {"price", price},
{"diamond", q5.ToString(diamond)}, {"diamond", q5.ToString(diamond)},
{"present_diamond", q5.ToString(presentDiamond)}, {"present_diamond", q5.ToString(presentDiamond)},
{"return_contribution", q5.ToString(srcPrice * 1)}, {"return_contribution", q5.ToString(srcPrice * 1)},