101 lines
4.7 KiB
Plaintext
101 lines
4.7 KiB
Plaintext
async def sale_protocol_update(ns={}):
|
|
"""
|
|
协议修改
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
ns_sale_protocol = {
|
|
'id': ns.get('protocolid'),
|
|
'salemode': ns.get('salemode'),
|
|
'start_date': ns.get('start_date'),
|
|
'end_date': ns.get('end_date'),
|
|
}
|
|
protocolid = ns.get('protocolid')
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# 如果只是改起始时间 子表不需要删除
|
|
exist_mode_li = await sor.R('saleprotocol', {'id': ns.get('protocolid'), 'del_flg': '0'})
|
|
exist_mode = exist_mode_li[0]['salemode']
|
|
|
|
# 如果模式没有改变 只更新主表内容
|
|
if ns.get('protocolfile'):
|
|
ns_sale_protocol['protocolfile'] = ns.get('protocolfile')
|
|
if ns.get('settlemode'):
|
|
ns_sale_protocol['settle_mode'] = ns.get('settle_mode')
|
|
if ns.get('settle_dp'):
|
|
ns_sale_protocol['settle_dp'] = ns.get('settle_datep')
|
|
await sor.U('saleprotocol', ns_sale_protocol)
|
|
|
|
# 如果是供应商 修改provider表中salemode start_date end_date
|
|
if ns.get('provider_table_id'):
|
|
ns_provider = {'id': ns.get('provider_table_id')}
|
|
if ns.get('start_date'):
|
|
ns_provider['start_date'] = ns.get('start_date')
|
|
if ns.get('end_date'):
|
|
ns_provider['end_date'] = ns.get('end_date')
|
|
|
|
provider_orgid = (await sor.R('provider', {'id': ns.get('provider_table_id')}))[0]['orgid']
|
|
product_update_sql = """update product set effect_date = '%s', expire_date = '%s' where
|
|
providerid = '%s';""" % (ns.get('start_date'), ns.get('end_date'), provider_orgid)
|
|
await sor.sqlExe(product_update_sql, {})
|
|
|
|
if ns.get('salemode'):
|
|
salemode = str(ns.get('salemode'))
|
|
if salemode == '0':
|
|
ns_provider['discount_mode'] = 1
|
|
ns_provider['rebate_mode'] = None
|
|
ns_provider['floorprice_mode'] = None
|
|
elif salemode == '1':
|
|
ns_provider['discount_mode'] = None
|
|
ns_provider['rebate_mode'] = 1
|
|
ns_provider['floorprice_mode'] = None
|
|
elif salemode == '2':
|
|
ns_provider['discount_mode'] = None
|
|
ns_provider['rebate_mode'] = None
|
|
ns_provider['floorprice_mode'] = 1
|
|
await sor.U('provider', ns_provider)
|
|
|
|
# 如果模式改变 就删除子表protocolid内容
|
|
if exist_mode != ns.get('salemode'):
|
|
up_sql_s = """update product_salemode set del_flg = '1' where protocolid = '%s';""" % ns.get('protocolid')
|
|
await sor.sqlExe(up_sql_s, {})
|
|
# 删除已经统一配置对应的产品
|
|
# 删除供应商在协议子表中的所有产品
|
|
res_id_li = await sor.R('saleprotocol', {'id': ns.get('protocolid')})
|
|
provider_id = res_id_li[0]['offer_orgid']
|
|
# bid_orgid = res_id_li[0]['bid_orgid']
|
|
sql_up = """update product_salemode set del_flg = '1' where providerid = '%s';""" % provider_id
|
|
await sor.sqlExe(sql_up, {})
|
|
|
|
# 删除回佣主表
|
|
huiyong_sql = """update rebate_cycle set del_flg = '1' where protocolid = '%s';""" % protocolid
|
|
await sor.sqlExe(huiyong_sql, {})
|
|
# 删除回佣子表
|
|
huiyong_zi_search_sql = """select * from rebate_cycle where protocolid = '%s';""" % protocolid
|
|
huiyong_zi_res_li = await sor.sqlExe(huiyong_zi_search_sql, {})
|
|
for huiyong_zi_res in huiyong_zi_res_li:
|
|
cycleid = huiyong_zi_res['id']
|
|
huiyong_zi_up_sql = """update rp_rebate set del_flg = '1' WHERE rebatecycleid = '%s';""" % cycleid
|
|
await sor.sqlExe(huiyong_zi_up_sql)
|
|
|
|
# 删除促销商品表
|
|
products_li = await sor.R('product', {'providerid': provider_id})
|
|
for product_info in products_li:
|
|
product_ids = product_info['id']
|
|
promote_sql = """UPDATE promote_discount SET del_flg = '1' WHERE productid = '%s';""" % product_ids
|
|
await sor.sqlExe(promote_sql, {})
|
|
|
|
return {
|
|
'status': True,
|
|
'msg': '协议更新成功'
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
'status': False,
|
|
'msg': '协议更新失败'
|
|
}
|
|
|
|
ret = await sale_protocol_update(params_kw)
|
|
return ret |