refactor: Update topup amount type from int to int64 for improved precision
This commit is contained in:
@@ -19,13 +19,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type EpayRequest struct {
|
type EpayRequest struct {
|
||||||
Amount int `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
PaymentMethod string `json:"payment_method"`
|
PaymentMethod string `json:"payment_method"`
|
||||||
TopUpCode string `json:"top_up_code"`
|
TopUpCode string `json:"top_up_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AmountRequest struct {
|
type AmountRequest struct {
|
||||||
Amount int `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
TopUpCode string `json:"top_up_code"`
|
TopUpCode string `json:"top_up_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,8 +43,8 @@ func GetEpayClient() *epay.Client {
|
|||||||
return withUrl
|
return withUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPayMoney(amount float64, group string) float64 {
|
func getPayMoney(amount int64, group string) float64 {
|
||||||
dAmount := decimal.NewFromFloat(amount)
|
dAmount := decimal.NewFromInt(amount)
|
||||||
|
|
||||||
if !common.DisplayInCurrencyEnabled {
|
if !common.DisplayInCurrencyEnabled {
|
||||||
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
||||||
@@ -64,14 +64,14 @@ func getPayMoney(amount float64, group string) float64 {
|
|||||||
return payMoney.InexactFloat64()
|
return payMoney.InexactFloat64()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMinTopup() int {
|
func getMinTopup() int64 {
|
||||||
minTopup := setting.MinTopUp
|
minTopup := setting.MinTopUp
|
||||||
if !common.DisplayInCurrencyEnabled {
|
if !common.DisplayInCurrencyEnabled {
|
||||||
dMinTopup := decimal.NewFromInt(int64(minTopup))
|
dMinTopup := decimal.NewFromInt(int64(minTopup))
|
||||||
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
||||||
minTopup = int(dMinTopup.Mul(dQuotaPerUnit).IntPart())
|
minTopup = int(dMinTopup.Mul(dQuotaPerUnit).IntPart())
|
||||||
}
|
}
|
||||||
return minTopup
|
return int64(minTopup)
|
||||||
}
|
}
|
||||||
|
|
||||||
func RequestEpay(c *gin.Context) {
|
func RequestEpay(c *gin.Context) {
|
||||||
@@ -92,7 +92,7 @@ func RequestEpay(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
payMoney := getPayMoney(float64(req.Amount), group)
|
payMoney := getPayMoney(req.Amount, group)
|
||||||
if payMoney < 0.01 {
|
if payMoney < 0.01 {
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
||||||
return
|
return
|
||||||
@@ -132,7 +132,7 @@ func RequestEpay(c *gin.Context) {
|
|||||||
if !common.DisplayInCurrencyEnabled {
|
if !common.DisplayInCurrencyEnabled {
|
||||||
dAmount := decimal.NewFromInt(int64(amount))
|
dAmount := decimal.NewFromInt(int64(amount))
|
||||||
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
dQuotaPerUnit := decimal.NewFromFloat(common.QuotaPerUnit)
|
||||||
amount = int(dAmount.Div(dQuotaPerUnit).IntPart())
|
amount = dAmount.Div(dQuotaPerUnit).IntPart()
|
||||||
}
|
}
|
||||||
topUp := &model.TopUp{
|
topUp := &model.TopUp{
|
||||||
UserId: id,
|
UserId: id,
|
||||||
@@ -258,7 +258,7 @@ func RequestAmount(c *gin.Context) {
|
|||||||
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
c.JSON(200, gin.H{"message": "error", "data": "获取用户分组失败"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
payMoney := getPayMoney(float64(req.Amount), group)
|
payMoney := getPayMoney(req.Amount, group)
|
||||||
if payMoney <= 0.01 {
|
if payMoney <= 0.01 {
|
||||||
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package model
|
|||||||
type TopUp struct {
|
type TopUp struct {
|
||||||
Id int `json:"id"`
|
Id int `json:"id"`
|
||||||
UserId int `json:"user_id" gorm:"index"`
|
UserId int `json:"user_id" gorm:"index"`
|
||||||
Amount int `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
Money float64 `json:"money"`
|
Money float64 `json:"money"`
|
||||||
TradeNo string `json:"trade_no"`
|
TradeNo string `json:"trade_no"`
|
||||||
CreateTime int64 `json:"create_time"`
|
CreateTime int64 `json:"create_time"`
|
||||||
|
|||||||
Reference in New Issue
Block a user