From 031a0eb967f34058f6c8df62728b4e53ab62a997 Mon Sep 17 00:00:00 2001 From: jingrow Date: Tue, 6 May 2025 19:32:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96API=E6=89=A3=E8=B4=B9?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jcloud/api/account.py | 42 +++++------------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) 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}次", }) # 保存交易记录