From 0ce9836c0d5069957252b3ad72479974572b4936 Mon Sep 17 00:00:00 2001 From: ping <1017253325@qq.com> Date: Thu, 27 Nov 2025 18:00:11 +0800 Subject: [PATCH] update --- b/product/home_page_content_add.dspy | 50 ++++++++ b/product/home_page_content_delete.dspy | 33 ++++++ b/product/home_page_content_get_tree.dspy | 118 +++++++++++++++++++ b/product/home_page_content_search.dspy | 36 ++++++ b/product/home_page_content_update.dspy | 39 ++++++ b/product/home_page_product_menu_add.dspy | 12 +- b/product/home_page_product_menu_search.dspy | 2 +- b/product/home_page_product_menu_update.dspy | 6 +- b/product/home_page_product_update.dspy | 16 +-- 9 files changed, 294 insertions(+), 18 deletions(-) create mode 100644 b/product/home_page_content_add.dspy create mode 100644 b/product/home_page_content_delete.dspy create mode 100644 b/product/home_page_content_get_tree.dspy create mode 100644 b/product/home_page_content_search.dspy create mode 100644 b/product/home_page_content_update.dspy diff --git a/b/product/home_page_content_add.dspy b/b/product/home_page_content_add.dspy new file mode 100644 index 0000000..c3e3e5a --- /dev/null +++ b/b/product/home_page_content_add.dspy @@ -0,0 +1,50 @@ +async def home_page_content_add(ns={}): + """ + 添加首页内容项 + :param ns: 包含content_type, title, description等字段的字典 + :return: 创建结果 + """ + ns_dic = { + 'id': uuid(), # 固定写法 + 'menu_product_id': ns.get('menu_product_id'), + 'parent_id': ns.get('parent_id'), + 'level': ns.get('level', 1), + 'content_type': ns.get('content_type'), # advantage, feature, application, product + 'sort_order': ns.get('sort_order', 0), + 'title': ns.get('title'), + 'description': ns.get('description'), + 'img': ns.get('img'), + 'name': ns.get('name'), + 'price': ns.get('price'), + 'pre_price': ns.get('pre_price'), + 'price_unit': ns.get('price_unit'), + 'discount': ns.get('discount'), + 'bg_img_url': ns.get('bg_img_url'), + 'icon': ns.get('icon') + } + + # 必填字段验证 + if not ns_dic.get('content_type'): + return { + 'status': False, + 'msg': 'content_type is required' + } + + db = DBPools() + async with db.sqlorContext('kboss') as sor: + try: + await sor.C('home_page_content_items', ns_dic) + return { + 'status': True, + 'msg': 'create home page content success', + 'data': {'id': ns_dic['id']} + } + except Exception as e: + await sor.rollback() + return { + 'status': False, + 'msg': 'create home page content failed, %s' % str(e) + } + +ret = await home_page_content_add(params_kw) +return ret \ No newline at end of file diff --git a/b/product/home_page_content_delete.dspy b/b/product/home_page_content_delete.dspy new file mode 100644 index 0000000..bcc16e8 --- /dev/null +++ b/b/product/home_page_content_delete.dspy @@ -0,0 +1,33 @@ +async def home_page_content_delete(ns={}): + """ + 软删除内容项,id值必传并且把del_flg值修改为1 + :param ns: 包含id的字典 + :return: 删除结果 + """ + if not ns.get('id'): + return { + 'status': False, + 'msg': 'id is required' + } + + ns_dic = { + 'id': ns.get('id'), + 'del_flg': '1' + } + db = DBPools() + async with db.sqlorContext('kboss') as sor: + try: + await sor.U('home_page_content_items', ns_dic) + return { + 'status': True, + 'msg': 'delete home page content success' + } + except Exception as e: + await sor.rollback() + return { + 'status': False, + 'msg': 'delete home page content failed, %s' % str(e) + } + +ret = await home_page_content_delete(params_kw) +return ret \ No newline at end of file diff --git a/b/product/home_page_content_get_tree.dspy b/b/product/home_page_content_get_tree.dspy new file mode 100644 index 0000000..a45cf09 --- /dev/null +++ b/b/product/home_page_content_get_tree.dspy @@ -0,0 +1,118 @@ +async def home_page_content_get_tree(ns={}): + """ + 获取首页内容的树形结构,按content_type分组 + :param ns: 包含menu_product_id的字典 + :return: 树形结构数据 + """ + menu_product_id = ns.get('menu_product_id') + + if not menu_product_id: + return { + 'status': False, + 'msg': 'menu_product_id is required' + } + + db = DBPools() + async with db.sqlorContext('kboss') as sor: + try: + # 查询所有有效的内容项 + sql = """ + SELECT * FROM home_page_content_items + WHERE menu_product_id = '%s' AND del_flg = '0' + ORDER BY sort_order ASC, create_at ASC + """ % menu_product_id + all_items = await sor.sqlExe(sql, {}) + + # 通过home_page_product_info表查找标题和描述 + find_sql = """ + SELECT * FROM home_page_product_info + WHERE id = '%s' AND del_flg = '0' + """ % menu_product_id + product_info = await sor.sqlExe(find_sql, {}) + product_title = None + product_description = None + if product_info: + product_info = product_info[0] + product_title = product_info.get('name', '') + product_description = product_info.get('description', '') + + # 按content_type分组 + result = { + 'title': product_title, # 可以从其他表获取 + 'description': product_description, # 可以从其他表获取 + 'advantages': [], + 'features': [], + 'applications': [], + 'products': [] + } + + for item in all_items: + content_type = item.get('content_type') + item_data = { + 'id': item['id'], + 'title': item['title'], + 'description': item['description'], + 'img': item['img'], + 'icon': item['icon'] + } + + # 根据内容类型添加到对应的列表 + if content_type == 'advantage': + result['advantages'].append(item_data) + elif content_type == 'feature': + result['features'].append(item_data) + elif content_type == 'application': + # 应用场景可能包含子项 + app_data = item_data.copy() + if not item.get('parent_id'): # 顶级应用 + app_data['provide'] = [] # 子项将在后续处理 + result['applications'].append(app_data) + elif content_type == 'product' and not item.get('parent_id'): + # 产品可能包含配置项 + product_data = item_data.copy() + product_data['price'] = item.get('price') + product_data['pre_price'] = item.get('pre_price') + product_data['price_unit'] = item.get('price_unit') + product_data['discount'] = item.get('discount') + product_data['bg_img_url'] = item.get('bg_img_url') + product_data['list'] = [] # 子项将在后续处理 + result['products'].append(product_data) + + # 处理子级项目 + for item in all_items: + if item.get('parent_id') != '0': + parent_id = item.get('parent_id') + content_type = item.get('content_type') + + # 查找父级并添加子项 + if content_type == 'application': + for app in result['applications']: + if app['id'] == parent_id: + app['provide'].append({ + 'id': item['id'], + 'title': item['title'], + 'description': item['description'] + }) + elif content_type == 'product': + for product in result['products']: + if product['id'] == parent_id: + product['list'].append({ + 'id': item['id'], + 'name': item['name'], + 'description': item['description'], + 'icon': item['icon'] + }) + + return { + 'status': True, + 'msg': 'get home page content tree success', + 'data': result + } + except Exception as e: + return { + 'status': False, + 'msg': 'get home page content tree failed, %s' % str(e) + } + +ret = await home_page_content_get_tree(params_kw) +return ret \ No newline at end of file diff --git a/b/product/home_page_content_search.dspy b/b/product/home_page_content_search.dspy new file mode 100644 index 0000000..40b87e5 --- /dev/null +++ b/b/product/home_page_content_search.dspy @@ -0,0 +1,36 @@ +async def home_page_content_search(ns={}): + """ + 查找内容项,支持按内容类型、父级ID等条件查询 + :param ns: 查询条件字典 + :return: 查询结果 + """ + # 构建查询条件 + conditions = {"del_flg": "0"} + + if ns.get('content_type'): + conditions['content_type'] = ns.get('content_type') + if ns.get('parent_id'): + conditions['parent_id'] = ns.get('parent_id') + if ns.get('menu_product_id'): + conditions['menu_product_id'] = ns.get('menu_product_id') + if ns.get('id'): + conditions['id'] = ns.get('id') + + db = DBPools() + async with db.sqlorContext('kboss') as sor: + try: + result = await sor.R('home_page_content_items', conditions) + return { + 'status': True, + 'msg': 'search home page content success', + 'data': result + } + except Exception as e: + await sor.rollback() + return { + 'status': False, + 'msg': 'search home page content failed, %s' % str(e) + } + +ret = await home_page_content_search(params_kw) +return ret \ No newline at end of file diff --git a/b/product/home_page_content_update.dspy b/b/product/home_page_content_update.dspy new file mode 100644 index 0000000..ebd5f6a --- /dev/null +++ b/b/product/home_page_content_update.dspy @@ -0,0 +1,39 @@ +async def home_page_content_update(ns={}): + """ + 更新内容项 + :param ns: 包含id和需要更新的字段的字典 + :return: 更新结果 + """ + if not ns.get('id'): + return { + 'status': False, + 'msg': 'id is required' + } + + # 构建更新字段,排除空值 + ns_dic = {'id': ns.get('id')} + update_fields = ['title', 'description', 'img', 'name', 'price', + 'pre_price', 'price_unit', 'discount', 'bg_img_url', + 'icon', 'sort_order', 'parent_id', 'level'] + + for field in update_fields: + if ns.get(field): + ns_dic[field] = ns.get(field) + + db = DBPools() + async with db.sqlorContext('kboss') as sor: + try: + await sor.U('home_page_content_items', ns_dic) + return { + 'status': True, + 'msg': 'update home page content success' + } + except Exception as e: + await sor.rollback() + return { + 'status': False, + 'msg': 'update home page content failed, %s' % str(e) + } + +ret = await home_page_content_update(params_kw) +return ret \ No newline at end of file diff --git a/b/product/home_page_product_menu_add.dspy b/b/product/home_page_product_menu_add.dspy index 677eab5..8ba3e07 100644 --- a/b/product/home_page_product_menu_add.dspy +++ b/b/product/home_page_product_menu_add.dspy @@ -13,13 +13,13 @@ async def home_page_product_menu_add(ns={}): # 验证必填字段 - if not ns_dic.get('menu_level') or not ns_dic.get('title'): - return { - 'status': False, - 'msg': 'menu_level and title are required' - } + # if not ns_dic.get('menu_level') or not ns_dic.get('title'): + # return { + # 'status': False, + # 'msg': 'menu_level and title are required' + # } - if ns.get('menu_level') > 1 and not ns.get('parent_id'): + if int(ns.get('menu_level')) > 1 and not ns.get('parent_id'): return { 'status': False, 'msg': 'parent_id is required for menu_level > 1' diff --git a/b/product/home_page_product_menu_search.dspy b/b/product/home_page_product_menu_search.dspy index 7ed8f08..af946c7 100644 --- a/b/product/home_page_product_menu_search.dspy +++ b/b/product/home_page_product_menu_search.dspy @@ -165,7 +165,7 @@ async def build_menu_tree(menu_list, target_level=None, target_title=None): """ # 通过sort_order对菜单进行排序 - menu_list.sort(key=lambda x: x['sort_order'], reverse=True) + menu_list.sort(key=lambda x: int(x['sort_order']), reverse=False) menu_dict = {} result = [] diff --git a/b/product/home_page_product_menu_update.dspy b/b/product/home_page_product_menu_update.dspy index 893413d..0f853f5 100644 --- a/b/product/home_page_product_menu_update.dspy +++ b/b/product/home_page_product_menu_update.dspy @@ -14,12 +14,12 @@ async def home_page_product_menu_update(ns={}): ns_dic = {'id': ns.get('id')} if ns.get('title'): ns_dic['title'] = ns.get('title') - if ns.get('parent_id') is not None: + if ns.get('parent_id'): ns_dic['parent_id'] = ns.get('parent_id') if ns.get('menu_level'): ns_dic['menu_level'] = ns.get('menu_level') - if ns.get('sort_order') is not None: - ns_dic['sort_order'] = ns.get('sort_order') + if ns.get('sort_order'): + ns_dic['sort_order'] = int(ns.get('sort_order')) db = DBPools() async with db.sqlorContext('kboss') as sor: diff --git a/b/product/home_page_product_update.dspy b/b/product/home_page_product_update.dspy index cda43a5..118016f 100644 --- a/b/product/home_page_product_update.dspy +++ b/b/product/home_page_product_update.dspy @@ -14,21 +14,21 @@ async def home_page_product_update(ns={}): ns_dic = {'id': ns.get('id')} if ns.get('name'): ns_dic['name'] = ns.get('name') - if ns.get('description') is not None: + if ns.get('description'): ns_dic['description'] = ns.get('description') - if ns.get('label') is not None: + if ns.get('label'): ns_dic['label'] = ns.get('label') - if ns.get('product_group') is not None: + if ns.get('product_group'): ns_dic['product_group'] = ns.get('product_group') - if ns.get('url') is not None: + if ns.get('url'): ns_dic['url'] = ns.get('url') - if ns.get('list_url') is not None: + if ns.get('list_url'): ns_dic['list_url'] = ns.get('list_url') - if ns.get('icon_url') is not None: + if ns.get('icon_url'): ns_dic['icon_url'] = ns.get('icon_url') - if ns.get('source') is not None: + if ns.get('source'): ns_dic['source'] = ns.get('source') - if ns.get('sort_order') is not None: + if ns.get('sort_order'): ns_dic['sort_order'] = ns.get('sort_order') if ns.get('menu_id'): ns_dic['menu_id'] = ns.get('menu_id')