253 lines
15 KiB
Plaintext
253 lines
15 KiB
Plaintext
async def shangji_provider_product_search(ns={}):
|
|
"""
|
|
本机构针对某个provider持有的产品 递归
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
providerid = ns.get('providerid')
|
|
offer_orgid = ns.get('offer_orgid')
|
|
product_list = []
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
sql_find_bid = """select * from saleprotocol where bid_orgid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between start_date and end_date;""" % offer_orgid
|
|
sql_find_bid_li = await sor.sqlExe(sql_find_bid, {})
|
|
sql_res = [item.get('offer_orgid') for item in sql_find_bid_li]
|
|
# 首先判断是不是当前分销商的直属供应商
|
|
if providerid in sql_res:
|
|
print('该供应商就是上级机构的供应商, 返回该供应商所有产品')
|
|
provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % providerid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
product_list.extend(provider_product_li)
|
|
return product_list
|
|
else:
|
|
# 如果不是直属供应商 就是上级某级机构的供应商
|
|
for sett in sql_find_bid_li:
|
|
salemode = sett['salemode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 首先在折扣表里找对应的provider
|
|
if salemode == '0':
|
|
# 查找子表
|
|
zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
exits_star = [(item.get('providerid'), item.get('productid')) for item in zi_table]
|
|
exist_st = (providerid, '*')
|
|
if exist_st in exits_star:
|
|
await shangji_provider_product_search({'providerid': providerid, 'offer_orgid': offer_orgid})
|
|
else:
|
|
for zic in zi_table:
|
|
zic_provider = zic['providerid']
|
|
zic_productid = zic['productid']
|
|
if zic_provider == providerid:
|
|
provider_product_sql = """select * from product WHERE id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % zic_productid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
product_list.extend(provider_product_li)
|
|
elif salemode == '2':
|
|
# 查找子表
|
|
zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
for zic in zi_table:
|
|
zic_provider = zic['providerid']
|
|
zic_productid = zic['productid']
|
|
if zic_provider == providerid:
|
|
provider_product_sql = """select * from product WHERE id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % zic_productid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
product_list.extend(provider_product_li)
|
|
return product_list
|
|
|
|
|
|
async def kehu_kan_xiaoshoujigou(ns={}):
|
|
"""
|
|
客户查看所在的机构
|
|
:return:
|
|
"""
|
|
userid = await get_user()
|
|
sor = ns.get('sor')
|
|
user_li = await sor.R('users', {'id': userid, 'del_flg': '0'})
|
|
user_org_id = user_li[0]['orgid']
|
|
org_li = await sor.R('organization', {'id': user_org_id, 'del_flg': '0'})
|
|
sale_orgid = org_li[0]['parentid']
|
|
return user_org_id, sale_orgid
|
|
|
|
|
|
async def xiaoshou_kan_tongyi(ns={}):
|
|
"""
|
|
价格不落地
|
|
:return:
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# 配置产品id列表[]
|
|
product_all_ids = []
|
|
product_all_infos = []
|
|
|
|
# 通过salemanid查看客户所在机构
|
|
# user_org_id, orgid = await kehu_kan_xiaoshoujigou({'userid': await get_user(), 'sor': sor})
|
|
user_org_id = ns.get('customerid')
|
|
org_li = await sor.R('organization', {'id': user_org_id, 'del_flg': '0'})
|
|
orgid = org_li[0]['parentid']
|
|
|
|
# 优先查看bid为该用户的配置
|
|
xieyi_yonghu_cha_sql = """select * from saleprotocol where offer_orgid = '%s' and bid_orgid = '%s' and del_flg = '0'
|
|
and CURRENT_DATE between start_date and end_date;""" % (orgid, user_org_id)
|
|
xieyi_yonghu_cha_li = await sor.sqlExe(xieyi_yonghu_cha_sql, {})
|
|
for xieyi_yonghu_cha in xieyi_yonghu_cha_li:
|
|
salemode_yonghu = xieyi_yonghu_cha['salemode']
|
|
protocolid_yonghu = xieyi_yonghu_cha['id']
|
|
# 查看子表
|
|
xieyi_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid_yonghu, 'del_flg': '0'})
|
|
xieyi_zibiao_cha_li_ = sorted(xieyi_zibiao_cha_li, key=lambda x: (x['productid'] == '*', x['productid']))
|
|
if salemode_yonghu == '0' or salemode_yonghu == '2':
|
|
for xieyi_zibiao in xieyi_zibiao_cha_li_:
|
|
providerid_yonghu = xieyi_zibiao['providerid']
|
|
productid_yonghu = xieyi_zibiao['productid']
|
|
discount_yonghu = xieyi_zibiao['discount']
|
|
price_yonghu = xieyi_zibiao['price']
|
|
zibiao_id_yonghu = xieyi_zibiao['id']
|
|
if productid_yonghu in product_all_ids:
|
|
# 产品id已经存在
|
|
continue
|
|
# 折扣表中 产品id不为* 就展示对应的产品信息和折扣信息和折扣后的价格 底价表中展示对应产品信息和售价信息
|
|
if salemode_yonghu == '0':
|
|
if productid_yonghu != '*':
|
|
# 筛选id
|
|
product_all_ids.append(productid_yonghu)
|
|
product_info_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid_yonghu
|
|
product_info_li = await sor.sqlExe(product_info_sql, {})
|
|
product_info = product_info_li[0] if product_info_li else {}
|
|
if product_info:
|
|
product_info['offer_orgid'] = orgid
|
|
product_info['bid_orgid'] = user_org_id
|
|
product_info['zibiao_id'] = zibiao_id_yonghu
|
|
product_info['protocolid'] = protocolid_yonghu
|
|
product_info['discount'] = discount_yonghu
|
|
# TODO 从供应商那里获取对应的产品价格
|
|
product_info['price'] = round(random.random() * 100, 2)
|
|
product_info['discount_price'] = round(product_info['price'] * product_info['discount'], 2)
|
|
# 追加产品信息
|
|
product_all_infos.append(product_info)
|
|
elif productid_yonghu == '*':
|
|
# 折扣表中 产品id为* 就向上级机构查找有对应providerid的多少产品 依次迭代
|
|
shangji_chanpin_li = await shangji_provider_product_search({'providerid': providerid_yonghu, 'offer_orgid': orgid})
|
|
for shangji_chanpin in shangji_chanpin_li:
|
|
shangji_chanpin_id = shangji_chanpin['id']
|
|
# 筛选id
|
|
if shangji_chanpin_id in product_all_ids:
|
|
continue
|
|
product_all_ids.append(shangji_chanpin_id)
|
|
shangji_chanpin['discount'] = discount_yonghu
|
|
shangji_chanpin['zibiao_id'] = '*'
|
|
shangji_chanpin['protocolid'] = protocolid_yonghu
|
|
shangji_chanpin['offer_orgid'] = orgid
|
|
shangji_chanpin['bid_orgid'] = user_org_id
|
|
|
|
product_all_infos.append(shangji_chanpin)
|
|
elif salemode_yonghu == '2':
|
|
# 筛选id
|
|
product_all_ids.append(productid_yonghu)
|
|
product_info_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid_yonghu
|
|
product_info_li = await sor.sqlExe(product_info_sql, {})
|
|
product_info = product_info_li[0] if product_info_li else {}
|
|
if product_info:
|
|
product_info['price'] = price_yonghu
|
|
product_info['zibiao_id'] = zibiao_id_yonghu
|
|
product_info['protocolid'] = protocolid_yonghu
|
|
product_info['offer_orgid'] = orgid
|
|
product_info['bid_orgid'] = user_org_id
|
|
|
|
# 追加产品信息
|
|
product_all_infos.append(product_info)
|
|
|
|
|
|
|
|
# 查找offer对应的机构id bid为* 的所有配置 时间限制
|
|
xieyi_cha_sql = """select * from saleprotocol where offer_orgid = '%s' and bid_orgid = '*' and del_flg = '0'
|
|
and CURRENT_DATE between start_date and end_date;""" % orgid
|
|
xieyi_cha_res_li = await sor.sqlExe(xieyi_cha_sql, {})
|
|
|
|
for xieyi_cha in xieyi_cha_res_li:
|
|
salemode = xieyi_cha['salemode']
|
|
protocolid = xieyi_cha['id']
|
|
# 查看子表
|
|
xieyi_zibiao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
xieyi_zibiao_cha_li_ = sorted(xieyi_zibiao_cha_li, key=lambda x: (x['productid'] == '*', x['productid']))
|
|
if salemode == '0' or salemode == '2':
|
|
for xieyi_zibiao in xieyi_zibiao_cha_li_:
|
|
providerid = xieyi_zibiao['providerid']
|
|
productid = xieyi_zibiao['productid']
|
|
discount = xieyi_zibiao['discount']
|
|
price = xieyi_zibiao['price']
|
|
zibiao_id_ = xieyi_zibiao['id']
|
|
if productid in product_all_ids:
|
|
# 产品id已经存在
|
|
continue
|
|
# 折扣表中 产品id不为* 就展示对应的产品信息和折扣信息和折扣后的价格 底价表中展示对应产品信息和售价信息
|
|
if salemode == '0':
|
|
if productid != '*':
|
|
# 筛选id
|
|
product_all_ids.append(productid)
|
|
product_info_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid
|
|
product_info_li = await sor.sqlExe(product_info_sql, {})
|
|
product_info = product_info_li[0] if product_info_li else {}
|
|
if product_info:
|
|
product_info['offer_orgid'] = orgid
|
|
product_info['bid_orgid'] = user_org_id
|
|
product_info['protocolid'] = protocolid
|
|
product_info['zibiao_id'] = zibiao_id_
|
|
product_info['discount'] = discount
|
|
# TODO 从供应商那里获取对应的产品价格
|
|
product_info['price'] = round(random.random() * 100, 2)
|
|
product_info['discount_price'] = round(product_info['price'] * product_info['discount'], 2)
|
|
# 追加产品信息
|
|
product_all_infos.append(product_info)
|
|
elif productid == '*':
|
|
# 折扣表中 产品id为* 就向上级机构查找有对应providerid的多少产品 依次迭代
|
|
shangji_chanpin_li = await shangji_provider_product_search({'providerid': providerid, 'offer_orgid': orgid})
|
|
for shangji_chanpin in shangji_chanpin_li:
|
|
shangji_chanpin_id = shangji_chanpin['id']
|
|
# 筛选id
|
|
if shangji_chanpin_id in product_all_ids:
|
|
continue
|
|
product_all_ids.append(shangji_chanpin_id)
|
|
shangji_chanpin['discount'] = discount
|
|
shangji_chanpin['zibiao_id'] = zibiao_id_
|
|
shangji_chanpin['protocolid'] = protocolid
|
|
shangji_chanpin['offer_orgid'] = orgid
|
|
shangji_chanpin['bid_orgid'] = user_org_id
|
|
|
|
product_all_infos.append(shangji_chanpin)
|
|
elif salemode == '2':
|
|
# 筛选id
|
|
product_all_ids.append(productid)
|
|
product_info_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid
|
|
product_info_li = await sor.sqlExe(product_info_sql, {})
|
|
product_info = product_info_li[0] if product_info_li else {}
|
|
if product_info:
|
|
product_info['offer_orgid'] = orgid
|
|
product_info['bid_orgid'] = user_org_id
|
|
product_info['price'] = price
|
|
product_info['zibiao_id'] = zibiao_id_
|
|
product_info['protocolid'] = protocolid
|
|
# 追加产品信息
|
|
product_all_infos.append(product_info)
|
|
return {
|
|
'status': True,
|
|
'msg': '销售获取商品统一信息成功',
|
|
'data': product_all_infos
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
'status': False,
|
|
'msg': '销售获取商品统一信息出错',
|
|
'err_msg': e
|
|
}
|
|
|
|
ret = await xiaoshou_kan_tongyi(params_kw)
|
|
return ret |