fix: 无默认方案时创建客户方案报错提示

This commit is contained in:
yumoqing 2026-06-30 11:35:25 +08:00
parent d08f6fb289
commit 9f4901c945

View File

@ -16,9 +16,7 @@ try:
data['customerid'] = customerid
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('discount', data)
# Copy default discount details (customerid=NULL) to this customer's plan
# Find default discount plan (all users)
default_sql = """
SELECT id FROM discount
WHERE resellerid = ${resellerid}$ AND customerid IS NULL
@ -26,20 +24,26 @@ try:
"""
default_recs = await sor.sqlExe(default_sql, {'resellerid': user_orgid})
if default_recs:
default_discountid = default_recs[0].id
detail_sql = "SELECT * FROM discount_detail WHERE discountid = ${did}$"
details = await sor.sqlExe(detail_sql, {'did': default_discountid})
if not default_recs:
result = {'widgettype': 'Error', 'options': {'title': '创建失败', 'message': '系统中没有全部用户的默认折扣方案,请先创建默认方案', 'timeout': 5}}
return result
for d in details or []:
await sor.C('discount_detail', {
'id': getID(),
'discountid': discountid,
'resellerid': user_orgid,
'prodtypeid': d.prodtypeid,
'productid': d.productid,
'discount': d.discount,
})
await sor.C('discount', data)
# Copy default discount details to this customer's plan
default_discountid = default_recs[0].id
detail_sql = "SELECT * FROM discount_detail WHERE discountid = ${did}$"
details = await sor.sqlExe(detail_sql, {'did': default_discountid})
for d in details or []:
await sor.C('discount_detail', {
'id': getID(),
'discountid': discountid,
'resellerid': user_orgid,
'prodtypeid': d.prodtypeid,
'productid': d.productid,
'discount': d.discount,
})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣方案创建成功,已复制默认产品折扣', 'type': 'success', 'timeout': 3}}