11from nonebot_plugin_orm import get_session
22
3- from ..db_api .balance import add_balance as _a_balance
4- from ..db_api .balance import del_account as _del_account
5- from ..db_api .balance import del_balance as _d_balance
6- from ..db_api .balance import get_or_create_account as _go_account
7- from ..db_api .balance import list_accounts as _list_accounts
8- from ..db_api .balance import transfer_funds as _transfer
93from ..pyd_models .balance_pyd import UserAccountData
4+ from ..services .balance import add_balance as _a_balance
5+ from ..services .balance import del_account as _del_account
6+ from ..services .balance import del_balance as _d_balance
7+ from ..services .balance import get_or_create_account as _go_account
8+ from ..services .balance import list_accounts as _list_accounts
9+ from ..services .balance import transfer_funds as _transfer
1010from .api_currency import get_default_currency as _get_default
1111
1212
@@ -84,7 +84,7 @@ async def add_balance(
8484
8585 Args:
8686 user_id (str): 用户ID
87- amount (float): 数量
87+ amount (float): 金额
8888 source (str, optional): 源描述. Defaults to "_transfer".
8989 currency_id (str | None, optional): 货币ID(不填使用默认). Defaults to None.
9090
@@ -98,8 +98,8 @@ async def add_balance(
9898 if currency_id is None :
9999 currency_id = (await _get_default ()).id
100100 data = await _a_balance (user_id , currency_id , amount , source )
101- if not data .get ( " success" , False ) :
102- raise RuntimeError (data .get ( " message" , "" ) )
101+ if not data .success :
102+ raise RuntimeError (data .message )
103103 return await get_or_create_account (user_id , currency_id )
104104
105105
@@ -126,8 +126,8 @@ async def del_balance(
126126 if currency_id is None :
127127 currency_id = (await _get_default ()).id
128128 data = await _d_balance (user_id , currency_id , amount , source )
129- if not data .get ( " success" , False ) :
130- raise RuntimeError (data .get ( " message" , "" ) )
129+ if not data .success :
130+ raise RuntimeError (data .message )
131131 return await get_or_create_account (user_id , currency_id )
132132
133133
@@ -143,7 +143,7 @@ async def transfer_funds(
143143 Args:
144144 from_id (str): 源账户
145145 to_id (str): 目标账户
146- amount (float): 数量
146+ amount (float): 金额
147147 source (str, optional): 来源说明. Defaults to "from {from_id} to {to_id}".
148148 currency_id (str | None, optional): 货币ID(不填则使用默认货币). Defaults to None.
149149
@@ -155,9 +155,9 @@ async def transfer_funds(
155155 """
156156 if currency_id is None :
157157 currency_id = (await _get_default ()).id
158- if source == "" :
158+ if not source :
159159 source = f"from '{ from_id } ' to '{ to_id } '"
160160 data = await _transfer (from_id , to_id , currency_id , amount , source )
161- if not data .get ( " success" , False ) :
162- raise RuntimeError (data .get ( " message" , "" ) )
161+ if not data .success :
162+ raise RuntimeError (data .message )
163163 return await get_or_create_account (to_id , currency_id )
0 commit comments