fix: 订单分页缓存、统计与列表一致、admin-assignments 解析

This commit is contained in:
XingQue
2026-06-24 06:18:47 +08:00
parent c42f979082
commit b33bd3eb18
3 changed files with 123 additions and 96 deletions

View File

@@ -7049,7 +7049,7 @@ class KefuGetOrderListView(APIView):
q_conditions = base_q & Q(OrderID=dingdan_id)
else:
q_conditions = base_q
if leixing is not None:
if leixing is not None and str(leixing).strip() != '':
try:
leixing_int = int(leixing)
q_conditions &= Q(ProductTypeID=leixing_int)
@@ -7076,40 +7076,42 @@ class KefuGetOrderListView(APIView):
if clkf:
q_conditions &= Q(AssignedCS__icontains=clkf)
from jituan.services.club_context import orders_for_request
from jituan.services.club_context import orders_for_request, paginate_fluent_query
from orders.models import PlatformOrderExt
# ---------- 统计(仅按发单平台,非跨平台) ----------
# ---------- 统计与列表共用同一筛选条件 ----------
club_orders = orders_for_request(request)
platform_orders = club_orders.filter(Platform=1)
stats = platform_orders.aggregate(
filtered_orders = club_orders.filter(q_conditions)
stats = filtered_orders.aggregate(
total_orders=Count('id'),
completed_orders=Count('id', filter=Q(Status=3)),
refund_orders=Count('id', filter=Q(Status=5)),
pending_orders=Count('id', filter=Q(Status__in=[4,8]))
pending_orders=Count('id', filter=Q(Status__in=[4, 8]))
)
# ---------- 状态计数(所有状态都返回,非跨平台) ----------
status_counts = {
'all': platform_orders.count(),
'1,7': platform_orders.filter(Status__in=[1,7]).count(),
'2': platform_orders.filter(Status=2).count(),
'8': platform_orders.filter(Status=8).count(),
'3': platform_orders.filter(Status=3).count(),
'4': platform_orders.filter(Status=4).count(),
'5': platform_orders.filter(Status=5).count(),
'6': platform_orders.filter(Status=6).count(),
'all': filtered_orders.count(),
'1,7': filtered_orders.filter(Status__in=[1, 7]).count(),
'2': filtered_orders.filter(Status=2).count(),
'8': filtered_orders.filter(Status=8).count(),
'3': filtered_orders.filter(Status=3).count(),
'4': filtered_orders.filter(Status=4).count(),
'5': filtered_orders.filter(Status=5).count(),
'6': filtered_orders.filter(Status=6).count(),
}
# ---------- 分页查询(避免 only+select_related 导致列表为空) ----------
list_qs = club_orders.filter(q_conditions).select_related('pingtai_kuozhan').order_by('-CreateTime')
total_count = list_qs.count()
orders_page = list_qs[(page - 1) * page_size: page * page_size].to_list()
list_qs = filtered_orders.order_by('-CreateTime')
total_count, orders_page = paginate_fluent_query(list_qs, page, page_size)
order_ids = [o.OrderID for o in orders_page if o.OrderID]
ext_map = {}
if order_ids:
for ext in PlatformOrderExt.query.filter(Order__OrderID__in=order_ids).select_related('Order'):
if ext.Order:
ext_map[ext.Order.OrderID] = ext
# ---------- 获取老板昵称 ----------
laoban_ids = [
o.pingtai_kuozhan.BossID
for o in orders_page
if getattr(o, 'pingtai_kuozhan', None) and o.pingtai_kuozhan.BossID
ext.BossID for ext in ext_map.values() if ext.BossID
]
nickname_map = {}
if laoban_ids:
@@ -7121,7 +7123,7 @@ class KefuGetOrderListView(APIView):
result_list = []
for order in orders_page:
ext = getattr(order, 'pingtai_kuozhan', None)
ext = ext_map.get(order.OrderID)
laoban_id = ext.BossID if ext else ''
youxi_nicheng = nickname_map.get(laoban_id, order.Nickname or '')
result_list.append({
@@ -7219,7 +7221,7 @@ class KefuGetShangjiaOrderListView(APIView):
q_conditions = base_q & Q(OrderID=dingdan_id)
else:
q_conditions = base_q
if leixing is not None:
if leixing is not None and str(leixing).strip() != '':
try:
leixing_int = int(leixing)
q_conditions &= Q(ProductTypeID=leixing_int)
@@ -7250,40 +7252,41 @@ class KefuGetShangjiaOrderListView(APIView):
ShopProfile__nicheng__icontains=shangjia_nicheng
).values_list('UserUID', flat=True))
from jituan.services.club_context import orders_for_request
from jituan.services.club_context import orders_for_request, paginate_fluent_query
from orders.models import MerchantOrderExt
# ---------- 统计(仅按发单平台,非跨平台) ----------
club_orders = orders_for_request(request)
merchant_orders = club_orders.filter(Platform=2)
stats = merchant_orders.aggregate(
filtered_orders = club_orders.filter(q_conditions)
stats = filtered_orders.aggregate(
total_orders=Count('id'),
completed_orders=Count('id', filter=Q(Status=3)),
refund_orders=Count('id', filter=Q(Status=5)),
pending_orders=Count('id', filter=Q(Status__in=[4,8]))
pending_orders=Count('id', filter=Q(Status__in=[4, 8]))
)
# ---------- 状态计数(所有状态都返回,非跨平台) ----------
status_counts = {
'all': merchant_orders.count(),
'1,7': merchant_orders.filter(Status__in=[1,7]).count(),
'2': merchant_orders.filter(Status=2).count(),
'8': merchant_orders.filter(Status=8).count(),
'3': merchant_orders.filter(Status=3).count(),
'4': merchant_orders.filter(Status=4).count(),
'5': merchant_orders.filter(Status=5).count(),
'6': merchant_orders.filter(Status=6).count(),
'all': filtered_orders.count(),
'1,7': filtered_orders.filter(Status__in=[1, 7]).count(),
'2': filtered_orders.filter(Status=2).count(),
'8': filtered_orders.filter(Status=8).count(),
'3': filtered_orders.filter(Status=3).count(),
'4': filtered_orders.filter(Status=4).count(),
'5': filtered_orders.filter(Status=5).count(),
'6': filtered_orders.filter(Status=6).count(),
}
# ---------- 分页查询 ----------
list_qs = club_orders.filter(q_conditions).select_related('shangjia_kuozhan').order_by('-CreateTime')
total_count = list_qs.count()
orders_page = list_qs[(page - 1) * page_size: page * page_size].to_list()
list_qs = filtered_orders.order_by('-CreateTime')
total_count, orders_page = paginate_fluent_query(list_qs, page, page_size)
order_ids = [o.OrderID for o in orders_page if o.OrderID]
ext_map = {}
if order_ids:
for ext in MerchantOrderExt.query.filter(Order__OrderID__in=order_ids).select_related('Order'):
if ext.Order:
ext_map[ext.Order.OrderID] = ext
# ---------- 获取商家昵称 ----------
shangjia_ids = [
o.shangjia_kuozhan.MerchantID
for o in orders_page
if getattr(o, 'shangjia_kuozhan', None) and o.shangjia_kuozhan.MerchantID
ext.MerchantID for ext in ext_map.values() if ext.MerchantID
]
nickname_map = {}
if shangjia_ids:
@@ -7295,9 +7298,9 @@ class KefuGetShangjiaOrderListView(APIView):
result_list = []
for order in orders_page:
ext = getattr(order, 'shangjia_kuozhan', None)
ext = ext_map.get(order.OrderID)
shangjia_id = ext.MerchantID if ext else ''
youxi_nicheng = order.Nickname or '' # 商家订单的玩家昵称
youxi_nicheng = order.Nickname or ''
result_list.append({
'dingdan_id': order.OrderID or '',
'jieshao': order.Description or '',