From 9d4c83a25f96056c271f89b2c1010d7338dc84f9 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 30 Jun 2026 14:20:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=A2=E6=88=B7=E6=8A=98=E6=89=A3?= =?UTF-8?q?=E4=B8=8D=E5=BE=97=E9=AB=98=E4=BA=8E=E5=85=A8=E9=83=A8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=8A=98=E6=89=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/discount_setting/save_discount.dspy | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wwwroot/discount_setting/save_discount.dspy b/wwwroot/discount_setting/save_discount.dspy index 2778a1a..ecee3bc 100644 --- a/wwwroot/discount_setting/save_discount.dspy +++ b/wwwroot/discount_setting/save_discount.dspy @@ -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,