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