67 lines
3.3 KiB
Plaintext
67 lines
3.3 KiB
Plaintext
async def provider_product_search(ns={}):
|
|
"""
|
|
查看供应商所有产品
|
|
:return:
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
product_all = []
|
|
if ns.get('providerid'):
|
|
res_product_sql = """select * from product where providerid = '%s' and del_flg = '0'""" % ns.get('providerid')
|
|
res_product_li = await sor.sqlExe(res_product_sql, {})
|
|
return {
|
|
'status': True,
|
|
'msg': '供应商产品查找成功',
|
|
'data': res_product_li
|
|
}
|
|
if ns.get('protocolid'):
|
|
res_product_sql = """select * from product_salemode where protocolid = '%s' and del_flg = '0'""" % ns.get('protocolid')
|
|
zibiao_cha_li = await sor.sqlExe(res_product_sql, {})
|
|
classify_list = []
|
|
for zibiao_cha in zibiao_cha_li:
|
|
product_id = zibiao_cha['productid']
|
|
product_info_li = await sor.R('product', {'id': product_id, 'del_flg': '0'})
|
|
# if not product_info_li:
|
|
# return {
|
|
# 'status': False,
|
|
# 'msg': '%s 产品表没有这个产品或产品表这个产品已经删除' % product_id
|
|
# }
|
|
if product_info_li:
|
|
product_info = product_info_li[0]
|
|
product_info['spec_note'] = product_info.get('spec_note').replace('Value', 'value') if product_info.get('spec_note') else None
|
|
product_info['productid'] = product_info.pop('id')
|
|
product_info['zi_biao_id'] =zibiao_cha['id']
|
|
product_info.update(zibiao_cha)
|
|
product_all.append(product_info)
|
|
classify_single = product_info.get('classify') if product_info.get('classify') else '未配置'
|
|
class_dic = {'class_key': classify_single}
|
|
if class_dic not in classify_list:
|
|
classify_list.append(class_dic)
|
|
if ns.get('productname'):
|
|
productname = ns.get('productname')
|
|
product_all = [i for i in product_all if productname in i['name']]
|
|
if ns.get('start_discount') and ns.get('end_discount'):
|
|
product_all = [i for i in product_all if float(ns.get('start_discount')) / 10 <= float(i['discount']) <= float(ns.get('end_discount')) / 10]
|
|
if ns.get('classify'):
|
|
if ns['classify'] == '未配置':
|
|
classify_filter = None
|
|
else:
|
|
classify_filter = ns['classify']
|
|
product_all = [i for i in product_all if i.get('classify') == classify_filter]
|
|
return {
|
|
'status': True,
|
|
'msg': '供应商产品查找成功',
|
|
'classify_list': classify_list,
|
|
'data': product_all
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
'status': False,
|
|
'msg': '供应商产品查找失败'
|
|
}
|
|
|
|
|
|
ret = await provider_product_search(params_kw)
|
|
return ret |