fix: 用dspy原生bare function(get_user/entire_url/bind_customer),去掉env间接调用

This commit is contained in:
yumoqing 2026-07-06 14:41:20 +08:00
parent 79494622b9
commit 2bbe82fd23

View File

@ -2,19 +2,18 @@
# 参数: code=促销码id 或 id=discount_qr id
# 已登录: 直接绑定; 未登录: 提示登录/注册
env = request._run_ns
code = params_kw.get('code', '')
qr_id = params_kw.get('id', '')
user = await env.get_user()
user = await get_user()
if not user:
# 未登录 - 显示登录/注册引导
back_url = ''
if code:
back_url = env.entire_url('./promote/index.dspy') + f'?code={code}'
back_url = entire_url('./promote/index.dspy') + f'?code={code}'
elif qr_id:
back_url = env.entire_url('./promote/index.dspy') + f'?id={qr_id}'
back_url = entire_url('./promote/index.dspy') + f'?id={qr_id}'
result = {
"widgettype": "VBox",
@ -38,7 +37,7 @@ if not user:
"label": "登录",
"css": "primary",
"actiontype": "link",
"url": env.entire_url('/rbac/user/login.ui') + f"?back={back_url}" if back_url else env.entire_url('/rbac/user/login.ui')
"url": entire_url('/rbac/user/login.ui') + f"?back={back_url}" if back_url else entire_url('/rbac/user/login.ui')
}
},
{
@ -47,7 +46,7 @@ if not user:
"label": "注册",
"css": "secondary",
"actiontype": "link",
"url": env.entire_url('/rbac/user/register') + f"?back={back_url}" if back_url else env.entire_url('/rbac/user/register')
"url": entire_url('/rbac/user/register') + f"?back={back_url}" if back_url else entire_url('/rbac/user/register')
}
}
]
@ -57,11 +56,10 @@ if not user:
elif code:
# 已登录 + 促销码参数 - 绑定促销码
try:
# bind_customer expects promo_code_id
bind_params = params_kw.copy()
bind_params['promo_code_id'] = code
ret = await bind_customer(request, bind_params)
home_url = env.entire_url('/')
home_url = entire_url('/')
if ret.get('status') == 'success':
result = {
"widgettype": "VBox",