async def publish_product_search_first_page(ns={}): """ 普通客户查看 运营查看自己提交内容 运营查看所有用户内容 :param ns: :return: """ publish_type = ns.get('publish_type') 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') product_category = ns.get('product_category') if 'localhost' in domain_name: domain_name = 'dev.opencomputing.cn' db = DBPools() async with db.sqlorContext('kboss') as sor: try: 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' AND publish_type = '%s' ORDER BY create_at DESC;""" % (domain_name, publish_type) 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' AND upp.publish_type = '%s' ORDER BY uppc.priority ASC, upp.create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, publish_type, 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' AND publish_type = '%s' ORDER BY create_at DESC;""" % publish_type 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' AND publish_type = '%s' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (publish_type, 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' AND publish_type = '%s' ORDER BY create_at DESC;""" % (domain_name, publish_type) find_sql = """SELECT * FROM user_publish_product WHERE domain_name = '%s' AND audit_status = 'approved' AND del_flg = '0' AND publish_type = '%s' ORDER BY create_at DESC LIMIT %s OFFSET %s;""" % (domain_name, publish_type, page_size, current_page) else: count_sql = '' find_sql = '' total_count = (await sor.sqlExe(count_sql, {}))[0]['total_count'] result = await sor.sqlExe(find_sql, {}) 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 if res.get('img') and res['img'] != 'null': res['img'] = 'https://' + domain_name + '/idfile?path=' + res['img'] else: res['img'] = None # 电话和邮箱模糊化处理 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 '其他' if product_dic.get(category_name): product_dic[category_name].append(res) else: 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': current_page_param, 'product_list': value}) return { 'status': True, 'msg': 'Requirements retrieved successfully', 'data': product_list } except Exception as e: return { 'status': False, 'msg': 'Failed to retrieve requirements, %s' % str(e) } ret = await publish_product_search_first_page(params_kw) return ret