#!/usr/bin/env python3 import json result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}} try: user_id = await get_user() org_id = (await get_userorgid()) or '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)