Commit 9faa42b8 authored by 陈涛's avatar 陈涛

修改申购赎回账单

parent 6eb87824
...@@ -11,6 +11,7 @@ from model.bill import PCFBill, ExchangeBill, AdjustBill, StakingBill ...@@ -11,6 +11,7 @@ from model.bill import PCFBill, ExchangeBill, AdjustBill, StakingBill
from schema.bill import CreatePCFBill, PCFBillType, CreateExchangeBill, CreateAdjustBill, CreateStakingBill, \ from schema.bill import CreatePCFBill, PCFBillType, CreateExchangeBill, CreateAdjustBill, CreateStakingBill, \
UpdatePCFBill, UpdateExchangeBill, UpdateStakingBill, UpdateAdjustBill, AllBillType UpdatePCFBill, UpdateExchangeBill, UpdateStakingBill, UpdateAdjustBill, AllBillType
from service.bill import update_bill, create_staking from service.bill import update_bill, create_staking
from service.fund import query_fund_assets, update_assets
from tools.jwt_tools import User from tools.jwt_tools import User
router = APIRouter() router = APIRouter()
...@@ -27,19 +28,15 @@ async def create_pcf( ...@@ -27,19 +28,15 @@ async def create_pcf(
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),
): ):
query = {"id": item.fund_id, "user_id": user.id} assets, adjust_assets, pending_assets, staking_assets = await query_fund_assets(fund_collect, item.fund_id, user.id)
fund = await fund_collect.find_one(query) if item.currency in assets:
assert fund, NotFundError()
filter_asset = list(filter(lambda x: x["currency"] == item.currency, fund["assets"]))
if filter_asset:
inc = item.volume if item.bill_type == PCFBillType.sub else -item.volume inc = item.volume if item.bill_type == PCFBillType.sub else -item.volume
assert filter_asset[0]["volume"] + inc >= 0, "余额不足" assert assets[item.currency] + inc >= 0, "余额不足"
update = {"$inc": {"assets.$.volume": inc}} assets[item.currency] += inc
await fund_collect.update_one({**query, "assets.currency": item.currency}, update)
else: else:
update = {"$push": {"assets": {"currency": item.currency, "volume": item.volume}}} assert item.bill_type == PCFBillType.sub, "余额不足"
await fund_collect.update_one(query, update) assets.update({item.currency: item.volume})
await update_assets(fund_collect, item.fund_id, assets=assets)
pcf = PCFBill(user_id=user.id, **item.dict()) pcf = PCFBill(user_id=user.id, **item.dict())
await bill_collect.insert_one(pcf.dict()) await bill_collect.insert_one(pcf.dict())
return Response[PCFBill](data=pcf.dict()) return Response[PCFBill](data=pcf.dict())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment