Commit 4073c450 authored by 陈涛's avatar 陈涛

增加更新bill账目,fund增加绑定机构id

parent bc1d2dc2
import datetime
from loguru import logger from loguru import logger
from fastapi import APIRouter, Depends from fastapi import APIRouter, Depends
from motor.core import AgnosticCollection from motor.core import AgnosticCollection
from pymongo import ReturnDocument
from pymongo.operations import UpdateOne from pymongo.operations import UpdateOne
from dependencies import get_current_user, get_fund_collect, get_bill_collect from dependencies import get_current_user, get_fund_collect, get_bill_collect
from exception.db import NotFundError from exception.db import NotFundError
from model import Response, Page, PageResponse from model import Response, Page, PageResponse
from model.bill import PCFBill, ExchangeBill, BillType, CreatePCFBill, CreateExchangeBill, StakingBill, CreateStaking, \ from model.bill import PCFBill, ExchangeBill, BillType, CreatePCFBill, CreateExchangeBill, StakingBill, CreateStaking, \
AdjustBill, CreateAdjustBill AdjustBill, CreateAdjustBill, UpdatePCFBill, UpdateExchangeBill, UpdateStakingBill, UpdateAdjustBill
from service.bill import update_bill
from tools.jwt_tools import User from tools.jwt_tools import User
router = APIRouter() router = APIRouter()
...@@ -182,14 +184,97 @@ async def query_adjust( ...@@ -182,14 +184,97 @@ async def query_adjust(
return response return response
# @router.put('/{fund_id}/', @router.put('/{fund_id}/pcf/',
# response_model=PageResponse[AdjustBill], response_model=Response[PCFBill],
# summary='更新调整记录', summary='更新申购赎回记录',
# description='') description='')
# async def update_bill( async def update_pcf_bill(
# bill_id: str, bill_id: str,
# update_item: str, fund_id: str,
# user: User = Depends(get_current_user), update_item: UpdatePCFBill,
# bill_collect: AgnosticCollection = Depends(get_bill_collect), user: User = Depends(get_current_user),
# ): fund_collect: AgnosticCollection = Depends(get_fund_collect),
# pass bill_collect: AgnosticCollection = Depends(get_bill_collect),
\ No newline at end of file ):
response = await update_bill(
bill_id=bill_id,
fund_id=fund_id,
user_id=user.id,
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=PCFBill
)
return response
@router.put('/{fund_id}/exchange/',
response_model=Response[ExchangeBill],
summary='更新置换记录',
description='')
async def update_exchange_bill(
bill_id: str,
fund_id: str,
update_item: UpdateExchangeBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
response = await update_bill(
bill_id=bill_id,
fund_id=fund_id,
user_id=user.id,
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=ExchangeBill
)
return response
@router.put('/{fund_id}/staking/',
response_model=Response[StakingBill],
summary='更新申购赎回调整记录',
description='')
async def update_staking_bill(
bill_id: str,
fund_id: str,
update_item: UpdateStakingBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
response = await update_bill(
bill_id=bill_id,
fund_id=fund_id,
user_id=user.id,
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=StakingBill
)
return response
@router.put('/{fund_id}/adjust/',
response_model=Response[AdjustBill],
summary='更新调整记录',
description='')
async def update_adjust_bill(
bill_id: str,
fund_id: str,
update_item: UpdateAdjustBill,
user: User = Depends(get_current_user),
fund_collect: AgnosticCollection = Depends(get_fund_collect),
bill_collect: AgnosticCollection = Depends(get_bill_collect),
):
response = await update_bill(
bill_id=bill_id,
fund_id=fund_id,
user_id=user.id,
update_data=update_item,
fund_collect=fund_collect,
bill_collect=bill_collect,
res_model=AdjustBill
)
return response
...@@ -87,27 +87,40 @@ class AdjustBill(CreateAdjustBill, BaseCreateModel): ...@@ -87,27 +87,40 @@ class AdjustBill(CreateAdjustBill, BaseCreateModel):
class UpdatePCFBill(BaseModel): class UpdatePCFBill(BaseModel):
email: Optional[str] = Field(None, description='客户邮箱') email: Optional[str] = Field(None, description='客户邮箱')
currency: Optional[str] = Field(None, description='币种') currency: Optional[str] = Field(None, description='币种')
volume: Optional[float] = Field(..., description='资产数量') volume: Optional[float] = Field(None, description='资产数量')
price: Optional[float] = Field(None, description="价格") price: Optional[float] = Field(None, description="价格")
fund_share: Optional[float] = Field(None, description="基金份额") fund_share: Optional[float] = Field(None, description="基金份额")
market_value: Optional[float] = Field(None, description="市值") market_value: Optional[float] = Field(None, description="市值")
class Config:
orm_mode = True
class UpdateExchangeBill(BaseModel): class UpdateExchangeBill(BaseModel):
input_currency: Optional[str] = Field(..., description="投入币种") input_currency: Optional[str] = Field(None, description="投入币种")
input_price: Optional[float] = Field(..., description="投入币种价格") input_price: Optional[float] = Field(None, description="投入币种价格")
input_volume: Optional[float] = Field(..., description="投入数量") input_volume: Optional[float] = Field(None, description="投入数量")
output_currency: Optional[str] = Field(..., description="输出币种") output_currency: Optional[str] = Field(None, description="输出币种")
output_price: Optional[float] = Field(..., description="输出币种价格") output_price: Optional[float] = Field(None, description="输出币种价格")
output_volume: Optional[float] = Field(..., description="输出数量") output_volume: Optional[float] = Field(None, description="输出数量")
class Config:
orm_mode = True
class UpdateStakingBill(BaseModel): class UpdateStakingBill(BaseModel):
currency: Optional[str] = Field(default="ETH", description='币种') currency: Optional[str] = Field(default="ETH", description='币种')
volume: Optional[float] = Field(..., description='数量') volume: Optional[float] = Field(None, description='数量')
price: float = Field(None, description="价格")
class Config:
orm_mode = True
class UpdateAdjustBill(BaseModel): class UpdateAdjustBill(BaseModel):
currency: Optional[str] = Field(None, description='币种') currency: Optional[str] = Field(None, description='币种')
volume: Optional[float] = Field(..., description='资产数量') volume: Optional[float] = Field(None, description='资产数量')
price: Optional[float] = Field(None, description="价格") price: Optional[float] = Field(None, description="价格")
class Config:
orm_mode = True
...@@ -20,6 +20,7 @@ class FundStatus(str, Enum): ...@@ -20,6 +20,7 @@ class FundStatus(str, Enum):
class BaseFundItem(BaseModel): class BaseFundItem(BaseModel):
org_id: int = Field(..., description="机构id")
name: str = Field(..., description='基金名称') name: str = Field(..., description='基金名称')
fund_type: FundType = Field(default=FundType.staking, description='基金类型') fund_type: FundType = Field(default=FundType.staking, description='基金类型')
fund_status: FundStatus = Field(default=FundStatus.active, description='基金状态') fund_status: FundStatus = Field(default=FundStatus.active, description='基金状态')
......
import datetime
from typing import TypeVar, Generic, Type
from motor.core import AgnosticCollection from motor.core import AgnosticCollection
from pymongo import ReturnDocument
from exception.db import NotFundError from exception.db import NotFundError
from model import Response
from model.bill import CreateStaking, StakingBill from model.bill import CreateStaking, StakingBill
DataT = TypeVar('DataT')
async def create_staking( async def create_staking(
item: CreateStaking, item: CreateStaking,
...@@ -25,3 +32,18 @@ async def create_staking( ...@@ -25,3 +32,18 @@ async def create_staking(
return staking_bill return staking_bill
async def update_bill(
bill_id: str, fund_id: str, user_id: str, update_data: [], fund_collect, bill_collect,
res_model: Type[DataT]
) -> Response[DataT]:
fund = await fund_collect.find_one({'id': fund_id, 'user_id': user_id})
assert fund, NotFundError()
db_update_data = update_data.dict(exclude_unset=True)
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},
return_document=ReturnDocument.AFTER)
assert data, NotFundError()
response = Response[DataT](data=res_model(**data))
return response
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