Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
PyFund
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈涛
PyFund
Commits
c7f245da
Commit
c7f245da
authored
Mar 27, 2023
by
confusion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加 增加质押记录接口
parent
76336ff9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
18 deletions
+35
-18
bill.py
api/bill.py
+21
-4
bill.py
model/bill.py
+2
-2
bill.py
service/bill.py
+12
-12
No files found.
api/bill.py
View file @
c7f245da
...
...
@@ -8,8 +8,9 @@ from dependencies import get_current_user, get_fund_collect, get_bill_collect
from
exception.db
import
NotFundError
from
model
import
Response
,
Page
,
PageResponse
,
SortParams
,
FilterTime
from
model.bill
import
PCFBill
,
ExchangeBill
,
BillType
,
CreatePCFBill
,
CreateExchangeBill
,
StakingBill
,
\
AdjustBill
,
CreateAdjustBill
,
UpdatePCFBill
,
UpdateExchangeBill
,
UpdateStakingBill
,
UpdateAdjustBill
from
service.bill
import
update_bill
AdjustBill
,
CreateAdjustBill
,
UpdatePCFBill
,
UpdateExchangeBill
,
UpdateStakingBill
,
UpdateAdjustBill
,
\
CreateStakingBill
from
service.bill
import
update_bill
,
create_staking
from
tools.jwt_tools
import
User
router
=
APIRouter
()
...
...
@@ -18,7 +19,7 @@ router = APIRouter()
@
router
.
post
(
'/pcf/'
,
response_model
=
Response
[
PCFBill
],
tags
=
[
'新增'
],
summary
=
'添加
申购赎回
账目'
,
summary
=
'添加
[申购/赎回]
账目'
,
description
=
'添加申购赎回账目'
)
async
def
create_pcf
(
item
:
CreatePCFBill
,
...
...
@@ -111,6 +112,22 @@ async def create_adjust(
return
response
@
router
.
post
(
'/staking/'
,
response_model
=
Response
[
StakingBill
],
tags
=
[
'新增'
],
summary
=
'添加质押账目'
,
description
=
'添加质押账目'
)
async
def
create_staking_api
(
item
:
CreateStakingBill
,
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
):
staking_bill
=
await
create_staking
(
item
,
user
.
id
,
fund_collect
,
bill_collect
)
response
=
Response
[
StakingBill
](
data
=
staking_bill
.
dict
())
return
response
# @router.get('/exchange/{fund_id}/',
# response_model=PageResponse[ExchangeBill],
# summary='查询置换记录',
...
...
@@ -221,7 +238,7 @@ async def update_exchange_bill(
@
router
.
put
(
'/staking/{fund_id}/'
,
tags
=
[
'更新'
],
response_model
=
Response
[
StakingBill
],
summary
=
'更新
申购赎回调整
记录'
,
summary
=
'更新
质押
记录'
,
description
=
''
)
async
def
update_staking_bill
(
bill_id
:
str
,
...
...
model/bill.py
View file @
c7f245da
...
...
@@ -69,10 +69,10 @@ class ExchangeBill(CreateExchangeBill, BaseCreateModel):
bill_type
:
BillType
=
Field
(
default
=
BillType
.
exchange
,
description
=
'账目类型'
)
class
CreateStaking
(
BaseModel
):
class
CreateStaking
Bill
(
BaseModel
):
fund_id
:
str
=
Field
(
None
,
description
=
'基金id'
)
currency
:
str
=
Field
(
default
=
"ETH"
,
description
=
'币种'
)
volume
:
float
=
Field
(
...
,
description
=
'数量'
)
volume
:
float
=
Field
(
default
=
32
,
description
=
'数量'
)
record_time
:
str
=
Field
(
default_factory
=
lambda
:
str
(
datetime
.
datetime
.
utcnow
()
.
date
()),
description
=
'记录时间'
)
remark
:
str
=
Field
(
default
=
""
,
description
=
"备注"
)
...
...
service/bill.py
View file @
c7f245da
...
...
@@ -6,27 +6,27 @@ from pymongo import ReturnDocument
from
exception.db
import
NotFundError
from
model
import
Response
from
model.bill
import
CreateStaking
,
StakingBill
from
model.bill
import
CreateStaking
Bill
,
StakingBill
DataT
=
TypeVar
(
'DataT'
)
async
def
create_staking
(
item
:
CreateStaking
,
item
:
CreateStaking
Bill
,
user_id
,
fund_collect
:
AgnosticCollection
,
bill_collect
:
AgnosticCollection
,
):
query
=
{
"id"
:
item
.
fund_id
,
"user_id"
:
user_id
}
fund
=
await
fund_collect
.
find_one
(
query
)
assert
fund
,
NotFundError
()
filter_asset
=
list
(
filter
(
lambda
x
:
x
[
"currency"
]
==
item
.
currency
,
fund
[
"assets"
]))
if
filter_asset
:
update
=
{
"$inc"
:
{
"assets.$.volume"
:
-
item
.
volume
}}
await
fund_collect
.
update_one
({
**
query
,
"assets.currency"
:
item
.
currency
},
update
)
else
:
update
=
{
"$push"
:
{
"assets"
:
{
"currency"
:
item
.
currency
,
"volume"
:
-
item
.
volume
}}}
await
fund_collect
.
update_one
(
query
,
update
)
#
query = {"id": item.fund_id, "user_id": user_id}
#
fund = await fund_collect.find_one(query)
#
assert fund, NotFundError()
#
filter_asset = list(filter(lambda x: x["currency"] == item.currency, fund["assets"]))
#
if filter_asset:
#
update = {"$inc": {"assets.$.volume": -item.volume}}
#
await fund_collect.update_one({**query, "assets.currency": item.currency}, update)
#
else:
#
update = {"$push": {"assets": {"currency": item.currency, "volume": -item.volume}}}
#
await fund_collect.update_one(query, update)
staking_bill
=
StakingBill
(
user_id
=
user_id
,
**
item
.
dict
())
await
bill_collect
.
insert_one
(
staking_bill
.
dict
())
return
staking_bill
...
...
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