242 lines
13 KiB
Plaintext
242 lines
13 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 self_product_search(ns={}):
|
|
"""
|
|
产品不落地
|
|
本机构所有产品查找 回佣>折扣>底价
|
|
本机构是业主机构
|
|
协议表所有bid是本机构 *就查找product表 provider所有产品 本质是往上找一层
|
|
本机构是某级分销商
|
|
协议表所有bid是本机构 *就查找 上级offer为bid *对应的provider 循环 直到不含有*/offer为provider类型为供应商为止 找N层
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
# ns = {
|
|
# 'bid_orgid': '6woiJ-_5tDmZUHFnLLty_',
|
|
# }
|
|
bid_orgid = ns.get('bid_orgid')
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
if ns.get('sor'):
|
|
sor = ns.get('sor')
|
|
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:
|
|
salemode = sett['salemode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 如果salemode是1 就是供应商所有产品
|
|
if salemode == '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)
|
|
# 如果salemode是折扣 如果有* 就是供应商所有产品 如果salemode是底价就获取所有productid
|
|
if salemode == '0' or salemode == '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:
|
|
salemode = sett['salemode']
|
|
offer_orgid = sett['offer_orgid']
|
|
protocolid = sett['id']
|
|
# 判断是业主机构还是分销商
|
|
yezhu_li = await sor.R('organization', {'id': offer_orgid})
|
|
yezhu_judge = yezhu_li[0]['org_type']
|
|
# 如果salemode是1 就是offer所有产品
|
|
if salemode == '1':
|
|
prodcut_one = await self_product_search({'bid_orgid': offer_orgid})
|
|
all_product.extend(prodcut_one)
|
|
# 如果salemode是折扣 如果有* 就是供应商所有产品 不是* 就获取所有productid
|
|
if salemode == '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)
|
|
|
|
# 如果salemode是底价 就获取所有productid
|
|
if salemode == '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 all_product
|
|
# 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"
|
|
}
|
|
|
|
async def discount_guanli_no_config(ns={}):
|
|
"""
|
|
折扣管理查
|
|
:return:
|
|
"""
|
|
bid_orgid = ns.get('bid_orgid')
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
ns_kehu_zhekou = {
|
|
'offer_orgid': bid_orgid,
|
|
'bid_orgid': '*',
|
|
'salemode': '0',
|
|
'del_flg': '0'
|
|
}
|
|
ns_dijia = {
|
|
'bid_orgid': ns.get('bid_orgid'),
|
|
'salemode': '2',
|
|
'del_flg': '0'
|
|
}
|
|
# 本机构所有产品
|
|
self_product_all = await self_product_search({'bid_orgid': bid_orgid})
|
|
# 筛选所有是底价的产品
|
|
dijia_res_li = await sor.R('saleprotocol', ns_dijia)
|
|
dijia_res_ids = [item_.get('productid') for item_ in dijia_res_li if item_.get('productid')]
|
|
# 本机构折扣和回佣产品
|
|
jigou_zhekou_huiyong = [item_prd for item_prd in self_product_all if item_prd.get('id') not in dijia_res_ids]
|
|
|
|
zhekou_exist = []
|
|
# 本机构所有设置过统一折扣的产品
|
|
kehu_zhekou_res_li = await sor.R('saleprotocol', ns_kehu_zhekou)
|
|
for kehu_zhekou in kehu_zhekou_res_li:
|
|
protocolid = kehu_zhekou['id']
|
|
zi_biao_cha_li = await sor.R('product_salemode', {'protocolid': protocolid, 'del_flg': '0'})
|
|
for zibiao in zi_biao_cha_li:
|
|
zhekou_exist.append(zibiao['productid'])
|
|
|
|
product_all = [prd_item for prd_item in jigou_zhekou_huiyong if prd_item.get('id') not in zhekou_exist]
|
|
return {
|
|
'status': True,
|
|
'msg': '销售看折扣成功',
|
|
'data': product_all
|
|
}
|
|
except Exception as e:
|
|
return {
|
|
'status': False,
|
|
'msg': '销售看折扣失败',
|
|
'err_msg': e
|
|
}
|
|
|
|
ret = await discount_guanli_no_config(params_kw)
|
|
return ret |