diff --git a/jcloud/api/account.py b/jcloud/api/account.py index a9a91fb..d806608 100644 --- a/jcloud/api/account.py +++ b/jcloud/api/account.py @@ -1540,20 +1540,7 @@ def update_profile_email(email): @jingrow.whitelist() def verify_api_credentials_and_balance(api_key: str, api_secret: str, api_name: str): - """ - 验证API密钥和团队余额 - - 参数: - api_key: API密钥 - api_secret: API密钥 - api_name: API名称 - - 返回: - { - "success": bool, - "message": str - } - """ + try: # 获取当前用户(管理员)的API信息 admin_user = jingrow.session.user @@ -1645,21 +1632,7 @@ def verify_api_credentials_and_balance(api_key: str, api_secret: str, api_name: @jingrow.whitelist() def deduct_api_usage_fee(api_key: str, api_secret: str, api_name: str, usage_count: int = 1): - """ - 从API用户的团队扣除API调用费用 - - 参数: - api_key: API密钥 - api_secret: API密钥 - api_name: API名称 - usage_count: API使用次数,默认为1 - - 返回: - { - "success": bool, - "message": str - } - """ + try: # 获取当前用户(管理员) admin_user = jingrow.session.user @@ -1719,14 +1692,9 @@ def deduct_api_usage_fee(api_key: str, api_secret: str, api_name: str, usage_cou "message": "团队账户已禁用" } - # 获取团队对象 - team_pg = jingrow.get_pg("Team", team[0]) - - # 获取团队余额 - current_balance = team_pg.get_balance() - - # 获取API价格 + # 获取API价格及描述 price = jingrow.db.get_value("Api Pricing", {"api_name": api_name}, "price") or 0 + api_description = jingrow.db.get_value("Api Pricing", {"api_name": api_name}, "description") or api_name if price <= 0: return { @@ -1744,7 +1712,7 @@ def deduct_api_usage_fee(api_key: str, api_secret: str, api_name: str, usage_cou "type": "Adjustment", "source": "Prepaid Credits", "amount": -1 * float(total_price), # 使用负数表示扣减 - "description": f"API使用费: {api_name} x {usage_count}次", + "description": f"API使用费: {api_description} x {usage_count}次", }) # 保存交易记录