async def getcp_discount(ns): """ 客户折扣列表 """ db = DBPools() async with db.sqlorContext('kboss') as sor: if ns: if not ns.get('customerid'): if ns.get('type'): if ns.get('orgname'): nss = {'orgname': '%' + ns.get('orgname') + '%'} sql = """select * from organization where del_flg = 0 and orgname like ${orgname}$""" elif ns.get('contactor_phone'): nss = {'contactor_phone': '%' + ns.get('contactor_phone') + '%'} sql = """select * from organization where del_flg = 0 and contactor_phone like ${contactor_phone}$""" reacsdata = await sor.sqlExe(sql, nss) salemanlist = [] for i in reacsdata: saleman = await sor.R('customer', {'salemanid': ns.get('salemanid'), 'del_flg': '0', 'customerid': i['id']}) if len(saleman) >= 1: salemanlist.append(saleman[0]) for i in salemanlist: reacsdata = await sor.R('organization', {'id': i['customerid'], 'del_flg': '0'}) if len(reacsdata) >= 1: i['organization'] = reacsdata[0] continue return {'status': True, 'data': salemanlist} saleman = await sor.R('customer', {'salemanid': ns.get('salemanid'), 'page': ns.get('page'), 'del_flg': '0'}) for i in saleman['rows']: reacsdata = await sor.R('organization', {'id': i['customerid'], 'del_flg': '0'}) if len(reacsdata) >= 1: i['organization'] = reacsdata[0] continue return {'status': True, 'data': saleman} else: org = await sor.R('organization',{'id':ns['customerid']}) product = await sor.R('product', {'page': ns.get('page'), 'del_flg': '0','reseller_orgid':org[0]['parentid'],'sort': 'create_at desc'}) for i in product['rows']: reacsdata = await sor.R('saleprotocol',{'sort': 'start_date desc', 'bid_orgid':ns['customerid'],'del_flg': '0'}) for k in reacsdata: product_salemode = await sor.R('product_salemode',{'del_flg': '0','protocolid':k['id'],'productid':i['id']}) for k in product_salemode: product_salemode = await sor.R('product_salemode', {'del_flg': '0', 'protocolid': k['id'], 'productid': i['id']}) if len(product_salemode) == 1: k['product_salemode'] = product_salemode[0] i['discount'] = reacsdata[0] if len(product_salemode) >= 1: date = datetime.datetime.now().strftime("%Y-%m-%d") for j in reacsdata: if j['start_date'] <= date < j['end_date']: i['discount'] = j break elif j['start_date'] >= date: i['discount'] = j break return {'status': True, 'data': product} return {'status': False, 'msg': '获取失败'} ret = await getcp_discount(params_kw) return ret