customer_management/wwwroot/api/customers_delete.dspy
yumoqing 469255afe7 sync: local modifications to customer_management
- Updated core.py
- Updated base.ui
- Added new API files: check_tables, customer_pool_list, customers CRUD, handover_list
- Added new UI/DSPY files: customer_edit, customer_list, customer_pool, handover_list
2026-04-28 18:51:23 +08:00

26 lines
1.1 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Customer delete API"""
import json
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
try:
record_id = params_kw.get('id', '').strip()
if not record_id:
result['options'] = {'title': 'Error', 'message': '记录ID不能为空', 'type': 'error'}
else:
dbname = get_module_dbname('customer_management')
async with DBPools().sqlorContext(dbname) as sor:
existing = await sor.sqlExe("SELECT id FROM customers WHERE id = ${id}$", {'id': record_id})
if not existing:
result['options'] = {'title': 'Error', 'message': '客户不存在', 'type': 'error'}
else:
await sor.sqlExe("DELETE FROM customers WHERE id = ${id}$", {'id': record_id})
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '删除成功', 'type': 'success'}}
except Exception as e:
result['options'] = {'title': 'Error', 'message': f'删除失败: {str(e)}', 'type': 'error'}
return json.dumps(result, ensure_ascii=False)