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
abb82a0b
authored
Oct 11, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新增充值分组倍率设置
parent
32bb9ff7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
9 deletions
+72
-9
common/topup-ratio.go
+31
-0
controller/topup.go
+12
-6
model/option.go
+3
-0
web/src/components/SystemSetting.js
+26
-3
No files found.
common/topup-ratio.go
0 → 100644
View file @
abb82a0b
package
common
import
"encoding/json"
var
TopupGroupRatio
=
map
[
string
]
float64
{
"default"
:
1
,
"vip"
:
1
,
"svip"
:
1
,
}
func
TopupGroupRatio2JSONString
()
string
{
jsonBytes
,
err
:=
json
.
Marshal
(
TopupGroupRatio
)
if
err
!=
nil
{
SysError
(
"error marshalling model ratio: "
+
err
.
Error
())
}
return
string
(
jsonBytes
)
}
func
UpdateTopupGroupRatioByJSONString
(
jsonStr
string
)
error
{
TopupGroupRatio
=
make
(
map
[
string
]
float64
)
return
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
TopupGroupRatio
)
}
func
GetTopupGroupRatio
(
name
string
)
float64
{
ratio
,
ok
:=
TopupGroupRatio
[
name
]
if
!
ok
{
SysError
(
"topup group ratio not found: "
+
name
)
return
1
}
return
ratio
}
controller/topup.go
View file @
abb82a0b
...
...
@@ -38,9 +38,13 @@ func GetEpayClient() *epay.Client {
return
withUrl
}
func
GetAmount
(
count
float64
)
float64
{
func
GetAmount
(
count
float64
,
user
model
.
User
)
float64
{
// 别问为什么用float64,问就是这么点钱没必要
amount
:=
count
*
common
.
Price
topupGroupRatio
:=
common
.
GetTopupGroupRatio
(
user
.
Group
)
if
topupGroupRatio
==
0
{
topupGroupRatio
=
1
}
amount
:=
count
*
common
.
Price
*
topupGroupRatio
return
amount
}
...
...
@@ -57,7 +61,8 @@ func RequestEpay(c *gin.Context) {
}
id
:=
c
.
GetInt
(
"id"
)
amount
:=
GetAmount
(
float64
(
req
.
Amount
))
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
amount
:=
GetAmount
(
float64
(
req
.
Amount
),
*
user
)
if
req
.
PaymentMethod
==
"zfb"
{
req
.
PaymentMethod
=
"alipay"
...
...
@@ -148,7 +153,7 @@ func EpayNotify(c *gin.Context) {
return
}
log
.
Printf
(
"易支付回调更新用户成功 %v"
,
topUp
)
model
.
RecordLog
(
topUp
.
UserId
,
model
.
LogTypeTopup
,
fmt
.
Sprintf
(
"使用在线充值成功,充值金额: %v
"
,
common
.
LogQuota
(
topUp
.
Amount
*
500000
)
))
model
.
RecordLog
(
topUp
.
UserId
,
model
.
LogTypeTopup
,
fmt
.
Sprintf
(
"使用在线充值成功,充值金额: %v
,支付金额:%d"
,
common
.
LogQuota
(
topUp
.
Amount
*
500000
),
topUp
.
Money
))
}
}
else
{
log
.
Printf
(
"易支付异常回调: %v"
,
verifyInfo
)
...
...
@@ -166,6 +171,7 @@ func RequestAmount(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额不能小于1"
})
return
}
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"success"
,
"data"
:
GetAmount
(
float64
(
req
.
Amount
))})
id
:=
c
.
GetInt
(
"id"
)
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"success"
,
"data"
:
GetAmount
(
float64
(
req
.
Amount
),
*
user
)})
}
model/option.go
View file @
abb82a0b
...
...
@@ -57,6 +57,7 @@ func InitOptionMap() {
common
.
OptionMap
[
"EpayId"
]
=
""
common
.
OptionMap
[
"EpayKey"
]
=
""
common
.
OptionMap
[
"Price"
]
=
strconv
.
FormatFloat
(
common
.
Price
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"TopupGroupRatio"
]
=
common
.
TopupGroupRatio2JSONString
()
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
common
.
OptionMap
[
"WeChatServerAddress"
]
=
""
...
...
@@ -184,6 +185,8 @@ func updateOptionMap(key string, value string) (err error) {
common
.
EpayKey
=
value
case
"Price"
:
common
.
Price
,
_
=
strconv
.
ParseFloat
(
value
,
64
)
case
"TopupGroupRatio"
:
err
=
common
.
UpdateTopupGroupRatioByJSONString
(
value
)
case
"GitHubClientId"
:
common
.
GitHubClientId
=
value
case
"GitHubClientSecret"
:
...
...
web/src/components/SystemSetting.js
View file @
abb82a0b
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Button
,
Divider
,
Form
,
Grid
,
Header
,
Modal
,
Message
}
from
'semantic-ui-react'
;
import
{
API
,
removeTrailingSlash
,
showError
}
from
'../helpers'
;
import
{
API
,
removeTrailingSlash
,
showError
,
verifyJSON
}
from
'../helpers'
;
const
SystemSetting
=
()
=>
{
let
[
inputs
,
setInputs
]
=
useState
({
...
...
@@ -20,6 +20,7 @@ const SystemSetting = () => {
EpayId
:
''
,
EpayKey
:
''
,
Price
:
7.3
,
TopupGroupRatio
:
''
,
PayAddress
:
''
,
Footer
:
''
,
WeChatAuthEnabled
:
''
,
...
...
@@ -45,6 +46,9 @@ const SystemSetting = () => {
if
(
success
)
{
let
newInputs
=
{};
data
.
forEach
((
item
)
=>
{
if
(
item
.
key
===
'TopupGroupRatio'
)
{
item
.
value
=
JSON
.
stringify
(
JSON
.
parse
(
item
.
value
),
null
,
2
);
}
newInputs
[
item
.
key
]
=
item
.
value
;
});
setInputs
({
...
...
@@ -123,7 +127,8 @@ const SystemSetting = () => {
name
===
'WeChatAccountQRCodeImageURL'
||
name
===
'TurnstileSiteKey'
||
name
===
'TurnstileSecretKey'
||
name
===
'EmailDomainWhitelist'
name
===
'EmailDomainWhitelist'
||
name
===
'TopupGroupRatio'
)
{
setInputs
((
inputs
)
=>
({...
inputs
,
[
name
]:
value
}));
}
else
{
...
...
@@ -141,6 +146,13 @@ const SystemSetting = () => {
showError
(
'请先填写服务器地址'
);
return
}
if
(
originInputs
[
'TopupGroupRatio'
]
!==
inputs
.
TopupGroupRatio
)
{
if
(
!
verifyJSON
(
inputs
.
TopupGroupRatio
))
{
showError
(
'充值分组倍率不是合法的 JSON 字符串'
);
return
;
}
await
updateOption
(
'TopupGroupRatio'
,
inputs
.
TopupGroupRatio
);
}
let
PayAddress
=
removeTrailingSlash
(
inputs
.
PayAddress
);
await
updateOption
(
'PayAddress'
,
PayAddress
);
await
updateOption
(
'EpayId'
,
inputs
.
EpayId
);
...
...
@@ -297,8 +309,19 @@ const SystemSetting = () => {
onChange
=
{
handleInputChange
}
/
>
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
TextArea
label
=
'充值分组倍率'
name
=
'TopupGroupRatio'
onChange
=
{
handleInputChange
}
style
=
{{
minHeight
:
250
,
fontFamily
:
'JetBrains Mono, Consolas'
}}
autoComplete
=
'new-password'
value
=
{
inputs
.
TopupGroupRatio
}
placeholder
=
'为一个 JSON 文本,键为组名称,值为倍率'
/>
<
/Form.Group
>
<
Form
.
Button
onClick
=
{
submitPayAddress
}
>
更新支付
地址
更新支付
设置
<
/Form.Button
>
<
Divider
/>
<
Header
as
=
'h3'
>
配置登录注册
<
/Header
>
...
...
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