feat: 商家订单准确统计、客服备注与按客服筛选

This commit is contained in:
XingQue
2026-06-27 05:17:36 +08:00
parent 2445b39f3b
commit fdecf2fe3c
10 changed files with 304 additions and 15 deletions

View File

@@ -2082,17 +2082,22 @@ class ShangjiaDingdanHuoquView(APIView):
MerchantID=yonghuid
).select_related('Order')
filter_payload = dict(data)
filter_payload['_merchant_id_filter'] = yonghuid
# 5. 状态过滤
base_qs = base_qs.filter(Order__Status__in=zhuangtai_list)
# 67. 类型 / 关键字 / 时间段
base_qs = apply_merchant_order_list_filters(base_qs, data)
# 67. 类型 / 关键字 / 时间段 / 客服筛选
base_qs = apply_merchant_order_list_filters(base_qs, filter_payload)
# 8. 计算待结算订单数量状态为8
pending_count = MerchantOrderExt.query.filter(
MerchantID=yonghuid,
Order__Status=8
).count()
# 8. 待结算统计(全量聚合,非分页求和
from orders.services.merchant_order_stats import (
build_merchant_order_stats, merchant_ext_qs, filter_by_staff_member,
)
stats_qs = merchant_ext_qs(yonghuid)
stats_qs = apply_merchant_order_list_filters(stats_qs, filter_payload)
order_stats = build_merchant_order_stats(stats_qs)
# 9. 排序、分页
total_count = base_qs.count()
@@ -2117,7 +2122,8 @@ class ShangjiaDingdanHuoquView(APIView):
'list': order_list,
'has_more': has_more,
'total': total_count,
'pending_count': pending_count
'pending_count': order_stats['pending_count'],
'pending_amount': order_stats['pending_amount'],
}
}, status=status.HTTP_200_OK)
@@ -2130,6 +2136,71 @@ class ShangjiaDingdanHuoquView(APIView):
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class ShangjiaShujuTongjiView(APIView):
"""
商家经营数据统计(订单表聚合)
POST /dingdan/sjshujutj
"""
permission_classes = [IsAuthenticated]
def post(self, request):
try:
current_user = request.user
yonghuid = current_user.UserUID
except AttributeError:
return Response({'code': 1, 'msg': '用户认证失败', 'data': None}, status=401)
try:
shangjia = current_user.ShopProfile
if shangjia.zhuangtai != 1:
return Response({'code': 403, 'msg': '商家状态异常', 'data': None}, status=403)
except Exception:
return Response({'code': 403, 'msg': '非商家用户', 'data': None}, status=403)
data = request.data or {}
from orders.services.merchant_order_list_filters import apply_merchant_order_list_filters
from orders.services.merchant_order_stats import merchant_ext_qs, build_merchant_order_stats
filter_payload = dict(data)
filter_payload['_merchant_id_filter'] = yonghuid
qs = merchant_ext_qs(yonghuid)
qs = apply_merchant_order_list_filters(qs, filter_payload)
order_stats = build_merchant_order_stats(qs)
penalty_stats = None
try:
from orders.models import Penalty, PenaltyRecord
from django.db.models import Q, Sum
fakuan_pending = Penalty.query.filter(ApplicantID=yonghuid, Status=1).count()
fakuan_pending_amt = Penalty.query.filter(ApplicantID=yonghuid, Status=1).aggregate(
amt=Sum('FineAmount')
)['amt']
jifen_pending = PenaltyRecord.query.filter(
ApplicantID=yonghuid,
).filter(Q(ApplyStatus=0) | Q(ApplyStatus=3)).count()
penalty_stats = {
'fakuan_pending': fakuan_pending,
'fakuan_pending_amount': str(fakuan_pending_amt or '0.00'),
'jifen_pending': jifen_pending,
}
except Exception:
penalty_stats = {
'fakuan_pending': 0,
'fakuan_pending_amount': '0.00',
'jifen_pending': 0,
}
return Response({
'code': 0,
'msg': '成功',
'data': {
'order': order_stats,
'penalty': penalty_stats,
'can_view_finance': True,
},
})
class ShangjiaDingdanXiangqingView(APIView):