咨询表单 查找更新
This commit is contained in:
parent
4dfa04560c
commit
be9e1efacf
@ -10,7 +10,50 @@ async def search_user_inquiry(ns={}):
|
|||||||
|
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
async with db.sqlorContext('kboss') as sor:
|
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
|
where_conditions = ["domain_name = '%s'" % domain_name, "del_flg = '0'"]
|
||||||
|
if ns.get('name'):
|
||||||
|
where_conditions.append("name like '%%%%%s%%%%'" % ns.get('name'))
|
||||||
|
if ns.get('phone'):
|
||||||
|
where_conditions.append("phone like '%%%%%s%%%%'" % ns.get('phone'))
|
||||||
|
if ns.get('email'):
|
||||||
|
where_conditions.append("email like '%%%%%s%%%%'" % ns.get('email'))
|
||||||
|
if ns.get('source'):
|
||||||
|
if ns.get('source') == '未知':
|
||||||
|
where_conditions.append("(source is null or source = '')")
|
||||||
|
else:
|
||||||
|
where_conditions.append("source = '%s'" % ns.get('source'))
|
||||||
|
if ns.get('feedback'):
|
||||||
|
where_conditions.append("feedback = '%s'" % ns.get('feedback'))
|
||||||
|
where_clause = ' and '.join(where_conditions)
|
||||||
|
|
||||||
|
# 分页参数
|
||||||
|
page = int(ns.get('page', 1))
|
||||||
|
page_size = int(ns.get('page_size', 20))
|
||||||
|
offset = (page - 1) * page_size
|
||||||
|
|
||||||
|
# 统计查询(基于全部符合条件的数据)
|
||||||
|
count_sql = """select count(*) as cnt from product_inquiry where %s""" % where_clause
|
||||||
|
total_count = (await sor.sqlExe(count_sql, {}))[0]['cnt']
|
||||||
|
|
||||||
|
source_sql = """select source, count(*) as cnt from product_inquiry where %s group by source""" % where_clause
|
||||||
|
source_result = await sor.sqlExe(source_sql, {})
|
||||||
|
source_stats = {}
|
||||||
|
for row in source_result:
|
||||||
|
src = row.get('source') or '未知'
|
||||||
|
source_stats[src] = row.get('cnt')
|
||||||
|
|
||||||
|
pending_sql = """select count(*) as cnt from product_inquiry where %s and feedback = '0'""" % where_clause
|
||||||
|
pending_count = (await sor.sqlExe(pending_sql, {}))[0]['cnt']
|
||||||
|
|
||||||
|
source_list_sql = """select distinct source from product_inquiry where %s""" % where_clause
|
||||||
|
source_list = [row['source'] for row in (await sor.sqlExe(source_list_sql, {}))]
|
||||||
|
has_empty_source = any(s is None or s == '' for s in source_list)
|
||||||
|
source_list = [s for s in source_list if s] # 过滤空值
|
||||||
|
if has_empty_source:
|
||||||
|
source_list.append('未知')
|
||||||
|
|
||||||
|
# 分页查询
|
||||||
|
search_sql = """select * from product_inquiry where %s order by update_time desc limit %d offset %d;""" % (where_clause, page_size, offset)
|
||||||
result = await sor.sqlExe(search_sql, {})
|
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_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_result = await sor.sqlExe(dict_sql, {})
|
||||||
@ -23,7 +66,7 @@ async def search_user_inquiry(ns={}):
|
|||||||
'custom_type': {'0': '个人', '1': '企业'},
|
'custom_type': {'0': '个人', '1': '企业'},
|
||||||
'enterprise_type': dict_mapping.get('enterprise_type', {}),
|
'enterprise_type': dict_mapping.get('enterprise_type', {}),
|
||||||
'region': dict_mapping.get('region', {}),
|
'region': dict_mapping.get('region', {}),
|
||||||
'feedback': {'0': '未反馈', '1': '已反馈'}
|
'feedback': {'0': '待回复', '1': '沟通中', '2': '已关闭', '3': '号码错误'}
|
||||||
}
|
}
|
||||||
for data_dic in result:
|
for data_dic in result:
|
||||||
for key, mapping in value_mapping.items():
|
for key, mapping in value_mapping.items():
|
||||||
@ -75,7 +118,14 @@ async def search_user_inquiry(ns={}):
|
|||||||
return {
|
return {
|
||||||
'status': True,
|
'status': True,
|
||||||
'msg': 'search success',
|
'msg': 'search success',
|
||||||
'data': result
|
'data': result,
|
||||||
|
'total_count': total_count,
|
||||||
|
'source_stats': source_stats,
|
||||||
|
'pending_count': pending_count,
|
||||||
|
'source_list': source_list,
|
||||||
|
'page': page,
|
||||||
|
'page_size': page_size,
|
||||||
|
'feedback_list': [{'id': 0, 'name': '待回复'},{'id': 1, 'name': '沟通中'},{'id': 2, 'name': '已关闭'},{'id': 3, 'name': '号码错误'}]
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = await search_user_inquiry(params_kw)
|
ret = await search_user_inquiry(params_kw)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user