This commit is contained in:
hrx 2025-10-09 18:14:03 +08:00
commit bf38e76be0
3 changed files with 273 additions and 98 deletions

View File

@ -583,6 +583,22 @@ async def get_baidu_orderlist(ns={}):
nss['resourceids'] = ','.join(i['shortIds']) if i.get('shortIds') else ''
nss['orderkey'] = i.get('key')
try:
# 保存配置configurations 存入specdata表中
if i.get('configurations'):
specdata = json.dumps(i['configurations'], ensure_ascii=False)
ns_specificdata = {
'id': uuid(),
'productid': product[0]['id'],
'spec_data': specdata,
}
nss['spec_id'] = ns_specificdata['id']
await sor.C('specificdata', ns_specificdata)
except Exception as e:
print('保存配置configurations失败', str(e))
with open('baidu_error.log', 'a') as f:
f.write('保存配置configurations失败' + str(e) + '\n')
# 如果是续费订单 由于没有返回日期, 重新计算日期
if order_type == 'RENEW':
history_time_sql = "select resourcestarttime, resourceendtime from order_goods where FIND_IN_SET('%s', resourceids) order by resourceendtime desc;" % \

View File

@ -1,110 +1,159 @@
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 not users_id:
server_error(401)
# 兼容第三范式产品展示 这段代码可注释
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'])
# 分页参数
page = int(ns.get('page', 1))
size = int(ns.get('size', 10))
offset = (page - 1) * size
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'):
customerid = orgid[0]['id']
params = {'customerid': customerid, 'del_flg': '0'}
# 构建查询SQL主要查询order_goods并关联bz_order的部分字段
sql = """
SELECT
og.*,
bo.customerid,
bo.order_date,
bo.source,
bo.order_status,
bo.business_op,
bo.ordertype,
bo.originalprice,
bo.autoreneworder
FROM order_goods og
JOIN bz_order bo ON og.orderid = bo.id
WHERE og.del_flg = '0'
AND bo.del_flg = '0'
AND bo.customerid = ${customerid}$
"""
# 构建计数SQL
count_sql = """
SELECT COUNT(*) as total_count
FROM order_goods og
JOIN bz_order bo ON og.orderid = bo.id
WHERE og.del_flg = '0'
AND bo.del_flg = '0'
AND bo.customerid = ${customerid}$
"""
# 根据订单号搜索
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']})
if ns.get('id'):
sql += " AND bo.id LIKE ${order_id}$"
count_sql += " AND bo.id LIKE ${order_id}$"
params['order_id'] = f"%{ns.get('id')}%"
# 时间范围查询
if ns.get('start_time'):
sql += " AND bo.order_date >= ${start_time}$"
count_sql += " AND bo.order_date >= ${start_time}$"
params['start_time'] = ns.get('start_time') + ' 00:00:00'
if ns.get('end_time'):
sql += " AND bo.order_date <= ${end_time}$"
count_sql += " AND bo.order_date <= ${end_time}$"
params['end_time'] = ns.get('end_time') + ' 23:59:59'
# 订单状态查询
if ns.get('order_status'):
sql += " AND bo.order_status = ${order_status}$"
count_sql += " AND bo.order_status = ${order_status}$"
params['order_status'] = ns.get('order_status')
# 添加排序
sql += " ORDER BY bo.order_date DESC"
# 获取总记录数
total_result = await sor.sqlExe(count_sql, params)
total_count = total_result[0]['total_count'] if total_result else 0
# 添加分页
sql += " LIMIT ${size}$ OFFSET ${offset}$"
params['size'] = size
params['offset'] = offset
# 执行查询
order_goods_list = await sor.sqlExe(sql, params)
if not order_goods_list:
return {
'status': True,
'data': [],
'pagination': {'page': page, 'size': size, 'total': 0}
}
# 处理数据
for item in order_goods_list:
# 清理折扣数据
if item['discount'] is None or item['discount'] == 1.0:
del item['discount']
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'})
item['discount'] = item['discount'] * 10 # 转换为百分比显示
# 处理结果中原价list_price和数量quantity 计算总价
if item['list_price'] is None:
item['list_price'] = 0
if item['quantity'] is None:
item['quantity'] = 0
item['origin_amout'] = float(item['list_price']) * float(item['quantity'])
# 获取产品名称
goods = await sor.R('product', {'id': item['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)}
item['product_name'] = goods[0]['name']
item['product_type'] = goods[0]['ptype']
# 获取产品配置详情
item['spec_data'] = None
if item.get('spec_id'):
specdata_list = await sor.R('specificdata', {'id': item['spec_id'], 'del_flg': '0'})
if specdata_list and specdata_list[0]['spec_data']:
item['spec_data'] = json.loads(specdata_list[0]['spec_data'])
# 格式化订单状态
status_mapping = {
'0': '未支付',
'1': '已支付',
'2': '已关闭',
'3': '已取消',
'4': '后付费'
}
item['order_status_text'] = status_mapping.get(item['order_status'], '未知状态')
# 格式化业务操作
business_op_mapping = {
'BUY': '购买',
'RENEW': '续费',
'BUY_REVERSE': '退款',
# 'UPGRADE': '升级'
}
item['business_op_text'] = business_op_mapping.get(item['business_op'], item['business_op'])
return {
'status': True,
'data': order_goods_list,
'pagination': {
'page': page,
'size': size,
'total': total_count
}
}
except Exception as e:
raise e
return {'status': False, 'msg': '信息错误'}
import traceback
traceback.print_exc()
return {'status': False, 'msg': '信息错误: %s' % str(e) + traceback.format_exc()}
ret = await getbz_order(params_kw)
return ret

View File

@ -0,0 +1,110 @@
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