feat(discount): calculate_product_cost 接入客户折扣
成交价 = 资源真实定价 × 客户折扣(照 llmage 范式 get_customer_discount) 返回 amount(成交价)/original_amount(原价)/discount(折扣率)
This commit is contained in:
parent
5fa0e92a6a
commit
ac72f6a56d
@ -173,5 +173,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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user