Compare commits
2 Commits
921adcdb2b
...
9e1997e3f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e1997e3f3 | ||
|
|
0ce9836c0d |
50
b/product/home_page_content_add.dspy
Normal file
50
b/product/home_page_content_add.dspy
Normal file
@ -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
|
||||
33
b/product/home_page_content_delete.dspy
Normal file
33
b/product/home_page_content_delete.dspy
Normal file
@ -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
|
||||
118
b/product/home_page_content_get_tree.dspy
Normal file
118
b/product/home_page_content_get_tree.dspy
Normal file
@ -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
|
||||
36
b/product/home_page_content_search.dspy
Normal file
36
b/product/home_page_content_search.dspy
Normal file
@ -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
|
||||
39
b/product/home_page_content_update.dspy
Normal file
39
b/product/home_page_content_update.dspy
Normal file
@ -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
|
||||
@ -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'
|
||||
|
||||
@ -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 = []
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user