Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a92d9b12
authored
Mar 08, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Update topup amount type from int to int64 for improved precision
parent
0876bc3f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
controller/topup.go
+9
-9
model/topup.go
+1
-1
No files found.
controller/topup.go
View file @
a92d9b12
...
...
@@ -19,13 +19,13 @@ import (
)
type
EpayRequest
struct
{
Amount
int
`json:"amount"`
Amount
int
64
`json:"amount"`
PaymentMethod
string
`json:"payment_method"`
TopUpCode
string
`json:"top_up_code"`
}
type
AmountRequest
struct
{
Amount
int
`json:"amount"`
Amount
int
64
`json:"amount"`
TopUpCode
string
`json:"top_up_code"`
}
...
...
@@ -43,8 +43,8 @@ func GetEpayClient() *epay.Client {
return
withUrl
}
func
getPayMoney
(
amount
floa
t64
,
group
string
)
float64
{
dAmount
:=
decimal
.
NewFrom
Floa
t
(
amount
)
func
getPayMoney
(
amount
in
t64
,
group
string
)
float64
{
dAmount
:=
decimal
.
NewFrom
In
t
(
amount
)
if
!
common
.
DisplayInCurrencyEnabled
{
dQuotaPerUnit
:=
decimal
.
NewFromFloat
(
common
.
QuotaPerUnit
)
...
...
@@ -64,14 +64,14 @@ func getPayMoney(amount float64, group string) float64 {
return
payMoney
.
InexactFloat64
()
}
func
getMinTopup
()
int
{
func
getMinTopup
()
int
64
{
minTopup
:=
setting
.
MinTopUp
if
!
common
.
DisplayInCurrencyEnabled
{
dMinTopup
:=
decimal
.
NewFromInt
(
int64
(
minTopup
))
dQuotaPerUnit
:=
decimal
.
NewFromFloat
(
common
.
QuotaPerUnit
)
minTopup
=
int
(
dMinTopup
.
Mul
(
dQuotaPerUnit
)
.
IntPart
())
}
return
minTopup
return
int64
(
minTopup
)
}
func
RequestEpay
(
c
*
gin
.
Context
)
{
...
...
@@ -92,7 +92,7 @@ func RequestEpay(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"获取用户分组失败"
})
return
}
payMoney
:=
getPayMoney
(
float64
(
req
.
Amount
)
,
group
)
payMoney
:=
getPayMoney
(
req
.
Amount
,
group
)
if
payMoney
<
0.01
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额过低"
})
return
...
...
@@ -132,7 +132,7 @@ func RequestEpay(c *gin.Context) {
if
!
common
.
DisplayInCurrencyEnabled
{
dAmount
:=
decimal
.
NewFromInt
(
int64
(
amount
))
dQuotaPerUnit
:=
decimal
.
NewFromFloat
(
common
.
QuotaPerUnit
)
amount
=
int
(
dAmount
.
Div
(
dQuotaPerUnit
)
.
IntPart
()
)
amount
=
dAmount
.
Div
(
dQuotaPerUnit
)
.
IntPart
(
)
}
topUp
:=
&
model
.
TopUp
{
UserId
:
id
,
...
...
@@ -258,7 +258,7 @@ func RequestAmount(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"获取用户分组失败"
})
return
}
payMoney
:=
getPayMoney
(
float64
(
req
.
Amount
)
,
group
)
payMoney
:=
getPayMoney
(
req
.
Amount
,
group
)
if
payMoney
<=
0.01
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额过低"
})
return
...
...
model/topup.go
View file @
a92d9b12
...
...
@@ -3,7 +3,7 @@ package model
type
TopUp
struct
{
Id
int
`json:"id"`
UserId
int
`json:"user_id" gorm:"index"`
Amount
int
`json:"amount"`
Amount
int
64
`json:"amount"`
Money
float64
`json:"money"`
TradeNo
string
`json:"trade_no"`
CreateTime
int64
`json:"create_time"`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment