From 783e61b12aa8696a133a13123500001d801cbe2c Mon Sep 17 00:00:00 2001 From: ping <1017253325@qq.com> Date: Mon, 18 Aug 2025 13:30:09 +0800 Subject: [PATCH] update --- b/product/homepage_product_category.dspy | 36 +++++++++++++++++ b/product/publish_product_add.dspy | 1 + b/product/publish_product_search.dspy | 39 ++++++++++++++----- b/product/publish_product_search_detail.dspy | 4 ++ .../publish_product_search_first_page.dspy | 8 +++- b/product/publish_product_update.dspy | 3 +- 6 files changed, 78 insertions(+), 13 deletions(-) create mode 100644 b/product/homepage_product_category.dspy diff --git a/b/product/homepage_product_category.dspy b/b/product/homepage_product_category.dspy new file mode 100644 index 0000000..8a01b8c --- /dev/null +++ b/b/product/homepage_product_category.dspy @@ -0,0 +1,36 @@ +async def homepage_product_category(ns={}): + if not ns.get('publish_type'): + return { + 'status': False, + 'msg': '请传递产品类型' + } + publish_type = ns.get('publish_type') + 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: + # 读取user_publish_product产品 + user_publish_product_sql = """SELECT DISTINCT(product_category) FROM user_publish_product WHERE domain_name = '%s' AND first_page = '1' AND audit_status = 'approved' AND listing_status = 'listing' AND del_flg = '0' AND publish_type = '%s' ORDER BY create_at DESC;""" % (domain_name, publish_type) + user_publish_product_result = await sor.sqlExe(user_publish_product_sql, {}) + if not user_publish_product_result: + return { + 'status': False, + 'msg': '没有找到匹配的产品' + } + user_publish_product_ids = [item['product_category'].split(",")[0] for item in user_publish_product_result] + + # 读取user_publish_product_category产品类别 + user_publish_product_category_sql = """SELECT * FROM user_publish_product_category WHERE domain_name = '%s' AND del_flg = '0' ORDER BY priority ASC;""" % domain_name + user_publish_product_category_result = await sor.sqlExe(user_publish_product_category_sql, {}) + result = [item for item in user_publish_product_category_result if str(item['id']) in user_publish_product_ids] + return { + 'status': True, + 'msg': 'success', + 'data': result + } + +ret = await homepage_product_category(params_kw) +return ret \ No newline at end of file diff --git a/b/product/publish_product_add.dspy b/b/product/publish_product_add.dspy index 4427aef..60a53d2 100644 --- a/b/product/publish_product_add.dspy +++ b/b/product/publish_product_add.dspy @@ -91,6 +91,7 @@ async def publish_product_add(ns={}): if user_role != '客户': ns['status'] = '1' ns_dic['audit_status'] = 'approved' + ns_dic['listing_status'] = 'listing' ns_dic['first_page'] = '1' try: await sor.C('user_publish_product', ns_dic) diff --git a/b/product/publish_product_search.dspy b/b/product/publish_product_search.dspy index 5da93e8..a2cbf13 100644 --- a/b/product/publish_product_search.dspy +++ b/b/product/publish_product_search.dspy @@ -36,6 +36,8 @@ async def publish_product_search(ns={}): """ offset = ns.get('offset') manager_self = ns.get('manager_self') + to_excel = ns.get('to_excel') + if ns.get('userid'): userid = ns.get('userid') @@ -141,17 +143,34 @@ async def publish_product_search(ns={}): res['img'] = 'https://' + domain_name + '/idfile?path=' + res['img'] else: res['img'] = None - return { - 'status': True, - 'msg': 'Requirements retrieved successfully', - 'data': { - "id": uuid(), - "total_count": total_count, - "page_size": page_size, - "current_page": current_page_param, - "product_list": result + + # 读取产品类别表 轮询匹配result中的所有类别 + product_category_list = await sor.R('user_publish_product_category', {'del_flg': '0'}) + for res in result: + for product_category in product_category_list: + if product_category['id'] == res['product_category'].split(",")[0]: + res['category_name'] = product_category['product_category'] + break + + if to_excel == '1': + res = await publish_product_to_excel({'result_from_search': result}) + return { + 'status': True, + 'msg': 'search to excel success', + 'data': res['data'] + } + else: + return { + 'status': True, + 'msg': 'Requirements retrieved successfully', + 'data': { + "id": uuid(), + "total_count": total_count, + "page_size": page_size, + "current_page": current_page_param, + "product_list": result + } } - } except Exception as e: return { 'status': False, diff --git a/b/product/publish_product_search_detail.dspy b/b/product/publish_product_search_detail.dspy index c212b01..f4938e4 100644 --- a/b/product/publish_product_search_detail.dspy +++ b/b/product/publish_product_search_detail.dspy @@ -44,8 +44,12 @@ async def publish_product_search_detail(ns={}): # 如果用户角色是运营并且from='b' product_list中的phone_number和email做加星号处理 product_list = await sor.R('user_publish_product', {'id': ns.get('id'), 'del_flg': '0'}) + product_category = await sor.R('user_publish_product_category', {'id': product_list[0]['product_category'].split(',')[0]}) + product_list[0]['product_category'] = product_category[0]['product_category'] if user_role == '运营' and ns.get('from') == 'b': pass + elif orgid == product_list[0]['orgid']: + pass else: for product in product_list: if product.get('phone_number'): diff --git a/b/product/publish_product_search_first_page.dspy b/b/product/publish_product_search_first_page.dspy index da7477b..a7c4afb 100644 --- a/b/product/publish_product_search_first_page.dspy +++ b/b/product/publish_product_search_first_page.dspy @@ -20,8 +20,12 @@ async def publish_product_search_first_page(ns={}): 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) + # 如果是首页并且有产品分类 + if to_page == 'first_page' and product_category: + count_sql = """SELECT COUNT(*) AS total_count FROM user_publish_product WHERE domain_name = '%s' AND first_page = '1' AND audit_status = 'approved' AND listing_status = 'listing' AND del_flg = '0' AND publish_type = '%s' AND product_category LIKE '%%%%%s%%%%' ORDER BY create_at DESC;""" % (domain_name, publish_type, product_category) + 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 listing_status = 'listing' AND upp.product_category LIKE '%%%%%s%%%%' 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, product_category, publish_type, page_size, current_page) + elif 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 listing_status = 'listing' 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 diff --git a/b/product/publish_product_update.dspy b/b/product/publish_product_update.dspy index 3c397b3..e824e5a 100644 --- a/b/product/publish_product_update.dspy +++ b/b/product/publish_product_update.dspy @@ -68,10 +68,11 @@ async def publish_product_update(ns={}): # 非客户角色编辑客户的产品 if user_role != '客户' and ns.get('orgid') != orgid: # 非客户角色审核客户的产品 - # 如果是待审状态 更新审核状态为通过 上架状态为上架 + # 如果是待审状态 更新审核状态为通过 上架状态为上架 清空驳回原因 if ns.get('audit_status') == 'approved': ns_dic['audit_status'] = 'approved' ns_dic['listing_status'] = 'listing' + ns_dic['reject_reason'] = None # 如果是上架商品 更新publish_time为当前时间 if ns.get('listing_status') == 'listing': ns_dic['publish_time'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')