59 lines
1.9 KiB
Plaintext
59 lines
1.9 KiB
Plaintext
async def rebate_add(ns={}):
|
|
"""
|
|
回佣添加
|
|
:param ns:
|
|
:return:
|
|
"""
|
|
ns_rebate_cycle = {
|
|
'id': uuid(),
|
|
'protocolid': ns.get('protocolid'),
|
|
'rebate_cycle': ns.get('rebate_cycle'),
|
|
'sette_dp': ns.get('settle_datep'),
|
|
}
|
|
ns_rp_rebate = {
|
|
'id': uuid(),
|
|
'rebatecycleid': ns_rebate_cycle['id'],
|
|
'sale_amount': ns.get('sale_amount'),
|
|
'rebate_rate': ns.get('rebate_rate')
|
|
}
|
|
ns_rebate_cycle_exist = {
|
|
'protocolid': ns.get('protocolid'),
|
|
'rebate_cycle': ns.get('rebate_cycle'),
|
|
'del_flg': '0'
|
|
}
|
|
ns_rp_rebate_exist = {
|
|
'rebatecycleid': ns_rebate_cycle['id'],
|
|
'sale_amount': ns.get('sale_amount'),
|
|
'rebate_rate': ns.get('rebate_rate'),
|
|
'del_flg': '0'
|
|
}
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
# 首先判断回佣协议主表是否存在
|
|
rebate_cycle_exist = await sor.R('rebate_cycle', ns_rebate_cycle_exist)
|
|
# 如果已经存在 再判断回佣子表是否已存在
|
|
if rebate_cycle_exist:
|
|
huiyong_zhu_id = rebate_cycle_exist[0]['id']
|
|
ns_rp_rebate['rebatecycleid'] = huiyong_zhu_id
|
|
ns_rp_rebate_exist['rebatecycleid'] = huiyong_zhu_id
|
|
rp_rebate_exist = await sor.R('rp_rebate', ns_rp_rebate_exist)
|
|
if not rp_rebate_exist:
|
|
await sor.C('rp_rebate', ns_rp_rebate)
|
|
else:
|
|
await sor.C('rebate_cycle', ns_rebate_cycle)
|
|
await sor.C('rp_rebate', ns_rp_rebate)
|
|
return {
|
|
'status': True,
|
|
'msg': '回佣添加成功'
|
|
}
|
|
except Exception as e:
|
|
raise e
|
|
return {
|
|
'status': False,
|
|
'msg': '回佣添加失败'
|
|
}
|
|
|
|
|
|
ret = await rebate_add(params_kw)
|
|
return ret |