refactor: keep get_min_product_discount in discount, move llm_id_to_product_id to product_management
This commit is contained in:
parent
10fe38b4e0
commit
bb5cb57d89
@ -277,23 +277,9 @@ where discountid = ${discountid}$
|
||||
|
||||
|
||||
async def sor_get_min_product_discount(sor, product_id, resellerid, customerid):
|
||||
"""Find the minimum discount for a specific product from active discount records.
|
||||
|
||||
Searches all active discount records for the given (resellerid, customerid),
|
||||
including fallback to customerid=NULL and customerid='*' defaults.
|
||||
Returns the minimum discount value across all matching discount_detail rows.
|
||||
|
||||
Args:
|
||||
sor: sqlor context
|
||||
product_id: product.id
|
||||
resellerid: LLM owner's org id (discount.resellerid)
|
||||
customerid: user's org id (discount.customerid)
|
||||
|
||||
Returns: minimum discount value (float), 1.0 if no discount found.
|
||||
"""
|
||||
"""Find the minimum discount for a specific product from active discount records."""
|
||||
env = ServerEnv()
|
||||
biz_date = await env.get_business_date(sor)
|
||||
|
||||
sql = """SELECT dd.discount
|
||||
FROM discount_detail dd
|
||||
JOIN discount d ON dd.discountid = d.id
|
||||
@ -309,25 +295,15 @@ WHERE d.resellerid = ${resellerid}$
|
||||
'product_id': product_id,
|
||||
}
|
||||
recs = await sor.sqlExe(sql, ns)
|
||||
|
||||
if recs:
|
||||
discounts = [r.discount for r in recs if r.discount is not None]
|
||||
if discounts:
|
||||
return min(discounts)
|
||||
|
||||
return 1.0
|
||||
|
||||
|
||||
async def get_min_product_discount(product_id, resellerid, customerid):
|
||||
"""Get the minimum discount for a specific product (convenience wrapper).
|
||||
|
||||
Args:
|
||||
product_id: product.id
|
||||
resellerid: LLM owner's org id
|
||||
customerid: user's org id
|
||||
|
||||
Returns: minimum discount value (float), 1.0 if no discount found.
|
||||
"""
|
||||
"""Get the minimum discount for a specific product (convenience wrapper)."""
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname('discount')
|
||||
config = getConfig()
|
||||
@ -338,28 +314,6 @@ async def get_min_product_discount(product_id, resellerid, customerid):
|
||||
return 1.0
|
||||
|
||||
|
||||
async def llm_id_to_product_id(llm_id):
|
||||
"""Convert an LLM model ID (llmage.llm.id) to a product ID (sage.product.id).
|
||||
|
||||
Args:
|
||||
llm_id: llmage.llm.id
|
||||
|
||||
Returns: product.id or None if not found.
|
||||
"""
|
||||
env = ServerEnv()
|
||||
dbname = env.get_module_dbname('discount')
|
||||
config = getConfig()
|
||||
db = DBPools()
|
||||
db.databases = config.databases
|
||||
async with db.sqlorContext(dbname) as sor:
|
||||
sql = """SELECT id FROM product
|
||||
WHERE resource_ref_id = ${llm_id}$ AND product_type = 'llm_model' LIMIT 1"""
|
||||
recs = await sor.sqlExe(sql, {'llm_id': llm_id})
|
||||
if recs:
|
||||
return recs[0].id
|
||||
return None
|
||||
|
||||
|
||||
async def get_customer_discount(resellerid, customerid):
|
||||
"""Legacy: get default discount for a customer (all products)."""
|
||||
env = ServerEnv()
|
||||
@ -856,7 +810,6 @@ def load_discount():
|
||||
env.sor_get_product_discount = sor_get_product_discount
|
||||
env.sor_get_min_product_discount = sor_get_min_product_discount
|
||||
env.get_min_product_discount = get_min_product_discount
|
||||
env.llm_id_to_product_id = llm_id_to_product_id
|
||||
env.discount_qrcode = discount_qrcode
|
||||
env.set_promote_discount = set_promote_discount
|
||||
env.get_discount_details = get_discount_details
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user