From 9f4901c9451ebd840b65a2f0f21958a2204ebee0 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 30 Jun 2026 11:35:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=A0=E9=BB=98=E8=AE=A4=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E6=97=B6=E5=88=9B=E5=BB=BA=E5=AE=A2=E6=88=B7=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E6=8A=A5=E9=94=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/discount_create.dspy | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/wwwroot/api/discount_create.dspy b/wwwroot/api/discount_create.dspy index 1548244..619ffc7 100644 --- a/wwwroot/api/discount_create.dspy +++ b/wwwroot/api/discount_create.dspy @@ -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}}