31 lines
1.8 KiB
Plaintext
31 lines
1.8 KiB
Plaintext
async def addpromote_discount(ns):
|
|
"""配置促销产品折扣"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
if ns:
|
|
for i in eval(ns.get('productid')):
|
|
ord = await sor.R('promote_discount',
|
|
{'del_flg': '0', 'promotingid': ns['promotingid'], 'productid': i})
|
|
if len(ord) >= 1:
|
|
return {'status': False, 'msg': '该产品已有折扣'}
|
|
promotings = await sor.R('promoting', {'id': ns['promotingid']})
|
|
date = await get_business_date(sor=None)
|
|
if promotings[0]['end_date'] < date:
|
|
return {'status': False, 'msg': '该活动已过期'}
|
|
for i in eval(ns.get('productid')):
|
|
providerid = (await sor.R('product', {'id': i}))[0]['providerid']
|
|
protocolid = (await sor.R('saleprotocol', {'offer_orgid': providerid}))[0]['id']
|
|
product_discount = (await sor.R('product_salemode', {'protocolid': protocolid, 'productid': i}))[0]['discount']
|
|
if product_discount is None:
|
|
ns = {'id': uuid(), 'promotingid': ns['promotingid'], 'productid': i, 'discount': ns['discount']}
|
|
await sor.C('promote_discount', ns)
|
|
continue
|
|
if float(ns['discount']) <= float(product_discount):
|
|
return {'status': False, 'msg': '折扣率不能小于供应商折扣'}
|
|
ns = {'id': uuid(), 'promotingid': ns['promotingid'], 'productid': i, 'discount': ns['discount']}
|
|
await sor.C('promote_discount', ns)
|
|
return {'status': True, 'msg': '配置成功'}
|
|
return {'status': False, 'msg': '参数错误'}
|
|
|
|
ret = await addpromote_discount(params_kw)
|
|
return ret |