From 9bb5c9e506c57dec3aa95eb21a6119dc0bf489a4 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 6 Jul 2026 13:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=83=E9=94=80=E7=A0=81=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E6=B5=81=E7=A8=8B:=20dspy=E7=AB=AF=E7=82=B9=E6=94=B9=E4=B8=BAU?= =?UTF-8?q?I=E5=85=AC=E5=BC=80=E5=85=A5=E5=8F=A3=EF=BC=8C=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=90=8E=E7=BB=91=E5=AE=9A=E5=B9=B6=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新建 promote/index.ui: 公开入口,未登录显示登录按钮,已登录自动跳dspy - QR URL 改为 promote/index.ui (原 promote.dspy) - load_path.py 注册 promote/index.ui 为 any 角色 - index.dspy 绑定成功后显示返回首页按钮跳转主页 - 修复 generate_promo_code sale_id: get_user() -> get_userid() --- discount/init.py | 4 +-- scripts/load_path.py | 1 + wwwroot/promote/index.dspy | 18 ++++++++++-- wwwroot/promote/index.ui | 60 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 wwwroot/promote/index.ui diff --git a/discount/init.py b/discount/init.py index 71e31e3..0c13652 100644 --- a/discount/init.py +++ b/discount/init.py @@ -490,7 +490,7 @@ async def generate_promo_code(request, params_kw): env = ServerEnv() dbname = env.get_module_dbname('discount') resellerid = await env.get_userorgid() - sale_id = await env.get_user() + sale_id = await env.get_userid() marketing_id = params_kw.get('marketing_id') # can be empty async with DBPools().sqlorContext(dbname) as sor: @@ -555,7 +555,7 @@ async def generate_promo_qr(request, params_kw): return {'widgettype': 'Message', 'options': {'title': 'Error', 'message': f'Promo code {promo_id} not found', 'type': 'error'}} config = getConfig() - qr_url = env.entire_url('./promote.dspy') + f'?code={promo_id}' + qr_url = env.entire_url('./promote/index.ui') + f'?code={promo_id}' fs = FileStorage() p = fs._name2path(f'{_getID()}.png') gen_qr_withlogo(qr_url, p, logopath=config.logopath, logoloc='cc') diff --git a/scripts/load_path.py b/scripts/load_path.py index f79013f..ae0373c 100644 --- a/scripts/load_path.py +++ b/scripts/load_path.py @@ -98,6 +98,7 @@ PATHS_ANY = [ # 促销页:客户扫码用,无需登录 f"/{MOD}/promote", f"/{MOD}/promote.dspy", + f"/{MOD}/promote/index.ui", f"/{MOD}/generate_qr.dspy", ] diff --git a/wwwroot/promote/index.dspy b/wwwroot/promote/index.dspy index e92f860..bb76d51 100644 --- a/wwwroot/promote/index.dspy +++ b/wwwroot/promote/index.dspy @@ -63,14 +63,28 @@ elif code: bind_params = params_kw.copy() bind_params['promo_code_id'] = code ret = await bind_customer(request, bind_params) + home_url = env.entire_url('/') if ret.get('status') == 'success': result = { "widgettype": "VBox", "options": {"width": "100%", "height": "100%", "spacing": 16, "padding": "20px"}, "subwidgets": [ { - "widgettype": "Message", - "options": {"title": "激活成功", "message": f"促销码 {code} 已成功激活,您已成为我们的客户!", "type": "success"} + "widgettype": "Title", + "options": {"otext": "激活成功", "level": 2, "i18n": True} + }, + { + "widgettype": "Text", + "options": {"text": f"促销码 {code} 已成功激活,即将跳转首页..."} + }, + { + "widgettype": "Button", + "options": {"label": "返回首页", "css": "primary"}, + "binds": [{ + "wid": "self", "event": "click", + "actiontype": "script", "target": "self", + "script": f"window.location.href='{home_url}';" + }] } ] } diff --git a/wwwroot/promote/index.ui b/wwwroot/promote/index.ui new file mode 100644 index 0000000..e7f656f --- /dev/null +++ b/wwwroot/promote/index.ui @@ -0,0 +1,60 @@ +{% set user = get_user() %} +{% set code = params_kw.get('code', '') %} +{% set qr_id = params_kw.get('id', '') %} +{% if code %} +{% set dspy_with_param = entire_url('./index.dspy') + '?code=' + code %} +{% elif qr_id %} +{% set dspy_with_param = entire_url('./index.dspy') + '?id=' + qr_id %} +{% else %} +{% set dspy_with_param = entire_url('./index.dspy') %} +{% endif %} +{% set login_back = entire_url('/rbac/user/login') + '?back=' + dspy_with_param %} +{% set register_back = entire_url('/rbac/user/register') + '?back=' + dspy_with_param %} +{% if not user %} +{ + "widgettype": "VBox", + "options": {"width": "100%", "height": "100%", "spacing": 16, "padding": "20px"}, + "subwidgets": [ + { + "widgettype": "Title", + "options": {"otext": "请先登录或注册", "level": 2, "i18n": true} + }, + { + "widgettype": "Text", + "options": {"otext": "使用促销码需要先登录,登录后将自动为您激活。", "i18n": true} + }, + { + "widgettype": "HBox", + "options": {"spacing": 10, "cheight": 3}, + "subwidgets": [ + { + "widgettype": "Button", + "options": {"label": "登录", "css": "primary"}, + "binds": [{ + "wid": "self", "event": "click", + "actiontype": "script", "target": "self", + "script": "window.location.href='{{login_back}}';" + }] + } + {% if not code %} + , + { + "widgettype": "Button", + "options": {"label": "注册", "css": "secondary"}, + "binds": [{ + "wid": "self", "event": "click", + "actiontype": "script", "target": "self", + "script": "window.location.href='{{register_back}}';" + }] + } + {% endif %} + ] + } + ] +} +{% else %} +{ + "widgettype": "Text", + "options": {"text": ""} +} +{% endif %}