64 lines
3.5 KiB
Plaintext
64 lines
3.5 KiB
Plaintext
async def upcp_discountrecord(ns):
|
|
"""
|
|
添加拉时间史客户折扣
|
|
"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
if ns:
|
|
discount = ns['discount']
|
|
ns.pop('discount')
|
|
start_date = ns['start_date']
|
|
ns.pop('start_date')
|
|
ns['del_flg'] = '0'
|
|
cp_discount = await sor.R('discount', ns)
|
|
ns.pop('id')
|
|
nsa = {}
|
|
nsa['sort'] = 'start_date'
|
|
nsa['receiverid'] = cp_discount[0]['receiverid']
|
|
nsa['productid'] = cp_discount[0]['productid']
|
|
cp_discounts = await sor.R('discount', nsa)
|
|
if len(cp_discounts) == 1:
|
|
if start_date < cp_discounts[0]['start_date']:
|
|
nss = {'id': uuid(), 'receiverid': cp_discounts[0]['receiverid'],
|
|
'productid': cp_discounts[0]['productid'],
|
|
'discount': discount, 'start_date': start_date, 'end_date': cp_discounts[0]['start_date']}
|
|
await sor.C('discount', nss)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
else:
|
|
await sor.U('discount', {'id': cp_discounts[0]['id'], 'end_date': start_date})
|
|
nss = {'id': uuid(), 'receiverid': cp_discounts[0]['receiverid'],
|
|
'productid': cp_discounts[0]['productid'],
|
|
'discount': discount, 'start_date': start_date, 'end_date': '9999-12-31'}
|
|
await sor.C('discount', nss)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
else:
|
|
data = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
id = ''
|
|
for i in cp_discounts:
|
|
if i['start_date'] == start_date:
|
|
return {'status': False, 'msg': '该时间段已有折扣'}
|
|
for i in cp_discounts:
|
|
if i['end_date'] > start_date > i['start_date']:
|
|
await sor.U('discount', {'id': i['id'], 'end_date': start_date})
|
|
nss = {'id': uuid(), 'receiverid': cp_discounts[0]['receiverid'],
|
|
'productid': cp_discounts[0]['productid'],
|
|
'discount': discount, 'start_date': start_date, 'end_date': i['end_date']}
|
|
await sor.C('discount', nss)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
for i in cp_discounts:
|
|
if i['start_date'] > data:
|
|
nss = {'id': uuid(), 'receiverid': cp_discounts[0]['receiverid'],
|
|
'productid': cp_discounts[0]['productid'],
|
|
'discount': discount, 'start_date': start_date, 'end_date': i['start_date']}
|
|
await sor.C('discount', nss)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
else:
|
|
await sor.U('discount', {'id': id, 'end_date': start_date})
|
|
nss = {'id ': uuid(), 'receiverid': cp_discounts[0]['receiverid'],
|
|
'productid': cp_discounts[0]['productid'],
|
|
'discount': discount, 'start_date': start_date, 'end_date': '9999-12-31'}
|
|
await sor.C('discount', nss)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
return {'status': False, 'msg': '配置失败'}
|
|
ret = await upcp_discountrecord(params_kw)
|
|
return ret |