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

修改申购赎回账单

parent 6eb87824
......@@ -11,6 +11,7 @@ from model.bill import PCFBill, ExchangeBill, AdjustBill, StakingBill
from schema.bill import CreatePCFBill, PCFBillType, CreateExchangeBill, CreateAdjustBill, CreateStakingBill, \
UpdatePCFBill, UpdateExchangeBill, UpdateStakingBill, UpdateAdjustBill, AllBillType
from service.bill import update_bill, create_staking
from service.fund import query_fund_assets, update_assets
from tools.jwt_tools import User
router = APIRouter()
......@@ -27,19 +28,15 @@ async def create_pcf(
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
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:
assets, adjust_assets, pending_assets, staking_assets = await query_fund_assets(fund_collect, item.fund_id, user.id)
if item.currency in assets:
inc = item.volume if item.bill_type == PCFBillType.sub else -item.volume
assert filter_asset[0]["volume"] + inc >= 0, "余额不足"
update = {"$inc": {"assets.$.volume": inc}}
await fund_collect.update_one({**query, "assets.currency": item.currency}, update)
assert assets[item.currency] + inc >= 0, "余额不足"
assets[item.currency] += inc
else:
update = {"$push": {"assets": {"currency": item.currency, "volume": item.volume}}}
await fund_collect.update_one(query, update)
assert item.bill_type == PCFBillType.sub, "余额不足"
assets.update({item.currency: item.volume})
await update_assets(fund_collect, item.fund_id, assets=assets)
pcf = PCFBill(user_id=user.id, **item.dict())
await bill_collect.insert_one(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