fix(product_accounting): 折扣对齐正确模型,消除双重折扣+换正确模块
- 客户折扣: calculate_product_cost 的 amount 已含客户折扣,product_accounting 不再重复乘 - 供应商成本: 用 cost_result['cost'](含 supplychain 供应商折扣,基于原价),不用 discount 模块的 get_min_supplier_discount - 分销折扣: 用 supplychain calculate_sale_amounts 的 distribution_amount,不用 get_min_distributor_discount - 供应商成本基于原价 original_amount,不再基于含客户折扣的售价
This commit is contained in:
parent
7852583739
commit
1cf2f62d74
@ -1543,6 +1543,8 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
if not cost_result or not cost_result.get('success'):
|
if not cost_result or not cost_result.get('success'):
|
||||||
raise Exception(f'calculate_product_cost failed: {cost_result}')
|
raise Exception(f'calculate_product_cost failed: {cost_result}')
|
||||||
raw_cost = cost_result.get('amount', 0)
|
raw_cost = cost_result.get('amount', 0)
|
||||||
|
original_amount = cost_result.get('original_amount', 0) or raw_cost
|
||||||
|
supplier_cost = cost_result.get('cost', 0) or raw_cost
|
||||||
|
|
||||||
# 4b. Get product currency
|
# 4b. Get product currency
|
||||||
prod_currency = 'CNY'
|
prod_currency = 'CNY'
|
||||||
@ -1586,10 +1588,9 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
except Exception:
|
except Exception:
|
||||||
chain = [ownerid]
|
chain = [ownerid]
|
||||||
|
|
||||||
# 7. Get customer discount (seller gives to customer)
|
# 7. 客户售价:calculate_product_cost 的 amount 已含客户折扣(discount 模块),
|
||||||
cust_discount = await env.get_min_product_discount(
|
# 这里不再重复乘,避免双重折扣。
|
||||||
product_id, seller_orgid, userorgid)
|
customer_amount = cost_in_user
|
||||||
customer_amount = cost_in_user * cust_discount
|
|
||||||
|
|
||||||
# 8. Build accounting items for each link in chain
|
# 8. Build accounting items for each link in chain
|
||||||
# Chain: product_owner → ... → seller
|
# Chain: product_owner → ... → seller
|
||||||
@ -1598,13 +1599,8 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
|
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
orderid = getID()
|
orderid = getID()
|
||||||
|
|
||||||
# Determine supplier discount (for last link to provider)
|
# 供应商成本:calculate_product_cost 的 cost 已含 supplychain 供应商折扣(基于原价)。
|
||||||
last_link_discount = 1.0
|
# 不用 discount 模块的 get_min_supplier_discount(供应商折扣归 supplychain 管)。
|
||||||
try:
|
|
||||||
last_link_discount = await env.get_min_supplier_discount(
|
|
||||||
product_id, ownerid, providerid) # supplier discount from product owner
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
accounting_items = []
|
accounting_items = []
|
||||||
|
|
||||||
@ -1619,8 +1615,8 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
productid=product_id, transamt=customer_amount,
|
productid=product_id, transamt=customer_amount,
|
||||||
currency=user_currency, base_amount=round(customer_amount, 2),
|
currency=user_currency, base_amount=round(customer_amount, 2),
|
||||||
variable={"交易金额": customer_amount, "交易币种": user_currency, "交易手续费": 0}))
|
variable={"交易金额": customer_amount, "交易币种": user_currency, "交易手续费": 0}))
|
||||||
# PAY*: owner → supplier, amount = raw_cost * supplier_discount
|
# PAY*: owner → supplier, amount = supplier_cost(含 supplychain 供应商折扣)
|
||||||
supplier_amount = raw_cost * last_link_discount
|
supplier_amount = supplier_cost
|
||||||
accounting_items.append(DictObject(
|
accounting_items.append(DictObject(
|
||||||
action='PAY*', customerid=ownerid, resellerid=ownerid,
|
action='PAY*', customerid=ownerid, resellerid=ownerid,
|
||||||
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
||||||
@ -1643,14 +1639,25 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
variable={"交易金额": customer_amount, "交易币种": user_currency, "交易手续费": 0}))
|
variable={"交易金额": customer_amount, "交易币种": user_currency, "交易手续费": 0}))
|
||||||
else:
|
else:
|
||||||
# Middle link: PAY*
|
# Middle link: PAY*
|
||||||
|
# 分销折扣从 supplychain 查(distribution_agreement_items),
|
||||||
|
# 不用 discount 模块的 get_min_distributor_discount。
|
||||||
next_orgid = chain[i + 1]
|
next_orgid = chain[i + 1]
|
||||||
up_discount = 1.0
|
link_amount = raw_cost
|
||||||
try:
|
try:
|
||||||
up_discount = await env.get_min_distributor_discount(
|
sc = await env.calculate_sale_amounts(None, {
|
||||||
product_id, next_orgid, orgid)
|
'resellerid': next_orgid,
|
||||||
|
'sub_reseller_id': orgid,
|
||||||
|
'productid': product_id,
|
||||||
|
'prodtypeid': '',
|
||||||
|
'quantity': 1,
|
||||||
|
'unit_price': original_amount,
|
||||||
|
})
|
||||||
|
if sc:
|
||||||
|
scd = json.loads(sc) if isinstance(sc, str) else sc
|
||||||
|
scd = scd.get('data', {}) if isinstance(scd, dict) else {}
|
||||||
|
link_amount = float(scd.get('distribution_amount', raw_cost) or raw_cost)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
link_amount = raw_cost * up_discount
|
|
||||||
accounting_items.append(DictObject(
|
accounting_items.append(DictObject(
|
||||||
action='PAY*', customerid=orgid, resellerid=next_orgid,
|
action='PAY*', customerid=orgid, resellerid=next_orgid,
|
||||||
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
||||||
@ -1658,7 +1665,7 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
|||||||
currency=prod_currency, base_amount=round(link_amount, 2),
|
currency=prod_currency, base_amount=round(link_amount, 2),
|
||||||
variable={"分销结算": link_amount, "结算币种": prod_currency}))
|
variable={"分销结算": link_amount, "结算币种": prod_currency}))
|
||||||
# Final PAY*: top of chain → supplier
|
# Final PAY*: top of chain → supplier
|
||||||
supplier_amount = raw_cost * last_link_discount
|
supplier_amount = supplier_cost
|
||||||
accounting_items.append(DictObject(
|
accounting_items.append(DictObject(
|
||||||
action='PAY*', customerid=chain[0], resellerid=chain[0],
|
action='PAY*', customerid=chain[0], resellerid=chain[0],
|
||||||
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
providerid=providerid, biz_date=biz_date, timestamp=timestamp,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user