fix: env = request._run_ns 替代 ServerEnv(),修复dspy中get_user返回None

This commit is contained in:
yumoqing 2026-07-06 14:39:44 +08:00
parent 5762e1c361
commit 79494622b9

View File

@ -2,21 +2,19 @@
# 参数: code=促销码id 或 id=discount_qr id
# 已登录: 直接绑定; 未登录: 提示登录/注册
from ahserver.serverenv import ServerEnv
env = request._run_ns
code = params_kw.get('code', '')
qr_id = params_kw.get('id', '')
env = ServerEnv()
user = await env.get_user()
if not user:
# 未登录 - 显示登录/注册引导
back_url = ''
if code:
back_url = env.entire_url('./promote') + f'?code={code}'
back_url = env.entire_url('./promote/index.dspy') + f'?code={code}'
elif qr_id:
back_url = env.entire_url('./promote') + f'?id={qr_id}'
back_url = env.entire_url('./promote/index.dspy') + f'?id={qr_id}'
result = {
"widgettype": "VBox",