191 lines
11 KiB
Plaintext
191 lines
11 KiB
Plaintext
async def shangji_provider_product_search(ns={}):
|
|
"""
|
|
本机构针对某个provider持有的产品 递归
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
ns = {
|
|
'providerid': '',
|
|
'offer_orgid': ''
|
|
}
|
|
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:
|
|
settle_mode = sett['settle_mode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 首先在折扣表里找对应的provider
|
|
if settle_mode == '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 settle_mode == '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)
|
|
|
|
|
|
async def self_product_search(ns={}):
|
|
"""
|
|
产品不落地
|
|
本机构所有产品查找 回佣>折扣>底价
|
|
本机构是业主机构
|
|
协议表所有bid是本机构 *就查找product表 provider所有产品 本质是往上找一层
|
|
本机构是某级分销商
|
|
协议表所有bid是本机构 *就查找 上级offer为bid *对应的provider 循环 直到不含有*/offer为provider类型为供应商为止 找N层
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
bid_orgid = ns.get('bid_orgid')
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
all_product = []
|
|
ns['del_flg'] = '0'
|
|
# 查找所有bid是本机构的协议表
|
|
sql_find_bid = """select * from saleprotocol where bid_orgid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between start_date and end_date;""" % bid_orgid
|
|
sql_find_bid_li = await sor.sqlExe(sql_find_bid, {})
|
|
# 判断是业主机构还是分销商
|
|
yezhu_li = await sor.R('organization', {'id': bid_orgid})
|
|
yezhu_judge = yezhu_li[0]['org_type']
|
|
# 如果是供应商 就返回所有产品
|
|
if yezhu_judge == '4':
|
|
provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % bid_orgid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
return provider_product_li
|
|
# 如果是业主机构
|
|
if yezhu_judge == '0':
|
|
for sett in sql_find_bid_li:
|
|
settle_mode = sett['settle_mode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 如果settle_mode是1 就是供应商所有产品
|
|
if settle_mode == '1':
|
|
provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % offer_orgid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
all_product.extend(provider_product_li)
|
|
# 如果settle_mode是折扣 如果有* 就是供应商所有产品 如果settle_mode是底价就获取所有productid
|
|
if settle_mode == '0' or settle_mode == '2':
|
|
# 查找子表
|
|
zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
# 如果有* 就获取providerid所有产品
|
|
star_flg = [item.get('productid') for item in zi_table]
|
|
if '*' in star_flg:
|
|
provider_product_sql = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % offer_orgid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql, {})
|
|
all_product.extend(provider_product_li)
|
|
else:
|
|
prd_single_ids = [item.get('productid') for item in zi_table]
|
|
for prd_single in prd_single_ids:
|
|
single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % prd_single
|
|
single_res_li = await sor.sqlExe(single_sql, {})
|
|
single_res = single_res_li[0] if single_res_li else {}
|
|
all_product.append(single_res)
|
|
return all_product
|
|
# 如果是分销商
|
|
if yezhu_judge == '1':
|
|
for sett in sql_find_bid_li:
|
|
settle_mode = sett['settle_mode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 判断是业主机构还是分销商
|
|
yezhu_li = await sor.R('organization', {'id': offer_orgid})
|
|
yezhu_judge = yezhu_li[0]['org_type']
|
|
# 如果settle_mode是1 就是offer所有产品
|
|
if settle_mode == '1':
|
|
prodcut_one = await self_product_serach({'bid_orgid': offer_orgid})
|
|
all_product.extend(prodcut_one)
|
|
# 如果settle_mode是折扣 如果有* 就是供应商所有产品 不是* 就获取所有productid
|
|
if settle_mode == '0':
|
|
# 如果上级机构是供应商就获取该供应商所有产品
|
|
if yezhu_judge == '4':
|
|
provider_product_sql_ = """select * from product WHERE providerid = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % offer_orgid
|
|
provider_product_li = await sor.sqlExe(provider_product_sql_, {})
|
|
all_product.extend(provider_product_li)
|
|
else:
|
|
# 如果不是供应商就查找子表
|
|
zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
# 如果有* 就获取providerid所有产品
|
|
for zic in zi_table:
|
|
providerid_ = zic['providerid']
|
|
productid_ = zic['productid']
|
|
if productid_ == '*':
|
|
# 查找上级机构该providerid持有的产品
|
|
product_res = await shangji_provider_product_search({'providerid': providerid_,
|
|
'offer_orgid': offer_orgid})
|
|
all_product.extend(product_res)
|
|
else:
|
|
single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid_
|
|
single_res_li = await sor.sqlExe(single_sql, {})
|
|
single_res = single_res_li[0] if single_res_li else {}
|
|
all_product.append(single_res)
|
|
|
|
# 如果settle_mode是底价 就获取所有productid
|
|
if settle_mode == '2':
|
|
zi_table = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
# 如果有* 就获取providerid所有产品
|
|
for zic in zi_table:
|
|
productid_ = zic['productid']
|
|
single_sql = """select * from product where id = '%s' and del_flg = '0' and CURRENT_DATE
|
|
between effect_date and expire_date;""" % productid_
|
|
single_res_li = await sor.sqlExe(single_sql, {})
|
|
single_res = single_res_li[0] if single_res_li else {}
|
|
all_product.append(single_res)
|
|
return {
|
|
"status": True,
|
|
"msg": "product_salemode search success",
|
|
"data": all_product
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
"status": False,
|
|
"msg": "product_salemode search failed"
|
|
}
|
|
|
|
|
|
ret = await self_product_search(params_kw)
|
|
return ret |