fix: dataurl改为/appbase/get_code.dspy,补全CRUD API

- json/discount_list.json: dataurl→/appbase/, resellerid隐藏+自动填充, customerid保留下拉
- json/discount_detail_list.json: dataurl→/appbase/
- 新增6个API: discount和discount_detail的create/update/delete
- load_path.py: 注册新API路径到logined和operator
This commit is contained in:
Hermes Agent 2026-06-24 01:40:54 +08:00
parent 1ba7e0e031
commit 0fcc34c235
9 changed files with 204 additions and 85 deletions

View File

@ -1,52 +1,62 @@
{
"tblname": "discount_detail",
"alias": "discount_detail_list",
"title": "折扣产品明细",
"params": {
"sortby": ["prodtypeid", "productid"],
"browserfields": {
"exclouded": ["id", "resellerid"],
"alters": {
"discountid": {
"uitype": "code",
"dataurl": "/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "discount",
"tblvalue": "id",
"tbltext": "name"
}
},
"prodtypeid": {
"uitype": "code",
"dataurl": "/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "prodtype",
"tblvalue": "id",
"tbltext": "name"
}
},
"productid": {
"uitype": "code",
"dataurl": "/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "product",
"tblvalue": "id",
"tbltext": "name"
}
}
}
"tblname": "discount_detail",
"alias": "discount_detail_list",
"title": "折扣产品明细",
"params": {
"sortby": [
"prodtypeid",
"productid"
],
"browserfields": {
"exclouded": [
"id",
"resellerid"
],
"alters": {
"discountid": {
"uitype": "code",
"dataurl": "/appbase/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "discount",
"tblvalue": "id",
"tbltext": "name"
}
},
"editexclouded": ["id", "discountid", "resellerid"],
"editable": {
"new_data_url": "{{entire_url('../api/discount_detail_create.dspy')}}",
"update_data_url": "{{entire_url('../api/discount_detail_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/discount_detail_delete.dspy')}}"
"prodtypeid": {
"uitype": "code",
"dataurl": "/appbase/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "prodtype",
"tblvalue": "id",
"tbltext": "name"
}
},
"productid": {
"uitype": "code",
"dataurl": "/appbase/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "product",
"tblvalue": "id",
"tbltext": "name"
}
}
}
},
"editexclouded": [
"id",
"discountid",
"resellerid"
],
"editable": {
"new_data_url": "{{entire_url('../api/discount_detail_create.dspy')}}",
"update_data_url": "{{entire_url('../api/discount_detail_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/discount_detail_delete.dspy')}}"
}
}
}

View File

@ -1,41 +1,39 @@
{
"tblname": "discount",
"alias": "discount_list",
"title": "折扣管理",
"params": {
"sortby": ["enabled_date desc"],
"browserfields": {
"exclouded": ["id"],
"alters": {
"resellerid": {
"uitype": "code",
"dataurl": "/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "organization",
"tblvalue": "id",
"tbltext": "orgname"
}
},
"customerid": {
"uitype": "code",
"dataurl": "/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "organization",
"tblvalue": "id",
"tbltext": "orgname"
}
}
}
},
"editexclouded": ["id"],
"editable": {
"new_data_url": "{{entire_url('../api/discount_create.dspy')}}",
"update_data_url": "{{entire_url('../api/discount_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/discount_delete.dspy')}}"
"tblname": "discount",
"alias": "discount_list",
"title": "折扣管理",
"params": {
"sortby": [
"enabled_date desc"
],
"browserfields": {
"exclouded": [
"id",
"resellerid"
],
"alters": {
"customerid": {
"uitype": "code",
"dataurl": "/appbase/get_code.dspy",
"datamethod": "GET",
"dataparams": {
"dbname": "sage",
"table": "organization",
"tblvalue": "id",
"tbltext": "orgname"
}
}
}
}
},
"editexclouded": [
"id",
"resellerid"
],
"editable": {
"new_data_url": "{{entire_url('../api/discount_create.dspy')}}",
"update_data_url": "{{entire_url('../api/discount_update.dspy')}}",
"delete_data_url": "{{entire_url('../api/discount_delete.dspy')}}"
},
"logined_userorgid": "resellerid"
}
}

View File

@ -101,6 +101,12 @@ PATHS_LOGINED = [
f"/{MOD}/discount_customer_bind_list/update_discount_customer_bind.dspy",
f"/{MOD}/discount_customer_bind_list/delete_discount_customer_bind.dspy",
# CRUD API (json/ defined)
f"/{MOD}/api/discount_create.dspy",
f"/{MOD}/api/discount_update.dspy",
f"/{MOD}/api/discount_delete.dspy",
f"/{MOD}/api/discount_detail_create.dspy",
f"/{MOD}/api/discount_detail_update.dspy",
f"/{MOD}/api/discount_detail_delete.dspy",
f"/{MOD}/api/marketing_create.dspy",
f"/{MOD}/api/marketing_update.dspy",
f"/{MOD}/api/marketing_delete.dspy",
@ -158,6 +164,13 @@ PATHS_OPERATOR = [
f"/{MOD}/api/customer_bind_create.dspy",
f"/{MOD}/api/customer_bind_update.dspy",
f"/{MOD}/api/customer_bind_delete.dspy",
# 折扣方案和明细 API
f"/{MOD}/api/discount_create.dspy",
f"/{MOD}/api/discount_update.dspy",
f"/{MOD}/api/discount_delete.dspy",
f"/{MOD}/api/discount_detail_create.dspy",
f"/{MOD}/api/discount_detail_update.dspy",
f"/{MOD}/api/discount_detail_delete.dspy",
]
# 角色专属权限 — sale 可查看促销码和客户归属

View File

@ -0,0 +1,19 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_orgid = (await get_userorgid()) or '0'
dbname = get_module_dbname('discount')
data = dict(params_kw)
data['id'] = getID()
data['resellerid'] = user_orgid
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('discount', data)
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)

View File

@ -0,0 +1,15 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('discount')
id = params_kw.get('id')
async with DBPools().sqlorContext(dbname) as sor:
await sor.D('discount', {'id': 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)

View File

@ -0,0 +1,19 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
user_orgid = (await get_userorgid()) or '0'
dbname = get_module_dbname('discount')
data = dict(params_kw)
data['id'] = getID()
data['resellerid'] = user_orgid
async with DBPools().sqlorContext(dbname) as sor:
await sor.C('discount_detail', data)
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)

View File

@ -0,0 +1,15 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
dbname = get_module_dbname('discount')
id = params_kw.get('id')
async with DBPools().sqlorContext(dbname) as sor:
await sor.D('discount_detail', {'id': 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)

View File

@ -0,0 +1,15 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
data = dict(params_kw)
dbname = get_module_dbname('discount')
async with DBPools().sqlorContext(dbname) as sor:
await sor.U('discount_detail', data)
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)

View File

@ -0,0 +1,15 @@
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
try:
data = dict(params_kw)
dbname = get_module_dbname('discount')
async with DBPools().sqlorContext(dbname) as sor:
await sor.U('discount', data)
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)