110 lines
6.2 KiB
Plaintext
110 lines
6.2 KiB
Plaintext
async def getbz_order(ns={}):
|
|
"""查询订单详情/我的所有订单"""
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
users_id = await get_user()
|
|
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)
|
|
|
|
# 兼容第三范式产品展示 这段代码可注释
|
|
if reacs and reacs[0].get('specdataid'):
|
|
specdata = await sor.R('specificdata', {'id': reacs[0].get('specdataid'), 'del_flg': '0'})
|
|
if specdata:
|
|
specdata_dumps = json.dumps(specdata[0]) if isinstance(specdata[0], dict) else specdata[0]
|
|
if 'internalip' in specdata_dumps and 'externalip' in specdata_dumps:
|
|
reacs[0]['spec_data'] = json.loads(json.loads(specdata_dumps)['spec_data'])
|
|
|
|
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']
|
|
i['discount'] = i['discount'] * 10 if i.get('discount') else None
|
|
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': users_id, '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': users_id, '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'})
|
|
actual_all_price = 0
|
|
for j in reacs:
|
|
reacsgoods = await sor.R('order_goods', {'orderid': j['id'], 'del_flg': '0'})
|
|
all_price = 0
|
|
countlist_price = 0
|
|
business_op = j['business_op']
|
|
for i in reacsgoods:
|
|
if i['discount'] == None or i['discount'] == 1.0:
|
|
del i['discount']
|
|
i['discount'] = i['discount'] * 10 if i.get('discount') else None
|
|
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'] * i['quantity']
|
|
actual_price = i['price'] * i['quantity']
|
|
# countlist_price += i['list_price']
|
|
# countlist_price *= i['quantity']
|
|
if j['order_status'] == '1':
|
|
all_price += countlist_price
|
|
if business_op != 'BUY_REVERSE':
|
|
actual_all_price += actual_price
|
|
j['countprice'] = round(all_price,2)
|
|
if j['countprice'] == 0:
|
|
j['countprice'] = j['originalprice']
|
|
return {'status': True, 'data': reacs,'all_price': round(actual_all_price,2)}
|
|
except Exception as e:
|
|
raise e
|
|
return {'status': False, 'msg': '信息错误'}
|
|
|
|
ret = await getbz_order(params_kw)
|
|
return ret |