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
c7d1cef7
authored
Aug 25, 2023
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改stat接口返回值
parent
68b24da6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
25 deletions
+54
-25
controller/log.go
+7
-4
controller/midjourney.go
+6
-0
controller/topup.go
+28
-14
model/log.go
+10
-4
web/src/pages/TopUp/index.js
+3
-3
No files found.
controller/log.go
View file @
c7d1cef7
...
@@ -118,14 +118,15 @@ func GetLogsStat(c *gin.Context) {
...
@@ -118,14 +118,15 @@ func GetLogsStat(c *gin.Context) {
tokenName
:=
c
.
Query
(
"token_name"
)
tokenName
:=
c
.
Query
(
"token_name"
)
username
:=
c
.
Query
(
"username"
)
username
:=
c
.
Query
(
"username"
)
modelName
:=
c
.
Query
(
"model_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
quotaNum
:=
model
.
SumUsedQuota
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
)
stat
:=
model
.
SumUsedQuota
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
)
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
//tokenNum := model.SumUsedToken(logType, startTimestamp, endTimestamp, modelName, username, "")
c
.
JSON
(
200
,
gin
.
H
{
c
.
JSON
(
200
,
gin
.
H
{
"success"
:
true
,
"success"
:
true
,
"message"
:
""
,
"message"
:
""
,
"data"
:
gin
.
H
{
"data"
:
gin
.
H
{
"quota"
:
quotaNum
,
"quota"
:
stat
.
Quota
,
//"token": tokenNum,
"rpm"
:
stat
.
Rpm
,
"tpm"
:
stat
.
Tpm
,
},
},
})
})
}
}
...
@@ -143,7 +144,9 @@ func GetLogsSelfStat(c *gin.Context) {
...
@@ -143,7 +144,9 @@ func GetLogsSelfStat(c *gin.Context) {
"success"
:
true
,
"success"
:
true
,
"message"
:
""
,
"message"
:
""
,
"data"
:
gin
.
H
{
"data"
:
gin
.
H
{
"quota"
:
quotaNum
,
"quota"
:
quotaNum
.
Quota
,
"rpm"
:
quotaNum
.
Rpm
,
"tpm"
:
quotaNum
.
Tpm
,
//"token": tokenNum,
//"token": tokenNum,
},
},
})
})
...
...
controller/midjourney.go
View file @
c7d1cef7
...
@@ -14,6 +14,12 @@ import (
...
@@ -14,6 +14,12 @@ import (
)
)
func
UpdateMidjourneyTask
()
{
func
UpdateMidjourneyTask
()
{
//revocer
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
log
.
Printf
(
"UpdateMidjourneyTask: %v"
,
err
)
}
}()
imageModel
:=
"midjourney"
imageModel
:=
"midjourney"
for
{
for
{
time
.
Sleep
(
time
.
Duration
(
15
)
*
time
.
Second
)
time
.
Sleep
(
time
.
Duration
(
15
)
*
time
.
Second
)
...
...
controller/topup.go
View file @
c7d1cef7
...
@@ -24,21 +24,28 @@ type AmountRequest struct {
...
@@ -24,21 +24,28 @@ type AmountRequest struct {
TopUpCode
string
`json:"top_up_code"`
TopUpCode
string
`json:"top_up_code"`
}
}
//var client, _ = epay.NewClientWithUrl(&epay.Config{
// PartnerID: "1096",
// Key: "n08V9LpE8JffA3NPP893689u8p39NV9J",
//}, "https://api.lempay.org")
var
client
,
_
=
epay
.
NewClientWithUrl
(
&
epay
.
Config
{
var
client
,
_
=
epay
.
NewClientWithUrl
(
&
epay
.
Config
{
PartnerID
:
"10
96
"
,
PartnerID
:
"10
64
"
,
Key
:
"n
08V9LpE8JffA3NPP893689u8p39NV9J
"
,
Key
:
"n
qrrZ5RjR86mKP8rKkyrOY5Pg8NmYfKR
"
,
},
"https://
api.lempay.org
"
)
},
"https://
pay.yunjuw.cn
"
)
func
GetAmount
(
id
int
,
count
float64
,
topUpCode
string
)
float64
{
func
GetAmount
(
id
int
,
count
float64
,
topUpCode
string
)
float64
{
amount
:=
count
*
1.5
amount
:=
count
*
1.5
if
topUpCode
!=
""
{
if
topUpCode
!=
""
{
if
topUpCode
==
"nekoapi"
{
if
topUpCode
==
"nekoapi"
{
if
id
==
89
{
if
id
==
89
{
amount
=
count
*
1
amount
=
count
*
0.8
}
else
if
id
==
98
||
id
==
105
||
id
==
107
{
}
else
if
id
==
105
||
id
==
107
{
amount
=
count
*
1.2
amount
=
count
*
1.2
}
else
if
id
==
1
{
}
else
if
id
==
1
{
amount
=
count
*
1
amount
=
count
*
1
}
else
if
id
==
98
{
amount
=
count
*
1.1
}
}
}
}
}
}
...
@@ -61,15 +68,15 @@ func RequestEpay(c *gin.Context) {
...
@@ -61,15 +68,15 @@ func RequestEpay(c *gin.Context) {
}
}
}
}
if
req
.
PaymentMethod
==
"zfb"
{
if
req
.
PaymentMethod
==
"zfb"
{
if
amount
>
4
00
{
if
amount
>
20
00
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"支付宝最大充值
400元"
,
"data"
:
amount
,
"count"
:
4
00
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"支付宝最大充值
2000元"
,
"data"
:
amount
,
"count"
:
20
00
})
return
return
}
}
req
.
PaymentMethod
=
"alipay"
req
.
PaymentMethod
=
"alipay"
}
}
if
req
.
PaymentMethod
==
"wx"
{
if
req
.
PaymentMethod
==
"wx"
{
if
amount
>
6
00
{
if
amount
>
20
00
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"微信最大充值
600元"
,
"data"
:
amount
,
"count"
:
6
00
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"微信最大充值
2000元"
,
"data"
:
amount
,
"count"
:
20
00
})
return
return
}
}
req
.
PaymentMethod
=
"wxpay"
req
.
PaymentMethod
=
"wxpay"
...
@@ -78,11 +85,18 @@ func RequestEpay(c *gin.Context) {
...
@@ -78,11 +85,18 @@ func RequestEpay(c *gin.Context) {
returnUrl
,
_
:=
url
.
Parse
(
"https://nekoapi.com/log"
)
returnUrl
,
_
:=
url
.
Parse
(
"https://nekoapi.com/log"
)
notifyUrl
,
_
:=
url
.
Parse
(
"https://nekoapi.com/api/user/epay/notify"
)
notifyUrl
,
_
:=
url
.
Parse
(
"https://nekoapi.com/api/user/epay/notify"
)
tradeNo
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
tradeNo
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
payMoney
:=
amount
//if payMoney < 400 {
// payMoney = amount * 0.99
// if amount-payMoney > 2 {
// payMoney = amount - 2
// }
//}
uri
,
params
,
err
:=
client
.
Purchase
(
&
epay
.
PurchaseArgs
{
uri
,
params
,
err
:=
client
.
Purchase
(
&
epay
.
PurchaseArgs
{
Type
:
epay
.
PurchaseType
(
req
.
PaymentMethod
),
Type
:
epay
.
PurchaseType
(
req
.
PaymentMethod
),
ServiceTradeNo
:
"A"
+
tradeNo
,
ServiceTradeNo
:
"A"
+
tradeNo
,
Name
:
"B"
+
tradeNo
,
Name
:
"B"
+
tradeNo
,
Money
:
strconv
.
FormatFloat
(
amount
*
0.99
,
'f'
,
2
,
64
),
Money
:
strconv
.
FormatFloat
(
payMoney
,
'f'
,
2
,
64
),
Device
:
epay
.
PC
,
Device
:
epay
.
PC
,
NotifyUrl
:
notifyUrl
,
NotifyUrl
:
notifyUrl
,
ReturnUrl
:
returnUrl
,
ReturnUrl
:
returnUrl
,
...
@@ -163,10 +177,10 @@ func RequestAmount(c *gin.Context) {
...
@@ -163,10 +177,10 @@ func RequestAmount(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"最小充值10刀"
,
"data"
:
GetAmount
(
id
,
10
,
req
.
TopUpCode
),
"count"
:
10
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"最小充值10刀"
,
"data"
:
GetAmount
(
id
,
10
,
req
.
TopUpCode
),
"count"
:
10
})
return
return
}
}
if
req
.
Amount
>
4
00
{
//if req.Amount > 15
00 {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"最大充值400刀"
,
"data"
:
GetAmount
(
id
,
400
,
req
.
TopUpCode
),
"count"
:
4
00
})
// c.JSON(200, gin.H{"message": "最大充值1000刀", "data": GetAmount(id, 1000, req.TopUpCode), "count": 15
00})
return
//
return
}
//
}
}
}
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"success"
,
"data"
:
GetAmount
(
id
,
float64
(
req
.
Amount
),
req
.
TopUpCode
)})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"success"
,
"data"
:
GetAmount
(
id
,
float64
(
req
.
Amount
),
req
.
TopUpCode
)})
...
...
model/log.go
View file @
c7d1cef7
...
@@ -133,8 +133,14 @@ func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
...
@@ -133,8 +133,14 @@ func SearchUserLogs(userId int, keyword string) (logs []*Log, err error) {
return
logs
,
err
return
logs
,
err
}
}
func
SumUsedQuota
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
)
(
quota
int
)
{
type
Stat
struct
{
tx
:=
DB
.
Table
(
"logs"
)
.
Select
(
"sum(quota)"
)
Quota
int
`json:"quota"`
Rpm
int
`json:"rpm"`
Tpm
int
`json:"tpm"`
}
func
SumUsedQuota
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
)
(
stat
Stat
)
{
tx
:=
DB
.
Table
(
"logs"
)
.
Select
(
"sum(quota) quota, count(*) rpm, sum(prompt_tokens) + sum(completion_tokens) tpm"
)
if
username
!=
""
{
if
username
!=
""
{
tx
=
tx
.
Where
(
"username = ?"
,
username
)
tx
=
tx
.
Where
(
"username = ?"
,
username
)
}
}
...
@@ -150,8 +156,8 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
...
@@ -150,8 +156,8 @@ func SumUsedQuota(logType int, startTimestamp int64, endTimestamp int64, modelNa
if
modelName
!=
""
{
if
modelName
!=
""
{
tx
=
tx
.
Where
(
"model_name = ?"
,
modelName
)
tx
=
tx
.
Where
(
"model_name = ?"
,
modelName
)
}
}
tx
.
Where
(
"type = ?"
,
LogTypeConsume
)
.
Scan
(
&
quota
)
tx
.
Where
(
"type = ?"
,
LogTypeConsume
)
.
Scan
(
&
stat
)
return
quota
return
stat
}
}
func
SumUsedToken
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
)
(
token
int
)
{
func
SumUsedToken
(
logType
int
,
startTimestamp
int64
,
endTimestamp
int64
,
modelName
string
,
username
string
,
tokenName
string
)
(
token
int
)
{
...
...
web/src/pages/TopUp/index.js
View file @
c7d1cef7
...
@@ -184,7 +184,7 @@ const TopUp = () => {
...
@@ -184,7 +184,7 @@ const TopUp = () => {
<
Grid
.
Column
>
<
Grid
.
Column
>
<
Form
>
<
Form
>
<
Form
.
Input
<
Form
.
Input
placeholder
=
'充值金额,最低10,最高
4
00'
placeholder
=
'充值金额,最低10,最高
10
00'
name
=
'redemptionCount'
name
=
'redemptionCount'
type
=
{
'number'
}
type
=
{
'number'
}
value
=
{
topUpCount
}
value
=
{
topUpCount
}
...
@@ -207,14 +207,14 @@ const TopUp = () => {
...
@@ -207,14 +207,14 @@ const TopUp = () => {
onlineTopUp
(
'zfb'
)
onlineTopUp
(
'zfb'
)
}
}
}
>
}
>
支付宝(最大
4
00
元)
支付宝(最大
20
00
元)
<
/Button
>
<
/Button
>
<
Button
color
=
'green'
onClick
=
{
<
Button
color
=
'green'
onClick
=
{
async
()
=>
{
async
()
=>
{
onlineTopUp
(
'wx'
)
onlineTopUp
(
'wx'
)
}
}
}
>
}
>
微信(最大
6
00
元)
微信(最大
20
00
元)
<
/Button
>
<
/Button
>
<
/Form
>
<
/Form
>
<
/Grid.Column
>
<
/Grid.Column
>
...
...
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