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
f5dd4ea2
authored
Apr 04, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 钱包兼容非货币形式显示额度
parent
b0dcea7e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
33 deletions
+73
-33
controller/topup.go
+30
-10
web/src/components/SystemSetting.js
+1
-1
web/src/helpers/render.js
+26
-5
web/src/pages/TopUp/index.js
+16
-17
No files found.
controller/topup.go
View file @
f5dd4ea2
...
...
@@ -40,31 +40,46 @@ func GetEpayClient() *epay.Client {
return
withUrl
}
func
GetAmount
(
count
float64
,
user
model
.
User
)
float64
{
func
getPayMoney
(
amount
float64
,
user
model
.
User
)
float64
{
if
!
common
.
DisplayInCurrencyEnabled
{
amount
=
amount
/
common
.
QuotaPerUnit
}
// 别问为什么用float64,问就是这么点钱没必要
topupGroupRatio
:=
common
.
GetTopupGroupRatio
(
user
.
Group
)
if
topupGroupRatio
==
0
{
topupGroupRatio
=
1
}
amount
:=
count
*
common
.
Price
*
topupGroupRatio
return
amount
payMoney
:=
amount
*
common
.
Price
*
topupGroupRatio
return
payMoney
}
func
getMinTopup
()
int
{
minTopup
:=
common
.
MinTopUp
if
!
common
.
DisplayInCurrencyEnabled
{
minTopup
=
minTopup
*
int
(
common
.
QuotaPerUnit
)
}
return
minTopup
}
func
RequestEpay
(
c
*
gin
.
Context
)
{
var
req
EpayRequest
err
:=
c
.
ShouldBindJSON
(
&
req
)
if
err
!=
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
err
.
Error
(),
"data"
:
10
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"参数错误"
})
return
}
if
req
.
Amount
<
common
.
MinTopUp
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
common
.
MinTopUp
),
"data"
:
10
})
if
req
.
Amount
<
getMinTopup
()
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
getMinTopup
())
})
return
}
id
:=
c
.
GetInt
(
"id"
)
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
payMoney
:=
GetAmount
(
float64
(
req
.
Amount
),
*
user
)
payMoney
:=
getPayMoney
(
float64
(
req
.
Amount
),
*
user
)
if
payMoney
<
0.01
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额过低"
})
return
}
var
payType
epay
.
PurchaseType
if
req
.
PaymentMethod
==
"zfb"
{
...
...
@@ -206,12 +221,17 @@ func RequestAmount(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"参数错误"
})
return
}
if
req
.
Amount
<
common
.
MinTopUp
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
common
.
MinTopUp
)})
if
req
.
Amount
<
getMinTopup
()
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
getMinTopup
())})
return
}
id
:=
c
.
GetInt
(
"id"
)
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
payMoney
:=
GetAmount
(
float64
(
req
.
Amount
),
*
user
)
payMoney
:=
getPayMoney
(
float64
(
req
.
Amount
),
*
user
)
if
payMoney
<=
0.01
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额过低"
})
return
}
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"success"
,
"data"
:
strconv
.
FormatFloat
(
payMoney
,
'f'
,
2
,
64
)})
}
web/src/components/SystemSetting.js
View file @
f5dd4ea2
...
...
@@ -362,7 +362,7 @@ const SystemSetting = () => {
onChange
=
{
handleInputChange
}
/
>
<
Form
.
Input
label
=
'最低充值
数量
'
label
=
'最低充值
美元数量(以美金为单位,如果使用额度请自行换算!)
'
placeholder
=
'例如:2,就是最低充值2$'
value
=
{
inputs
.
MinTopUp
}
name
=
'MinTopUp'
...
...
web/src/helpers/render.js
View file @
f5dd4ea2
...
...
@@ -15,14 +15,18 @@ export function renderText(text, limit) {
*/
export
function
renderGroup
(
group
)
{
if
(
group
===
''
)
{
return
<
Tag
size
=
'large'
key
=
'default'
>
default
<
/Tag>
;
return
(
<
Tag
size
=
'large'
key
=
'default'
>
default
<
/Tag
>
);
}
const
tagColors
=
{
'vip'
:
'yellow'
,
'pro'
:
'yellow'
,
'svip'
:
'red'
,
'premium'
:
'red'
vip
:
'yellow'
,
pro
:
'yellow'
,
svip
:
'red'
,
premium
:
'red'
,
};
const
groups
=
group
.
split
(
','
).
sort
();
...
...
@@ -97,12 +101,29 @@ export function getQuotaPerUnit() {
return
quotaPerUnit
;
}
export
function
renderUnitWithQuota
(
quota
)
{
let
quotaPerUnit
=
localStorage
.
getItem
(
'quota_per_unit'
);
quotaPerUnit
=
parseFloat
(
quotaPerUnit
);
quota
=
parseFloat
(
quota
);
return
quotaPerUnit
*
quota
;
}
export
function
getQuotaWithUnit
(
quota
,
digits
=
6
)
{
let
quotaPerUnit
=
localStorage
.
getItem
(
'quota_per_unit'
);
quotaPerUnit
=
parseFloat
(
quotaPerUnit
);
return
(
quota
/
quotaPerUnit
).
toFixed
(
digits
);
}
export
function
renderQuotaWithAmount
(
amount
)
{
let
displayInCurrency
=
localStorage
.
getItem
(
'display_in_currency'
);
displayInCurrency
=
displayInCurrency
===
'true'
;
if
(
displayInCurrency
)
{
return
'$'
+
amount
;
}
else
{
return
renderUnitWithQuota
(
amount
);
}
}
export
function
renderQuota
(
quota
,
digits
=
2
)
{
let
quotaPerUnit
=
localStorage
.
getItem
(
'quota_per_unit'
);
let
displayInCurrency
=
localStorage
.
getItem
(
'display_in_currency'
);
...
...
web/src/pages/TopUp/index.js
View file @
f5dd4ea2
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
API
,
isMobile
,
showError
,
showInfo
,
showSuccess
}
from
'../../helpers'
;
import
{
renderNumber
,
renderQuota
}
from
'../../helpers/render'
;
import
{
renderNumber
,
renderQuota
,
renderQuotaWithAmount
,
}
from
'../../helpers/render'
;
import
{
Col
,
Layout
,
...
...
@@ -12,6 +16,7 @@ import {
Divider
,
Space
,
Modal
,
Toast
,
}
from
'@douyinfe/semi-ui'
;
import
Title
from
'@douyinfe/semi-ui/lib/es/typography/title'
;
import
Text
from
'@douyinfe/semi-ui/lib/es/typography/text'
;
...
...
@@ -20,7 +25,7 @@ import { Link } from 'react-router-dom';
const
TopUp
=
()
=>
{
const
[
redemptionCode
,
setRedemptionCode
]
=
useState
(
''
);
const
[
topUpCode
,
setTopUpCode
]
=
useState
(
''
);
const
[
topUpCount
,
setTopUpCount
]
=
useState
(
1
0
);
const
[
topUpCount
,
setTopUpCount
]
=
useState
(
0
);
const
[
minTopupCount
,
setMinTopUpCount
]
=
useState
(
1
);
const
[
amount
,
setAmount
]
=
useState
(
0.0
);
const
[
minTopUp
,
setMinTopUp
]
=
useState
(
1
);
...
...
@@ -76,11 +81,9 @@ const TopUp = () => {
showError
(
'管理员未开启在线充值!'
);
return
;
}
if
(
amount
===
0
)
{
await
getAmount
();
}
await
getAmount
();
if
(
topUpCount
<
minTopUp
)
{
show
Info
(
'充值数量不能小于'
+
minTopUp
);
show
Error
(
'充值数量不能小于'
+
minTopUp
);
return
;
}
setPayWay
(
payment
);
...
...
@@ -92,7 +95,7 @@ const TopUp = () => {
await
getAmount
();
}
if
(
topUpCount
<
minTopUp
)
{
show
Info
(
'充值数量不能小于'
+
minTopUp
);
show
Error
(
'充值数量不能小于'
+
minTopUp
);
return
;
}
setOpen
(
false
);
...
...
@@ -189,7 +192,8 @@ const TopUp = () => {
if
(
message
===
'success'
)
{
setAmount
(
parseFloat
(
data
));
}
else
{
showError
(
data
);
setAmount
(
0
);
Toast
.
error
({
content
:
'错误:'
+
data
,
id
:
'getAmount'
});
// setTopUpCount(parseInt(res.data.count));
// setAmount(parseInt(data));
}
...
...
@@ -222,7 +226,7 @@ const TopUp = () => {
size
=
{
'small'
}
centered
=
{
true
}
>
<
p
>
充值数量:
{
topUpCount
}
$
<
/p
>
<
p
>
充值数量:
{
topUpCount
}
<
/p
>
<
p
>
实付金额:
{
renderAmount
()}
<
/p
>
<
p
>
是否确认充值?
<
/p
>
<
/Modal
>
...
...
@@ -274,21 +278,16 @@ const TopUp = () => {
disabled
=
{
!
enableOnlineTopUp
}
field
=
{
'redemptionCount'
}
label
=
{
'实付金额:'
+
renderAmount
()}
placeholder
=
{
'充值数量,最低'
+
minTopUp
+
'$'
}
placeholder
=
{
'充值数量,最低 '
+
renderQuotaWithAmount
(
minTopUp
)
}
name
=
'redemptionCount'
type
=
{
'number'
}
value
=
{
topUpCount
}
suffix
=
{
'$'
}
min
=
{
minTopUp
}
defaultValue
=
{
minTopUp
}
max
=
{
100000
}
onChange
=
{
async
(
value
)
=>
{
if
(
value
<
1
)
{
value
=
1
;
}
if
(
value
>
100000
)
{
value
=
100000
;
}
setTopUpCount
(
value
);
await
getAmount
(
value
);
}}
...
...
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