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 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' 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) 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) 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) 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: res['img'] = 'https://' + domain_name + '/idfile?path=' + res['img'] 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': offset + 1, '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