async def getbz_order(ns): """查询订单详情/我的所有订单""" db = DBPools() async with db.sqlorContext('kboss') as sor: if ns: try: ns['del_flg'] = '0' ns['sort'] = 'create_at desc' if ns.get('id') and not ns.get('type'): # 查询订单详情 reacs = await sor.R('bz_order', ns) reacsgoods = await sor.R('order_goods', {'orderid': ns['id'], 'del_flg': '0'}) for i in reacsgoods: if i['discount'] == None or i['discount'] == 1.0: del i['discount'] goods = await sor.R('product', {'id': i['productid'], 'del_flg': '0'}) if len(goods) >= 1: i['productid'] = goods[0]['name'] i['ptype'] = goods[0]['ptype'] reacs[0]['order_goods'] = reacsgoods return {'status': True, 'data': reacs} elif ns.get('type') == '200': #筛选支付类型 user = await sor.R('users', {'id': await get_user(), 'del_flg': '0'}) orgid = await sor.R('organization', {'id': user[0]['orgid'], 'del_flg': '0'}) ns['customerid'] = orgid[0]['id'] if ns.get('id'): #根据订单号搜索 reacs = await sor.R('bz_order', {'id': ns['id']}) elif ns.get('start_time'): sql = """select * from bz_order where del_flg = 0 AND customerid = ${customerid}$ AND order_date >= ${start_time}$ AND order_date <= ${end_time}$ ORDER BY order_date DESC """ start_time = ns.get('start_time') + ' 00:00:00' end_time = ns.get('end_time') + ' 23:59:59' reacs = await sor.sqlExe(sql, {'start_time': start_time,'end_time': end_time,'customerid' :ns['customerid']}) else: reacs = await sor.R('bz_order', {'customerid':ns['customerid'],'sort':'order_date desc','order_status':ns.get('order_status'),'del_flg':'0'}) all_price = 0 if len(reacs) >= 1: for j in reacs: reacsgoods = await sor.R('order_goods', {'orderid': j['id'], 'del_flg': '0'}) countlist_price = 0 for i in reacsgoods: if i['discount'] == None or i['discount'] == 1.0: del i['discount'] goods = await sor.R('product', {'id': i['productid'], 'del_flg': '0'}) if len(goods) >= 1: i['productid'] = goods[0]['name'] j['order_goods'] = reacsgoods countlist_price += i['list_price'] countlist_price *= i['quantity'] if j['order_status'] == '1': all_price += countlist_price j['countprice'] = round(countlist_price,2) if j['countprice'] == 0: j['countprice'] = j['originalprice'] return {'status': True, 'data': reacs, 'all_price': round(all_price, 2)} else: # 我的所有订单 ns['del_flg'] = '0' ns['sort'] = 'create_at desc' user = await sor.R('users', {'id': await get_user(), 'del_flg': '0'}) orgid = await sor.R('organization', {'id': user[0]['orgid'], 'del_flg': '0'}) ns['customerid'] = orgid[0]['id'] reacs = await sor.R('bz_order', {'customerid':ns['customerid'],'sort':'create_at desc','del_flg':'0'}) all_price = 0 for j in reacs: reacsgoods = await sor.R('order_goods', {'orderid': j['id'], 'del_flg': '0'}) countlist_price = 0 for i in reacsgoods: if i['discount'] == None or i['discount'] == 1.0: del i['discount'] goods = await sor.R('product', {'id': i['productid'], 'del_flg': '0'}) if len(goods) < 1: continue i['ptype'] = goods[0]['ptype'] if len(goods) >= 1: i['productid'] = goods[0]['name'] j['order_goods'] = reacsgoods countlist_price += i['list_price'] countlist_price *= i['quantity'] if j['order_status'] == '1': all_price += countlist_price j['countprice'] = round(countlist_price,2) if j['countprice'] == 0: j['countprice'] = j['originalprice'] return {'status': True, 'data': reacs,'all_price': round(all_price,2)} except Exception as e: raise e return {'status': False, 'msg': '信息错误'} ret = await getbz_order(params_kw) return ret