Commit a39871ce authored by confusion's avatar confusion

修改创建PCF账单接口

parent 83f2d5ac
......@@ -27,7 +27,6 @@ async def create_pcf(
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
assert item.bill_type == PCFBillType.sub or item.bill_type == PCFBillType.redemption, "枚举错误"
query = {"id": item.fund_id, "user_id": user.id}
fund = await fund_collect.find_one(query)
assert fund, NotFundError()
......@@ -40,10 +39,10 @@ async def create_pcf(
else:
update = {"$push": {"assets": {"currency": item.currency, "volume": item.volume}}}
await fund_collect.update_one(query, update)
market_value = item.volume * item.price
prc = PCFBill(user_id=user.id, fund_share=market_value / fund["nav"], market_value=market_value, **item.dict())
await bill_collect.insert_one(prc.dict())
return Response[PCFBill](data=prc.dict())
pcf = PCFBill(user_id=user.id, **item.dict())
await bill_collect.insert_one(pcf.dict())
return Response[PCFBill](data=pcf.dict())
@router.post('/exchange/',
......@@ -120,10 +119,9 @@ async def create_adjust(
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)
staking_bill = await create_staking(item, user.id, bill_collect)
response = Response[StakingBill](data=staking_bill.dict())
return response
......
......@@ -48,6 +48,9 @@ class StakingBillStatus(str, Enum):
# 创建申购赎回记录
class CreatePCFBill(BaseModel):
fund_id: str = Field(..., description='基金id')
fund_share: float = Field(..., description="基金份额")
market_value: float = Field(..., description="市值")
email: str = Field(..., description='客户邮箱')
bill_type: PCFBillType = Field(..., description='账目类型')
currency: str = Field(..., description='币种')
......
......@@ -15,19 +15,8 @@ DataT = TypeVar('DataT')
async def create_staking(
item: CreateStakingBill,
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)
staking_bill = StakingBill(user_id=user_id, **item.dict())
await bill_collect.insert_one(staking_bill.dict())
return staking_bill
......@@ -43,7 +32,8 @@ async def update_bill(
db_update_data.update({
"update_time": int(datetime.datetime.utcnow().timestamp())
})
data = await bill_collect.find_one_and_update({'id': bill_id, "fund_id": fund_id}, {'$set': db_update_data},
data = await bill_collect.find_one_and_update({'id': bill_id, "fund_id": fund_id},
{'$set': db_update_data},
return_document=ReturnDocument.AFTER)
assert data, NotFundError()
response = Response[DataT](data=res_model(**data))
......
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