From d08f6fb289a1732a403ae409365de2b70a1467db Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 30 Jun 2026 11:30:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=A0=E9=99=A4=E6=8A=98=E6=89=A3?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E6=98=8E=E7=BB=86=E8=8F=9C=E5=8D=95;=20creat?= =?UTF-8?q?e=E6=A0=A1=E9=AA=8Ccustomerid=E5=B9=B6=E4=BB=8E=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=96=B9=E6=A1=88=E5=A4=8D=E5=88=B6detail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/discount_create.dspy | 43 +++++++++++++++++++++++++++----- wwwroot/menu.ui | 5 ---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/wwwroot/api/discount_create.dspy b/wwwroot/api/discount_create.dspy index 25d786f..1548244 100644 --- a/wwwroot/api/discount_create.dspy +++ b/wwwroot/api/discount_create.dspy @@ -1,19 +1,50 @@ -result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}} +result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error', 'timeout': 3}} try: user_orgid = (await get_userorgid()) or '0' - dbname = get_module_dbname('discount') + customerid = params_kw.get('customerid') + if not customerid: + result = {'widgettype': 'Error', 'options': {'title': '参数错误', 'message': '请选择客户后再创建折扣方案', 'timeout': 5}} + return result + + dbname = get_module_dbname('discount') data = dict(params_kw) - data['id'] = uuid() + discountid = getID() + data['id'] = discountid data['resellerid'] = user_orgid + data['customerid'] = customerid async with DBPools().sqlorContext(dbname) as sor: await sor.C('discount', data) - result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '折扣方案创建成功', 'type': 'success'}} + # Copy default discount details (customerid=NULL) to this customer's plan + default_sql = """ + SELECT id FROM discount + WHERE resellerid = ${resellerid}$ AND customerid IS NULL + ORDER BY enabled_date DESC LIMIT 1 + """ + 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}) + + 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}} except Exception as e: - result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'} + debug(f'discount_create error: {format_exc()}') + result['options'] = {'title': 'Error', 'message': f'创建失败: {str(e)}', 'type': 'error', 'timeout': 5} -return json.dumps(result, ensure_ascii=False) +return result diff --git a/wwwroot/menu.ui b/wwwroot/menu.ui index be7e3ca..24c187d 100644 --- a/wwwroot/menu.ui +++ b/wwwroot/menu.ui @@ -10,11 +10,6 @@ "label": "折扣管理", "url": "{{entire_url('discount_list/index.ui')}}" }, - { - "name":"discount_detail_list", - "label": "折扣产品明细", - "url": "{{entire_url('discount_detail_list/index.ui')}}" - }, { "name":"discount_marketing_list", "label": "营销方案",