咨询表单更新
This commit is contained in:
parent
414abb3619
commit
1c23d6d26f
@ -20,6 +20,9 @@ async def add_user_inquiry(ns={}):
|
||||
'name': ns.get('name'),
|
||||
'phone': ns.get('phone'),
|
||||
'company': ns.get('company'),
|
||||
'enterprise_type': ns.get('enterprise_type'),
|
||||
'region': ns.get('region'),
|
||||
'consult_direction': ns.get('consult_direction'),
|
||||
'email': ns.get('email')
|
||||
}
|
||||
await sor.C('product_inquiry', ns_c)
|
||||
|
||||
@ -12,6 +12,27 @@ async def search_user_inquiry(ns={}):
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
search_sql = """select * from product_inquiry where domain_name = '%s' and del_flg = '0' order by update_time desc;""" % domain_name
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
dict_sql = """select dict_type, dict_key, dict_value from product_inquiry_dict where status = 1 order by dict_type asc, sort_order asc;"""
|
||||
dict_result = await sor.sqlExe(dict_sql, {})
|
||||
dict_mapping = {}
|
||||
for dict_item in dict_result:
|
||||
dict_type = dict_item.get('dict_type')
|
||||
dict_mapping.setdefault(dict_type, {})[str(dict_item.get('dict_key'))] = dict_item.get('dict_value')
|
||||
|
||||
value_mapping = {
|
||||
'custom_type': {'0': '个人', '1': '企业'},
|
||||
'enterprise_type': dict_mapping.get('enterprise_type', {}),
|
||||
'region': dict_mapping.get('region', {}),
|
||||
'feedback': {'0': '未反馈', '1': '已反馈'}
|
||||
}
|
||||
for data_dic in result:
|
||||
for key, mapping in value_mapping.items():
|
||||
if key in data_dic:
|
||||
data_dic['%s_name' % key] = mapping.get(str(data_dic.get(key)), data_dic.get(key))
|
||||
direction_mapping = dict_mapping.get('direction', {})
|
||||
direction_keys = str(data_dic.get('consult_direction')).split(',') if data_dic.get('consult_direction') else []
|
||||
data_dic['consult_direction_name'] = ','.join([direction_mapping.get(direction_key.strip(), direction_key.strip()) for direction_key in direction_keys if direction_key.strip()])
|
||||
|
||||
if ns.get('to_excel') == '1':
|
||||
# 创建映射字段 导出execl
|
||||
# 结果转换成 中文名称:值 的字典列表
|
||||
@ -21,14 +42,13 @@ async def search_user_inquiry(ns={}):
|
||||
'phone': '联系人电话',
|
||||
'email': '邮箱',
|
||||
'company': '公司名称',
|
||||
'enterprise_type': '企业类型',
|
||||
'region': '所在区域',
|
||||
'consult_direction': '咨询方向',
|
||||
'content': '咨询内容',
|
||||
'feedback': '反馈状态',
|
||||
}
|
||||
# 新增值映射字典,集中管理各字段的数值转换规则
|
||||
value_mapping = {
|
||||
'custom_type': {'0': '个人', '1': '企业'},
|
||||
'feedback': {'0': '未反馈', '1': '已反馈'} # 根据表结构补充反馈状态映射
|
||||
}
|
||||
# 转换字典键为中文
|
||||
for data_dic in result:
|
||||
# 拆分后:显式循环结构(便于后续处理)
|
||||
@ -40,7 +60,11 @@ async def search_user_inquiry(ns={}):
|
||||
continue
|
||||
value = data_dic[key]
|
||||
chinese_key = field_mapping[key]
|
||||
if key in value_mapping:
|
||||
if key == 'consult_direction':
|
||||
direction_mapping = dict_mapping.get('direction', {})
|
||||
direction_keys = str(value).split(',') if value else []
|
||||
new_data_dic[chinese_key] = ','.join([direction_mapping.get(direction_key.strip(), direction_key.strip()) for direction_key in direction_keys if direction_key.strip()])
|
||||
elif key in value_mapping:
|
||||
mapped_value = value_mapping[key].get(str(value), value) # 若未找到对应映射,保留原始值
|
||||
new_data_dic[chinese_key] = mapped_value
|
||||
else:
|
||||
|
||||
16
b/product/search_user_inquiry_dict.dspy
Normal file
16
b/product/search_user_inquiry_dict.dspy
Normal file
@ -0,0 +1,16 @@
|
||||
async def search_user_inquiry_dict(ns={}):
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
where_sql = "where status = 1"
|
||||
if ns.get('dict_type'):
|
||||
where_sql += " and dict_type = '%s'" % ns.get('dict_type')
|
||||
search_sql = """select id, dict_type, dict_key, dict_value, sort_order from product_inquiry_dict %s order by dict_type asc, sort_order asc;""" % where_sql
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'search success',
|
||||
'data': result
|
||||
}
|
||||
|
||||
ret = await search_user_inquiry_dict(params_kw)
|
||||
return ret
|
||||
43
b/user_inquiry.txt
Normal file
43
b/user_inquiry.txt
Normal file
@ -0,0 +1,43 @@
|
||||
CREATE TABLE `product_inquiry` (
|
||||
`id` varchar(32) NOT NULL COMMENT '唯一标识符',
|
||||
`domain_name` varchar(64) NOT NULL COMMENT '所属域名',
|
||||
`publish_type` varchar(1) DEFAULT NULL COMMENT '发布商品1/ 发布需求2',
|
||||
`relate_id` varchar(32) DEFAULT NULL COMMENT '发布商品1/ 发布需求2',
|
||||
`content` varchar(1024) DEFAULT NULL COMMENT '咨询需求内容',
|
||||
`custom_type` tinyint(1) DEFAULT NULL COMMENT '客户类型(0-个人/1-企业)',
|
||||
`name` varchar(50) DEFAULT NULL COMMENT '联系人姓名',
|
||||
`phone` varchar(20) DEFAULT NULL COMMENT '联系电话',
|
||||
`company` varchar(100) DEFAULT NULL COMMENT '企业客户公司名称',
|
||||
`enterprise_type` tinyint(1) DEFAULT NULL COMMENT '企业类型(1-大型/2-中小企业/3-OPC个人/4-高校科研机构/5-政府/6-其他)',
|
||||
`region` tinyint(1) DEFAULT NULL COMMENT '所在区域(0-大陆/1-港澳台)',
|
||||
`consult_direction` varchar(20) DEFAULT NULL COMMENT '咨询方向(多选用逗号分隔:1,2,3)',
|
||||
`email` varchar(50) DEFAULT NULL COMMENT '电子邮箱',
|
||||
`feedback` varchar(1) DEFAULT '0' COMMENT '反馈状态',
|
||||
`del_flg` varchar(1) DEFAULT '0' COMMENT '删除标志(0-正常/1-已删除)',
|
||||
`update_time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
|
||||
`create_at` timestamp NULL DEFAULT current_timestamp() COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci ROW_FORMAT=DYNAMIC COMMENT='产品咨询表';
|
||||
|
||||
CREATE TABLE `product_inquiry_dict` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`dict_type` varchar(30) NOT NULL COMMENT '字典类型(标识属于哪一组选项)',
|
||||
`dict_key` tinyint(4) NOT NULL COMMENT '字典键值(对应数据库实际存储的数字)',
|
||||
`dict_value` varchar(50) NOT NULL COMMENT '字典显示名称(前端下拉框展示的文字)',
|
||||
`sort_order` int(11) DEFAULT 0 COMMENT '排序序号(数字越小越靠前)',
|
||||
`status` tinyint(1) DEFAULT 1 COMMENT '状态(0-禁用/1-启用)',
|
||||
`create_time` timestamp NOT NULL DEFAULT current_timestamp() COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='咨询表字典配置表(运营可维护)';
|
||||
product_inquiry_dict表相关数据:
|
||||
1 enterprise_type 1 大型企业 1 1 2026-07-07 16:32:45
|
||||
2 enterprise_type 2 中小企业 2 1 2026-07-07 16:32:45
|
||||
3 enterprise_type 3 OPC个人 3 1 2026-07-07 16:32:45
|
||||
4 enterprise_type 4 高校科研机构 4 1 2026-07-07 16:32:45
|
||||
5 enterprise_type 5 政府 5 1 2026-07-07 16:32:45
|
||||
6 enterprise_type 6 其他 6 1 2026-07-07 16:32:45
|
||||
7 region 0 大陆 1 1 2026-07-07 16:34:02
|
||||
8 region 1 港澳台 2 1 2026-07-07 16:34:02
|
||||
9 direction 1 AI Infra 基础设施(云/网/算) 1 1 2026-07-07 16:34:02
|
||||
10 direction 2 AI Agent 智能体(产品开发) 2 1 2026-07-07 16:34:02
|
||||
11 direction 3 AI Builder 炼智师(能力提升培训) 3 1 2026-07-07 16:34:02
|
||||
Loading…
x
Reference in New Issue
Block a user