This commit is contained in:
ping 2025-08-01 16:21:59 +08:00
parent c3e268c640
commit a6d2c4166f
5 changed files with 117 additions and 38 deletions

View File

@ -1,14 +1,26 @@
async def company_category_add(ns={}):
if not ns.get('url_link'):
return {
'status': False,
'msg': '请传递url_link'
}
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
ns_dic = {
'id': uuid(),
'domain_name': domain_name,
'company_category': ns.get('company_category')
}
db = DBPools()
async with db.sqlorContext('kboss') as sor:
if ns.get('userid'):
userid = ns.get('userid')
else:
userid = await get_user()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 区分运营和普通客户
user_list = await sor.R('users', {'id': userid})
if not user_list:

View File

@ -1,24 +1,17 @@
async def company_category_search(ns={}):
if ns.get('userid'):
userid = ns.get('userid')
else:
userid = await get_user()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 区分运营和普通客户
user_list = await sor.R('users', {'id': userid})
if not user_list:
if not ns.get('url_link'):
return {
'status': False,
'msg': '没有找到匹配的用户'
}
orgid = user_list[0]['orgid']
ns_dic = {
'orgid': orgid,
'del_flg': '0'
'msg': '请传递url_link'
}
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
result = await sor.R('user_publish_company_category', ns_dic)
result = await sor.R('user_publish_company_category', {'domain_name': domain_name, 'del_flg': '0'})
return {
'status': True,
'msg': 'Company categories retrieved successfully',

View File

@ -1,9 +1,22 @@
async def product_category_add(ns={}):
if not ns.get('url_link'):
return {
'status': False,
'msg': '请传递路由链接'
}
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
ns_dic = {
'id': uuid(),
'domain_name': domain_name,
'product_category': ns.get('product_category'),
'parentid': ns.get('parentid') if ns.get('parentid') else None
'parentid': ns.get('parentid') if ns.get('parentid') else None,
'priority': ns['priority'] if ns.get('priority') else 99,
'permission': ns.get('permission') if ns.get('permission') else '1',
'cart_flag': ns.get('cart_flag') if ns.get('cart_flag') else None
}
if ns.get('userid'):
userid = ns.get('userid')
else:
@ -26,7 +39,6 @@ async def product_category_add(ns={}):
'msg': 'product category created successfully'
}
except Exception as e:
await sor.rollback()
return {
'status': False,
'msg': 'Failed to create product category, %s' % str(e)

View File

@ -6,13 +6,54 @@ async def build_tree(parent_id=None, all_cats=None):
"children": await build_tree(cat['id'], all_cats)
} for cat in all_cats if cat['parentid'] == parent_id]
async def get_user_role(ns={}):
sor = ns['sor']
# get role
ns['del_flg'] = '0'
res_role = await sor.R('userrole', ns)
if res_role:
user_role = res_role[0]
else:
return {
"status": False,
"msg": "userrole table, user id can not find..."
}
roleid = user_role.get('roleid')
# get role name
role_name = await sor.R('role', {'id': roleid})
if role_name:
role = role_name[0].get('role')
else:
return {
"status": False,
"msg": "role table, can not get role name"
}
return role
async def product_category_search(ns={}):
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
to_page = ns.get('to_page')
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 首页不登录 通过域名筛选
if to_page == 'show':
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' ORDER BY priority;""" % domain_name
result = await sor.sqlExe(find_sql, {})
return {
'status': True,
'msg': 'product categories retrieved successfully',
'data': result
}
# 发布弹窗中的产品种类通过用户筛选 普通用户/管理人员
if ns.get('userid'):
userid = ns.get('userid')
else:
userid = await get_user()
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 区分运营和普通客户
user_list = await sor.R('users', {'id': userid})
if not user_list:
@ -21,9 +62,12 @@ async def product_category_search(ns={}):
'msg': '没有找到匹配的用户'
}
orgid = user_list[0]['orgid']
ns_dic = {'orgid': orgid, 'del_flg': '0'}
user_role = await get_user_role({'userid': userid, 'sor': sor})
try:
find_sql = """SELECT * FROM user_publish_product_category WHERE orgid = '%s' AND del_flg = '0' ORDER BY priority;""" % orgid
if user_role == '客户':
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND permission = '1' AND del_flg = '0' ORDER BY priority;""" % domain_name
else:
find_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' ORDER BY priority;""" % domain_name
result = await sor.sqlExe(find_sql, {})
# res = await build_tree(parent_id=None, all_cats=result)
return {

View File

@ -6,8 +6,9 @@ async def publish_product_search_first_page(ns={}):
:param ns:
:return:
"""
page_size = int(ns['page_size']) if ns.get('page_size') else 10
offset = int(ns['offset'] - 1) if ns.get('offset') else 0
page_size = int(ns['page_size']) if ns.get('page_size') else 8
current_page_param = int(ns['current_page']) if ns.get('current_page') else 1
current_page = (current_page_param - 1) * page_size
to_page = ns.get('to_page') if ns.get('to_page') else 'first_page'
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
company_type = ns.get('company_type')
@ -20,16 +21,13 @@ async def publish_product_search_first_page(ns={}):
ns['del_flg'] = '0'
if to_page == 'first_page':
count_sql = """SELECT COUNT(*) AS total_count FROM user_publish_product WHERE domain_name = '%s' AND first_page = '1' AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC;""" % (domain_name,)
find_sql = """SELECT upp.* FROM user_publish_product AS upp INNER JOIN user_publish_product_category AS uppc ON upp.product_category LIKE uppc.id WHERE upp.domain_name = '%s' AND upp.first_page = '1' AND upp.audit_status = 'approved' AND upp.del_flg = '0' ORDER BY uppc.priority ASC, upp.create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, page_size, offset)
elif to_page == 'square' and product_category and company_type:
count_sql = """SELECT COUNT(*) AS total_count FROM user_publish_product WHERE domain_name = '%s' AND product_category LIKE """ % domain_name + """'%%""" + product_category + """%%'""" + """AND company_type LIKE """ + """'%%""" + company_type + """%%'""" + """ AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC;"""
find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND product_category LIKE """ % domain_name + """'%%""" + product_category + """%%'""" + """AND company_type LIKE """ + """'%%""" + company_type + """%%'""" + """ AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (page_size, offset)
find_sql = """SELECT upp.* FROM user_publish_product AS upp INNER JOIN user_publish_product_category AS uppc ON upp.product_category LIKE uppc.id WHERE upp.domain_name = '%s' AND upp.first_page = '1' AND upp.audit_status = 'approved' AND upp.del_flg = '0' ORDER BY uppc.priority ASC, upp.create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, page_size, current_page)
elif to_page == 'square' and product_category:
count_sql = """SELECT COUNT(*) AS total_count FROM user_publish_product WHERE domain_name = '%s' AND product_category LIKE """ % domain_name + """'%%""" + product_category + """%%'""" + """ AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC;"""
find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND product_category LIKE """ % domain_name + """'%%""" + product_category + """%%'""" + """ AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (page_size, offset)
find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND product_category LIKE """ % domain_name + """'%%""" + product_category + """%%'""" + """ AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (page_size, current_page)
elif to_page == 'square':
count_sql = """SELECT COUNT(*) AS total_count FROM user_publish_product WHERE domain_name = '%s' AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC;""" % (domain_name,)
find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, page_size, offset)
find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND audit_status = 'approved' AND del_flg = '0' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, page_size, current_page)
else:
count_sql = ''
find_sql = ''
@ -39,7 +37,26 @@ async def publish_product_search_first_page(ns={}):
category_all = await sor.R('user_publish_product_category', {})
product_dic = {}
for res in result:
# 公司类别筛选
if company_type:
list1 = [item.strip() for item in company_type.split(',')]
list2 = [item.strip() for item in res['company_type'].split(',')]
if not bool(set(list1) & set(list2)):
continue
res['img'] = 'https://' + domain_name + '/idfile?path=' + res['img']
# 电话和邮箱模糊化处理
if res.get('phone_number'):
res['phone_number'] = res['phone_number'][:3] + '****' + res['phone_number'][7:]
else:
res['phone_number'] = '198****8601'
if res.get('email'):
res['email'] = res['email'][:2] + '****' + res['email'][6:]
else:
res['email'] = 'kawa@****.com'
category_id = res['product_category'].split(',')[0]
category_name_li = [item['product_category'] for item in category_all if item['id'] == category_id]
category_name = category_name_li[0] if category_name_li else '其他'
@ -49,7 +66,7 @@ async def publish_product_search_first_page(ns={}):
product_dic[category_name] = [res]
product_list = []
for key, value in product_dic.items():
product_list.append({'id': uuid(), 'name': key, 'total_count': total_count, 'page_size': page_size, 'current_page': offset + 1, 'product_list': value})
product_list.append({'id': uuid(), 'name': key, 'total_count': total_count, 'page_size': page_size, 'current_page': current_page_param, 'product_list': value})
return {
'status': True,
'msg': 'Requirements retrieved successfully',
@ -60,5 +77,6 @@ async def publish_product_search_first_page(ns={}):
'status': False,
'msg': 'Failed to retrieve requirements, %s' % str(e)
}
ret = await publish_product_search_first_page(params_kw)
return ret