product_management/wwwroot/api/product_delete.dspy
yumoqing 4fd136bf53 refactor: reseller org_id isolation for product_management module
- product_category: org_id scoped tree, product_table_name -> product_type
- product: org_id scoped, added extra_json for custom attributes, product_type field
- product_type_config: org_id + operator_id dual isolation, unique key on (org_id, operator_id, category_id, config_name)
- All 18 API endpoints enforce org_id filtering via ServerEnv
- core.py: all methods accept optional org_id, default to current user's org
- CRUD definitions: logined_userorgid set to org_id on all lists
- init/data.json: removed hardcoded global categories (managed per reseller)
- Rebuilt mysql.ddl.sql and all CRUD UI files
2026-05-25 17:03:08 +08:00

34 lines
1.1 KiB
Python

#!/usr/bin/env python3
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_id = await get_user()
from ahserver.serverenv import ServerEnv
env = ServerEnv()
org_id = getattr(env, 'orgid', None) or getattr(env, 'org_id', '0')
dbname = get_module_dbname('product_management')
data = dict(params_kw)
record_id = data.get('id')
if not record_id:
raise ValueError('Missing id')
async with DBPools().sqlorContext(dbname) as sor:
check = await sor.sqlExe(
"SELECT id FROM product WHERE id = ${id}$ AND org_id = ${org_id}$",
{'id': record_id, 'org_id': org_id}
)
if not check:
raise ValueError('无权删除该记录')
await sor.D('product', {'id': record_id, 'org_id': org_id})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '产品删除成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': '删除失败: ' + str(e), 'type': 'error'}
return json.dumps(result, ensure_ascii=False)