salescrm/b/promoting/get_invitecodepromoting.dspy
2025-10-27 15:50:44 +08:00

30 lines
1.6 KiB
Plaintext

async def get_invitecodepromoting(ns):
db = DBPools()
async with db.sqlorContext('kboss') as sor:
# 邀请码表 invitecode 促销表 promoting 促销产品表 promote_discount 产品表productid
dates = datetime.datetime.now()
if not ns.get('domain_name'):
sql = """select * from promoting where del_flg = 0 and orgid = 'mIWUHBeeDM8mwAFPIQ8pS' and end_date > ${dates}$ order by create_at desc"""
promoting = await sor.sqlExe(sql, {'dates': dates})
if ns.get('domain_name'):
reseller = await sor.R('reseller', {'domain_name':ns.get('domain_name')})
sql = """select * from promoting where del_flg = 0 and orgid = ${org}$ and end_date > ${dates}$ order by create_at desc"""
promoting = await sor.sqlExe(sql, {'dates': dates,'org':reseller[0]['orgid']})
if len(promoting) >= 1:
for i in promoting:
lists = []
promote_discount = await sor.R('promote_discount', {'promotingid': i['id']})
for j in promote_discount:
dicts = {}
product = await sor.R('product', {'id': j['productid']})
dicts['id'] = j['id']
dicts['nameofactivity'] = i['title']
dicts['name'] = product[0]['name']
dicts['discount'] = j['discount']
lists.append(dicts)
i['discount'] = lists
return {'status': True, 'data': promoting}
ret = await get_invitecodepromoting(params_kw)
return ret