fix: 订单列表 FluentQuery 状态统计污染导致列表为空
This commit is contained in:
@@ -7077,31 +7077,24 @@ class KefuGetOrderListView(APIView):
|
||||
if clkf:
|
||||
q_conditions &= Q(AssignedCS__icontains=clkf)
|
||||
|
||||
from jituan.services.club_context import orders_for_request, paginate_fluent_query
|
||||
from jituan.services.club_context import (
|
||||
count_order_status_buckets,
|
||||
order_scope_qs,
|
||||
paginate_fluent_query,
|
||||
)
|
||||
from orders.models import PlatformOrderExt
|
||||
|
||||
# ---------- 统计与列表共用同一筛选条件 ----------
|
||||
club_orders = orders_for_request(request)
|
||||
filtered_orders = club_orders.filter(q_conditions)
|
||||
stats = filtered_orders.aggregate(
|
||||
# 旧 /yonghu/kfhqddlb 不按俱乐部过滤,与改造前行为一致
|
||||
stats_qs = order_scope_qs(None).filter(q_conditions)
|
||||
stats = stats_qs.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]))
|
||||
)
|
||||
status_counts = count_order_status_buckets(q_conditions, request=None)
|
||||
|
||||
status_counts = {
|
||||
'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 = filtered_orders.order_by('-CreateTime')
|
||||
list_qs = order_scope_qs(None).filter(q_conditions).order_by('-CreateTime')
|
||||
total_count, orders_page = paginate_fluent_query(list_qs, page, page_size)
|
||||
if total_count > 0 and not orders_page:
|
||||
start = (max(1, page) - 1) * page_size
|
||||
@@ -7256,30 +7249,23 @@ class KefuGetShangjiaOrderListView(APIView):
|
||||
ShopProfile__nicheng__icontains=shangjia_nicheng
|
||||
).values_list('UserUID', flat=True))
|
||||
|
||||
from jituan.services.club_context import orders_for_request, paginate_fluent_query
|
||||
from jituan.services.club_context import (
|
||||
count_order_status_buckets,
|
||||
order_scope_qs,
|
||||
paginate_fluent_query,
|
||||
)
|
||||
from orders.models import MerchantOrderExt
|
||||
|
||||
club_orders = orders_for_request(request)
|
||||
filtered_orders = club_orders.filter(q_conditions)
|
||||
stats = filtered_orders.aggregate(
|
||||
stats_qs = order_scope_qs(None).filter(q_conditions)
|
||||
stats = stats_qs.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]))
|
||||
)
|
||||
status_counts = count_order_status_buckets(q_conditions, request=None)
|
||||
|
||||
status_counts = {
|
||||
'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 = filtered_orders.order_by('-CreateTime')
|
||||
list_qs = order_scope_qs(None).filter(q_conditions).order_by('-CreateTime')
|
||||
total_count, orders_page = paginate_fluent_query(list_qs, page, page_size)
|
||||
if total_count > 0 and not orders_page:
|
||||
start = (max(1, page) - 1) * page_size
|
||||
|
||||
Reference in New Issue
Block a user