From b81d1e0bfc187979ae79bfe3cd4720532ee195b9 Mon Sep 17 00:00:00 2001 From: ymq Date: Wed, 26 Aug 2026 15:47:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(discount):=20calculate=5Fproduct=5Fcost=20?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E5=AE=A2=E6=88=B7=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 成交价 = 资源真实定价 × 客户折扣(照 llmage 范式 get_customer_discount) 返回 amount(成交价)/original_amount(原价)/discount(折扣率) --- storage_resource/product_interface.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/storage_resource/product_interface.py b/storage_resource/product_interface.py index 05feeb9..03fc363 100644 --- a/storage_resource/product_interface.py +++ b/storage_resource/product_interface.py @@ -146,5 +146,18 @@ async def calculate_product_cost(resource_ref_id, usage_data, user_org_id=None): return {'success': False, 'message': '定价计算失败: %s' % e} amount = sum(getattr(p, 'amount', 0) for p in prices) - return {'success': True, 'amount': amount, 'original_amount': amount, - 'cost': 0.0, 'discount': 1.0, 'pricing_program_id': ppid} + + # 客户折扣:资源真实定价 × 客户折扣 = 成交价(照 llmage 范式) + discount = 1.0 + if user_org_id: + try: + d = await env.get_customer_discount( + getattr(spec, 'org_id', '') or '0', user_org_id) + if d not in (None, '', 0): + discount = float(d) + except Exception: + discount = 1.0 + + return {'success': True, 'amount': round(amount * discount, 6), + 'original_amount': round(amount, 6), + 'cost': 0.0, 'discount': discount, 'pricing_program_id': ppid}