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 %}