Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
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
Unverified
Commit
63d1657f
authored
Jul 05, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin withdraw
parent
d00ac152
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
12 deletions
+38
-12
client/src/pages/api/admin/withdraw.ts
+36
-11
client/src/pages/number/index.tsx
+2
-1
No files found.
client/src/pages/api/admin/
countTraining
.ts
→
client/src/pages/api/admin/
withdraw
.ts
View file @
63d1657f
...
@@ -2,33 +2,58 @@
...
@@ -2,33 +2,58 @@
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
connectToDatabase
,
TrainingData
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
TrainingData
,
User
,
promotionRecord
}
from
'@/service/mongo'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
{
TrainingModeEnum
}
from
'@/constants/plugin'
;
import
mongoose
from
'mongoose'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
)
{
try
{
try
{
await
authUser
({
req
,
authRoot
:
true
});
await
authUser
({
req
,
authRoot
:
true
});
const
{
amount
,
userId
,
type
}
=
req
.
body
as
{
amount
:
number
;
userId
:
number
;
type
:
'withdraw'
;
};
await
connectToDatabase
();
await
connectToDatabase
();
// split queue data
if
(
!
userId
||
!
amount
||
type
!==
'withdraw'
||
amount
<=
0
)
{
const
result
=
await
TrainingData
.
aggregate
([
throw
new
Error
(
'params is error'
);
}
// check promotion balance
const
countResidue
:
{
totalAmount
:
number
}[]
=
await
promotionRecord
.
aggregate
([
{
$match
:
{
userId
:
new
mongoose
.
Types
.
ObjectId
(
userId
)
}
},
{
{
$group
:
{
$group
:
{
_id
:
'$mode'
,
_id
:
null
,
// 分组条件,这里使用 null 表示不分组
count
:
{
$sum
:
1
}
totalAmount
:
{
$sum
:
'$amount'
}
// 计算 amount 字段的总和
}
},
{
$project
:
{
_id
:
false
,
// 排除 _id 字段
totalAmount
:
true
// 只返回 totalAmount 字段
}
}
}
}
]);
]);
const
balance
=
countResidue
[
0
].
totalAmount
;
if
(
balance
<
amount
)
{
throw
new
Error
(
'可提现余额不足'
);
}
// add record
await
promotionRecord
.
create
({
userId
,
type
,
amount
:
-
amount
});
jsonRes
(
res
,
{
jsonRes
(
res
,
{
data
:
{
data
:
balance
qaListLen
:
result
.
find
((
item
)
=>
item
.
_id
===
TrainingModeEnum
.
qa
)?.
count
||
0
,
vectorListLen
:
result
.
find
((
item
)
=>
item
.
_id
===
TrainingModeEnum
.
index
)?.
count
||
0
}
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
error
error
...
...
client/src/pages/number/index.tsx
View file @
63d1657f
...
@@ -220,7 +220,8 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -220,7 +220,8 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
{
[
{
[
{
label
:
'佣金比例'
,
value
:
`${userInfo?.promotion.rate || 15}%`
},
{
label
:
'佣金比例'
,
value
:
`${userInfo?.promotion.rate || 15}%`
},
{
label
:
'已注册用户数'
,
value
:
`${invitedAmount}人`
},
{
label
:
'已注册用户数'
,
value
:
`${invitedAmount}人`
},
{
label
:
'累计佣金'
,
value
:
`¥${historyAmount}`
}
{
label
:
'累计佣金'
,
value
:
`¥${historyAmount}`
},
{
label
:
'可用佣金'
,
value
:
`¥${residueAmount}`
}
].
map
((
item
)
=>
(
].
map
((
item
)
=>
(
<
Flex
key=
{
item
.
label
}
alignItems=
{
'center'
}
mt=
{
4
}
justifyContent=
{
'space-between'
}
>
<
Flex
key=
{
item
.
label
}
alignItems=
{
'center'
}
mt=
{
4
}
justifyContent=
{
'space-between'
}
>
<
Box
w=
{
'120px'
}
>
{
item
.
label
}
</
Box
>
<
Box
w=
{
'120px'
}
>
{
item
.
label
}
</
Box
>
...
...
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