fix: 客户折扣不得高于全部用户折扣
This commit is contained in:
parent
1b20b28e7e
commit
9d4c83a25f
@ -1,5 +1,5 @@
|
||||
# Upsert折扣明细:对比old_discount和discount,不同才更新
|
||||
# 参数: discountid, productid, discount, old_discount, detail_id(可选)
|
||||
# 客户折扣不得高于全部用户折扣
|
||||
|
||||
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error', 'timeout': 3}}
|
||||
|
||||
@ -47,6 +47,26 @@ try:
|
||||
return result
|
||||
|
||||
async with DBPools().sqlorContext(dbname) as sor:
|
||||
# 检查是否客户专属折扣方案:如果是,验证折扣不高于全部用户折扣
|
||||
disc_sql = "SELECT customerid, resellerid FROM discount WHERE id = ${id}$"
|
||||
disc_recs = await sor.sqlExe(disc_sql, {'id': discountid})
|
||||
if disc_recs and disc_recs[0].customerid:
|
||||
# 查找全部用户默认方案的同一产品折扣
|
||||
default_sql = """
|
||||
SELECT dd.discount FROM discount_detail dd
|
||||
JOIN discount d ON dd.discountid = d.id
|
||||
WHERE d.resellerid = ${resellerid}$ AND d.customerid IS NULL
|
||||
AND dd.productid = ${productid}$
|
||||
LIMIT 1
|
||||
"""
|
||||
default_recs = await sor.sqlExe(default_sql, {'resellerid': disc_recs[0].resellerid, 'productid': productid})
|
||||
if default_recs and default_recs[0].discount is not None:
|
||||
default_d = float(default_recs[0].discount)
|
||||
customer_d = float(discount_val)
|
||||
if customer_d > default_d:
|
||||
result = {'widgettype': 'Error', 'options': {'title': '折扣无效', 'message': f'客户折扣({customer_d})不能高于全部用户折扣({default_d})', 'timeout': 5}}
|
||||
return result
|
||||
|
||||
if detail_id:
|
||||
await sor.U('discount_detail', {
|
||||
'id': detail_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user