From 1cf2f62d741ee6edd1da5030c71f59ecaee97f4f Mon Sep 17 00:00:00 2001 From: ymq Date: Wed, 26 Aug 2026 17:11:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(product=5Faccounting):=20=E6=8A=98=E6=89=A3?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E6=AD=A3=E7=A1=AE=E6=A8=A1=E5=9E=8B=EF=BC=8C?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E5=8F=8C=E9=87=8D=E6=8A=98=E6=89=A3+?= =?UTF-8?q?=E6=8D=A2=E6=AD=A3=E7=A1=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 客户折扣: 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,不再基于含客户折扣的售价 --- product_management/core.py | 43 ++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/product_management/core.py b/product_management/core.py index c785b72..3a17dfa 100644 --- a/product_management/core.py +++ b/product_management/core.py @@ -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'): raise Exception(f'calculate_product_cost failed: {cost_result}') 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 prod_currency = 'CNY' @@ -1586,10 +1588,9 @@ WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1""" except Exception: chain = [ownerid] - # 7. Get customer discount (seller gives to customer) - cust_discount = await env.get_min_product_discount( - product_id, seller_orgid, userorgid) - customer_amount = cost_in_user * cust_discount + # 7. 客户售价:calculate_product_cost 的 amount 已含客户折扣(discount 模块), + # 这里不再重复乘,避免双重折扣。 + customer_amount = cost_in_user # 8. Build accounting items for each link in chain # 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') orderid = getID() - # Determine supplier discount (for last link to provider) - last_link_discount = 1.0 - try: - last_link_discount = await env.get_min_supplier_discount( - product_id, ownerid, providerid) # supplier discount from product owner - except Exception: - pass + # 供应商成本:calculate_product_cost 的 cost 已含 supplychain 供应商折扣(基于原价)。 + # 不用 discount 模块的 get_min_supplier_discount(供应商折扣归 supplychain 管)。 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, currency=user_currency, base_amount=round(customer_amount, 2), variable={"交易金额": customer_amount, "交易币种": user_currency, "交易手续费": 0})) - # PAY*: owner → supplier, amount = raw_cost * supplier_discount - supplier_amount = raw_cost * last_link_discount + # PAY*: owner → supplier, amount = supplier_cost(含 supplychain 供应商折扣) + supplier_amount = supplier_cost accounting_items.append(DictObject( action='PAY*', customerid=ownerid, resellerid=ownerid, 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})) else: # Middle link: PAY* + # 分销折扣从 supplychain 查(distribution_agreement_items), + # 不用 discount 模块的 get_min_distributor_discount。 next_orgid = chain[i + 1] - up_discount = 1.0 + link_amount = raw_cost try: - up_discount = await env.get_min_distributor_discount( - product_id, next_orgid, orgid) + sc = await env.calculate_sale_amounts(None, { + '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: pass - link_amount = raw_cost * up_discount accounting_items.append(DictObject( action='PAY*', customerid=orgid, resellerid=next_orgid, 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), variable={"分销结算": link_amount, "结算币种": prod_currency})) # Final PAY*: top of chain → supplier - supplier_amount = raw_cost * last_link_discount + supplier_amount = supplier_cost accounting_items.append(DictObject( action='PAY*', customerid=chain[0], resellerid=chain[0], providerid=providerid, biz_date=biz_date, timestamp=timestamp,