促销码扫码流程: dspy端点改为UI公开入口,登录后绑定并跳转主页

- 新建 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()
This commit is contained in:
yumoqing 2026-07-06 13:34:25 +08:00
parent ceb997da09
commit 9bb5c9e506
4 changed files with 79 additions and 4 deletions

View File

@ -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')

View File

@ -98,6 +98,7 @@ PATHS_ANY = [
# 促销页:客户扫码用,无需登录
f"/{MOD}/promote",
f"/{MOD}/promote.dspy",
f"/{MOD}/promote/index.ui",
f"/{MOD}/generate_qr.dspy",
]

View File

@ -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}';"
}]
}
]
}

60
wwwroot/promote/index.ui Normal file
View File

@ -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": "<script>window.location.href='{{dspy_with_param}}';</script>"}
}
{% endif %}