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
f90d93a6
Commit
f90d93a6
authored
Jun 21, 2023
by
陈涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改删除账目管理
parent
514ce3df
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
7 deletions
+100
-7
bill.py
api/bill.py
+100
-7
No files found.
api/bill.py
View file @
f90d93a6
import
datetime
import
re
from
typing
import
Union
,
List
,
Any
from
typing
import
Union
,
List
,
Any
import
pytz
from
fastapi
import
APIRouter
,
Depends
,
Query
from
fastapi
import
APIRouter
,
Depends
,
Query
from
motor.core
import
AgnosticCollection
from
motor.core
import
AgnosticCollection
from
pymongo
import
UpdateOne
from
dependencies
import
get_current_user
,
get_fund_collect
,
get_bill_collect
,
get_permission_user_collect
,
\
from
dependencies
import
get_current_user
,
get_fund_collect
,
get_bill_collect
,
get_permission_user_collect
,
\
get_permission_role_collect
,
get_nav_collect
get_permission_role_collect
,
get_nav_collect
from
exception.api
import
APIError
from
model
import
Response
,
Page
,
PageResponse
,
SortParams
,
FilterTime
from
model
import
Response
,
Page
,
PageResponse
,
SortParams
,
FilterTime
from
model.bill
import
PCFBill
,
ExchangeBill
,
AdjustBill
,
StakingBill
from
model.bill
import
PCFBill
,
ExchangeBill
,
AdjustBill
,
StakingBill
from
model.node
import
BaseNode
from
model.node
import
BaseNode
from
schema.bill
import
CreatePCFBill
,
PCFBillType
,
CreateExchangeBill
,
CreateAdjustBill
,
CreateStakingBill
,
\
from
schema.bill
import
CreatePCFBill
,
PCFBillType
,
CreateExchangeBill
,
CreateAdjustBill
,
CreateStakingBill
,
\
UpdatePCFBill
,
UpdateExchangeBill
,
UpdateStakingBill
,
UpdateAdjustBill
,
AllBillType
,
StakingDirection
UpdatePCFBill
,
UpdateExchangeBill
,
UpdateStakingBill
,
UpdateAdjustBill
,
AllBillType
,
StakingDirection
,
BillType
from
schema.fund
import
FundStatus
from
schema.fund
import
FundStatus
from
schema.node
import
BindNode
from
schema.node
import
BindNode
from
service.beacon
import
BeaconChaService
from
service.beacon
import
BeaconChaService
...
@@ -159,7 +155,7 @@ async def create_adjust(
...
@@ -159,7 +155,7 @@ async def create_adjust(
fund_id
=
create_adjust_bill
.
fund_id
,
fund_id
=
create_adjust_bill
.
fund_id
,
record_time
=
create_adjust_bill
.
record_time
,
record_time
=
create_adjust_bill
.
record_time
,
settlement_time
=
fund_data
[
"settlement_time"
],
settlement_time
=
fund_data
[
"settlement_time"
],
a
sset
_changed
=
{
a
djust_assets
_changed
=
{
create_adjust_bill
.
currency
:
create_adjust_bill
.
volume
,
create_adjust_bill
.
currency
:
create_adjust_bill
.
volume
,
"fund_share"
:
create_adjust_bill
.
fund_share
"fund_share"
:
create_adjust_bill
.
fund_share
}
}
...
@@ -244,6 +240,7 @@ async def update_pcf_bill(
...
@@ -244,6 +240,7 @@ async def update_pcf_bill(
user
:
User
=
Depends
(
get_current_user
),
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
nav_collect
:
AgnosticCollection
=
Depends
(
get_nav_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
):
):
...
@@ -251,6 +248,25 @@ async def update_pcf_bill(
...
@@ -251,6 +248,25 @@ async def update_pcf_bill(
fund_id
,
fund_id
,
user
.
email
,
permission_user_collect
,
user
.
email
,
permission_user_collect
,
permission_role_collect
)
permission_role_collect
)
fund_data
=
await
fund_collect
.
find_one
({
"id"
:
fund_id
})
bill_data
=
await
bill_collect
.
find_one
({
"id"
:
bill_id
,
"bill_type"
:
{
"$in"
:
[
PCFBillType
.
sub
,
PCFBillType
.
redemption
]}})
A
=
{
bill_data
[
"currency"
]:
bill_data
[
"volume"
]}
B
=
{
update_item
.
currency
:
update_item
.
volume
}
changed
=
{
k
:
B
.
get
(
k
,
0
)
-
A
.
get
(
k
,
0
)
for
k
in
set
(
A
)
|
set
(
B
)}
bulk_list
=
await
build_nav_bulk_list
(
nav_collect
=
nav_collect
,
fund_id
=
fund_id
,
record_time
=
bill_data
[
"record_time"
],
settlement_time
=
fund_data
[
"settlement_time"
],
asset_changed
=
changed
)
assets
=
fund_data
[
"assets"
]
for
key
,
value
in
changed
.
items
():
assets
.
setdefault
(
key
,
0
)
assets
[
key
]
+=
value
await
update_fund
(
fund_collect
,
fund_id
,
assets
=
assets
)
if
bulk_list
:
await
nav_collect
.
bulk_write
(
bulk_list
)
response
=
await
update_bill
(
response
=
await
update_bill
(
bill_id
=
bill_id
,
bill_id
=
bill_id
,
fund_id
=
fund_id
,
fund_id
=
fund_id
,
...
@@ -274,6 +290,7 @@ async def update_exchange_bill(
...
@@ -274,6 +290,7 @@ async def update_exchange_bill(
user
:
User
=
Depends
(
get_current_user
),
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
nav_collect
:
AgnosticCollection
=
Depends
(
get_nav_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
):
):
...
@@ -281,6 +298,25 @@ async def update_exchange_bill(
...
@@ -281,6 +298,25 @@ async def update_exchange_bill(
fund_id
,
fund_id
,
user
.
email
,
permission_user_collect
,
user
.
email
,
permission_user_collect
,
permission_role_collect
)
permission_role_collect
)
fund_data
=
await
fund_collect
.
find_one
({
"id"
:
fund_id
})
bill_data
=
await
bill_collect
.
find_one
({
"id"
:
bill_id
,
"bill_type"
:
BillType
.
exchange
})
A
=
{
bill_data
[
"input_currency"
]:
-
bill_data
[
"input_volume"
],
bill_data
[
"output_currency"
]:
bill_data
[
"output_volume"
]}
B
=
{
update_item
.
input_currency
:
-
update_item
.
input_volume
,
update_item
.
output_currency
:
update_item
.
output_volume
}
changed
=
{
k
:
B
.
get
(
k
,
0
)
-
A
.
get
(
k
,
0
)
for
k
in
set
(
A
)
|
set
(
B
)}
bulk_list
=
await
build_nav_bulk_list
(
nav_collect
=
nav_collect
,
fund_id
=
fund_id
,
record_time
=
bill_data
[
"record_time"
],
settlement_time
=
fund_data
[
"settlement_time"
],
asset_changed
=
changed
)
assets
=
fund_data
[
"assets"
]
for
key
,
value
in
changed
.
items
():
assets
.
setdefault
(
key
,
0
)
assets
[
key
]
+=
value
await
update_fund
(
fund_collect
,
fund_id
,
assets
=
assets
)
if
bulk_list
:
await
nav_collect
.
bulk_write
(
bulk_list
)
response
=
await
update_bill
(
response
=
await
update_bill
(
bill_id
=
bill_id
,
bill_id
=
bill_id
,
fund_id
=
fund_id
,
fund_id
=
fund_id
,
...
@@ -304,6 +340,7 @@ async def update_adjust_bill(
...
@@ -304,6 +340,7 @@ async def update_adjust_bill(
user
:
User
=
Depends
(
get_current_user
),
user
:
User
=
Depends
(
get_current_user
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
nav_collect
:
AgnosticCollection
=
Depends
(
get_nav_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
):
):
...
@@ -311,6 +348,25 @@ async def update_adjust_bill(
...
@@ -311,6 +348,25 @@ async def update_adjust_bill(
fund_id
,
fund_id
,
user
.
email
,
permission_user_collect
,
user
.
email
,
permission_user_collect
,
permission_role_collect
)
permission_role_collect
)
fund_data
=
await
fund_collect
.
find_one
({
"id"
:
fund_id
})
bill_data
=
await
bill_collect
.
find_one
({
"id"
:
bill_id
,
"bill_type"
:
BillType
.
adjust
})
A
=
{
bill_data
[
"currency"
]:
bill_data
[
"volume"
],
"fund_share"
:
bill_data
[
"fund_share"
]}
B
=
{
update_item
.
currency
:
update_item
.
volume
,
"fund_share"
:
update_item
.
fund_share
}
changed
=
{
k
:
B
.
get
(
k
,
0
)
-
A
.
get
(
k
,
0
)
for
k
in
set
(
A
)
|
set
(
B
)}
bulk_list
=
await
build_nav_bulk_list
(
nav_collect
=
nav_collect
,
fund_id
=
fund_id
,
record_time
=
bill_data
[
"record_time"
],
settlement_time
=
fund_data
[
"settlement_time"
],
asset_changed
=
changed
)
adjust_assets
=
fund_data
[
"adjust_assets"
]
for
key
,
value
in
changed
.
items
():
adjust_assets
.
setdefault
(
key
,
0
)
adjust_assets
[
key
]
+=
value
await
update_fund
(
fund_collect
,
fund_id
,
adjust_assets
=
adjust_assets
)
if
bulk_list
:
await
nav_collect
.
bulk_write
(
bulk_list
)
response
=
await
update_bill
(
response
=
await
update_bill
(
bill_id
=
bill_id
,
bill_id
=
bill_id
,
fund_id
=
fund_id
,
fund_id
=
fund_id
,
...
@@ -394,7 +450,9 @@ async def query_bill(
...
@@ -394,7 +450,9 @@ async def query_bill(
fund_id
:
str
,
fund_id
:
str
,
bill_id
:
str
,
bill_id
:
str
,
bill_type
:
AllBillType
,
bill_type
:
AllBillType
,
fund_collect
:
AgnosticCollection
=
Depends
(
get_fund_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
bill_collect
:
AgnosticCollection
=
Depends
(
get_bill_collect
),
nav_collect
:
AgnosticCollection
=
Depends
(
get_nav_collect
),
user
:
User
=
Depends
(
get_current_user
),
user
:
User
=
Depends
(
get_current_user
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_user_collect
:
AgnosticCollection
=
Depends
(
get_permission_user_collect
),
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
permission_role_collect
:
AgnosticCollection
=
Depends
(
get_permission_role_collect
)
...
@@ -405,5 +463,40 @@ async def query_bill(
...
@@ -405,5 +463,40 @@ async def query_bill(
permission_role_collect
)
permission_role_collect
)
query
=
{
"fund_id"
:
fund_id
,
"bill_type"
:
bill_type
,
"id"
:
bill_id
}
query
=
{
"fund_id"
:
fund_id
,
"bill_type"
:
bill_type
,
"id"
:
bill_id
}
fund_data
=
await
fund_collect
.
find_one
({
"id"
:
fund_id
})
bill_data
=
await
bill_collect
.
find_one
({
"id"
:
bill_id
})
assets_changed
,
adjust_changed
=
{},
{}
assets
,
adjust_assets
=
fund_data
[
"assets"
],
fund_data
[
"adjust_assets"
]
if
bill_data
[
"bill_type"
]
==
PCFBillType
.
sub
or
bill_data
[
"bill_type"
]
==
PCFBillType
.
redemption
:
delta_volume
=
-
bill_data
[
"volume"
]
if
bill_data
[
"bill_type"
]
==
PCFBillType
.
sub
else
bill_data
[
"volume"
]
assets_changed
=
{
bill_data
[
"currency"
]:
delta_volume
}
assets
[
bill_data
[
"currency"
]]
+=
delta_volume
elif
bill_data
[
"bill_type"
]
==
BillType
.
exchange
:
assets_changed
.
update
({
bill_data
[
"input_currency"
]:
bill_data
[
"input_volume"
],
bill_data
[
"output_currency"
]:
-
bill_data
[
"output_volume"
]
})
assets
[
bill_data
[
"input_currency"
]]
+=
bill_data
[
"input_volume"
]
assets
[
bill_data
[
"output_currency"
]]
-=
bill_data
[
"output_volume"
]
elif
bill_data
[
"bill_type"
]
==
BillType
.
adjust
:
adjust_changed
.
update
({
bill_data
[
"currency"
]:
-
bill_data
[
"volume"
],
"fund_share"
:
-
bill_data
[
"fund_share"
]
})
adjust_assets
[
bill_data
[
"currency"
]]
-=
bill_data
[
"volume"
]
adjust_assets
[
"fund_share"
]
-=
bill_data
[
"fund_share"
]
else
:
raise
APIError
(
message
=
"该账单不支持删除"
)
bulk_list
=
await
build_nav_bulk_list
(
nav_collect
=
nav_collect
,
fund_id
=
fund_id
,
record_time
=
bill_data
[
"record_time"
],
settlement_time
=
fund_data
[
"settlement_time"
],
asset_changed
=
assets_changed
,
adjust_assets_changed
=
adjust_changed
)
await
update_fund
(
fund_collect
,
fund_id
,
assets
=
assets
,
adjust_assets
=
adjust_assets
)
if
bulk_list
:
await
nav_collect
.
bulk_write
(
bulk_list
)
await
bill_collect
.
delete_one
(
query
)
await
bill_collect
.
delete_one
(
query
)
return
Response
()
return
Response
()
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