Hermes Agent 6dae1676ef feat: 新增商家产品商城页面(storefront)
- 左侧可收缩产品分类树
- 右侧产品列表(卡片式)和产品详情
- 未登录可浏览,登录后显示购买按钮
- 页面和API注册到load_path.py
2026-06-23 18:19:42 +08:00

57 lines
1.8 KiB
Plaintext

result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
product_id = params_kw.get('product_id', '')
if not product_id:
raise ValueError('缺少产品ID')
userid = await get_user()
if not userid:
raise ValueError('请先登录')
userorgid = await get_userorgid()
dbname = get_module_dbname('product_management')
async with DBPools().sqlorContext(dbname) as sor:
recs = await sor.sqlExe(
"SELECT * FROM product WHERE id = ${id}$ AND status = '1'",
{'id': product_id}
)
if not recs:
raise ValueError('产品不存在或已下架')
p = recs[0]
order_id = getID()
now = timestampstr()
order = {
'id': order_id,
'product_id': p.id,
'product_code': p.product_code or '',
'product_name': p.product_name or '',
'buyer_id': userid,
'buyer_org_id': userorgid or '0',
'quantity': 1,
'unit_price': float(p.price or 0),
'total_price': float(p.price or 0),
'currency': p.currency or 'CNY',
'status': 'pending',
'purchase_data': '{}',
'created_at': now,
'updated_at': now
}
await sor.C('purchase_orders', order)
result = {
'widgettype': 'Message',
'options': {
'title': '购买成功',
'message': f"已提交购买订单: {p.product_name},订单号: {order_id}",
'type': 'success',
'timeout': 5
}
}
except Exception as e:
result['options'] = {'title': '购买失败', 'message': str(e), 'type': 'error', 'timeout': 5}
return json.dumps(result, ensure_ascii=False)