product_management/wwwroot/storefront/api/purchase_realtime.dspy
yumoqing ff501c13b5 fix(purchase): user_org_id获取崩溃——DictObject的hasattr恒True导致await None()
- dspy侧显式取get_userorgid()传入(与purchase_confirm同款)
- core侧hasattr判断改callable检查,兜底_get_current_org_id
2026-08-28 17:09:33 +08:00

45 lines
1.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 实时支付接口:点击确认支付 → purchase_realtime算价→余额预检→计费→实时记账→开权益
from ahserver.serverenv import ServerEnv
result = {'widgettype': 'Message', 'options': {
'title': '支付失败', 'message': '未知错误', 'type': 'error', 'timeout': 5}}
try:
userid = await get_user()
if not userid:
raise Exception('请先登录')
product_id = params_kw.get('product_id', '')
if not product_id:
raise Exception('缺少产品ID')
env = ServerEnv()
user_org_id = (await get_userorgid()) or '0'
r = await env.purchase_realtime(
product_id=product_id,
user_id=userid,
user_org_id=user_org_id,
charge_mode=params_kw.get('charge_mode') or None,
quantity=int(params_kw.get('quantity', 1) or 1),
storage_gb=float(params_kw.get('storage_gb', 0) or 0),
valid_months=int(params_kw.get('valid_months', 1) or 1))
if not r.get('success'):
raise Exception(r.get('message', '支付失败'))
result = {
'widgettype': 'Message',
'options': {
'title': '支付成功',
'type': 'success',
'timeout': 6,
'message': ('%s 购买成功,实付 ¥%.2f,订单号 %s权益有效期至 %s已实时记账'
% (r.get('product_name', ''), r.get('amount', 0),
r.get('orderid', ''), r.get('end_date', '')))
}
}
except Exception as e:
debug(f'purchase_realtime.dspy error: {format_exc()}')
result['options']['message'] = str(e)
return json.dumps(result, ensure_ascii=False)