feat: 商家罚单列表统计与证据图管理接口

This commit is contained in:
XingQue
2026-06-27 04:51:24 +08:00
parent 8f21491c72
commit 2445b39f3b
3 changed files with 275 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ from .views import WechatMiniProgramLoginView, UserInfoUpdateView, DashouXinxiAP
KefuUpdateDashouView, KefuPunishmentListView, KefuPunishmentActionView, KefuPunishmentDetailView, \
KefuWithdrawListView, KefuWithdrawDetailView, KefuWithdrawActionView, KefuPunishView, AdKfglView, AdKftjView, \
AdKfxgView,GuanshiRegisterView, WechatLoginAndGuanshiRegisterView,ZuzhangZhuceView, ZuzhangXinxiView,KefuForceCompleteView,HuoQuYaoQingRenView, DashouJianquanView, LaobanJianquanView,\
FaKuanJiFenTongJiView, DaShouFaKuanLieBiaoView,\
FaKuanJiFenTongJiView, DaShouFaKuanLieBiaoView, ShangjiaCufaTongjiView, ShangjiaFakuanLieBiaoView,\
FaKuanShenSuView, FaKuanPayView,FaKuanHuitiaoView, FaKuanPayPollView, FaKuanPayFailView,KaohePayView,KaohePayCallbackView, KaohePayPollView,KaohePayFailView, TixianAssetView, GuanshiContactView,TixianQueRenAutoView, TixianShenqingV3View, TixianCallbackV3View
from .tixian_shenhe_views import TixianZddkshApplyView
from .paihang_views import PhbHqsjView
@@ -135,6 +135,10 @@ urlpatterns = [
# 获取打手自己的罚款列表
path('dsfklbhq', DaShouFaKuanLieBiaoView.as_view(), name='获取打手自己的罚款列表'),
# 商家端处罚统计 / 金额罚单列表
path('sjcftjhq', ShangjiaCufaTongjiView.as_view(), name='商家处罚统计'),
path('sjfklbhq', ShangjiaFakuanLieBiaoView.as_view(), name='商家罚款列表'),
# 提交罚款申诉
path('fkss', FaKuanShenSuView.as_view(), name='提交罚款申诉'),

View File

@@ -11696,6 +11696,208 @@ class DaShouFaKuanLieBiaoView(APIView):
return Response({'code': 99, 'msg': '系统繁忙'}, status=500)
def _merchant_penalty_auth(user):
"""校验商家身份,返回 (yonghuid, None) 或 (None, error_response)。"""
try:
shangjia_profile = user.ShopProfile
if shangjia_profile.zhuangtai != 1:
return None, Response({
'code': 3, 'msg': '商家账号状态异常', 'data': None
}, status=status.HTTP_403_FORBIDDEN)
except UserShangjia.DoesNotExist:
return None, Response({
'code': 2, 'msg': '用户不是商家身份', 'data': None
}, status=status.HTTP_403_FORBIDDEN)
return user.UserUID, None
def _money_str(val):
if val is None:
return '0.00'
return str(val)
class ShangjiaCufaTongjiView(APIView):
"""
商家端罚款+积分处罚综合统计(含金额汇总)
路径: POST /yonghu/sjcftjhq
"""
permission_classes = [IsAuthenticated]
def post(self, request):
try:
yonghuid, err = _merchant_penalty_auth(request.user)
if err:
return err
fadan_agg = Penalty.query.filter(ApplicantID=yonghuid).aggregate(
total=Count('id'),
total_jine=Sum('FineAmount'),
daijiaona=Count('id', filter=Q(Status=1)),
daijiaona_jine=Sum('FineAmount', filter=Q(Status=1)),
yijiaona=Count('id', filter=Q(Status=2)),
yijiaona_jine=Sum('FineAmount', filter=Q(Status=2)),
shensuzhong=Count('id', filter=Q(Status=3)),
shensuzhong_jine=Sum('FineAmount', filter=Q(Status=3)),
yibohui=Count('id', filter=Q(Status=4)),
yibohui_jine=Sum('FineAmount', filter=Q(Status=4)),
shijidaozhang_jine=Sum('ApplicantBonusAmount', filter=Q(Status=2)),
)
jifen_agg = PenaltyRecord.query.filter(ApplicantID=yonghuid).aggregate(
total=Count('id'),
total_jifen=Sum('DeductedPoints'),
daichuli=Count('id', filter=Q(ApplyStatus=0) | Q(ApplyStatus=3)),
daichuli_jifen=Sum(
'DeductedPoints',
filter=Q(ApplyStatus=0) | Q(ApplyStatus=3),
),
yichuli=Count('id', filter=Q(ApplyStatus=1) | Q(ApplyStatus=2)),
yichuli_jifen=Sum(
'DeductedPoints',
filter=Q(ApplyStatus=1) | Q(ApplyStatus=2),
),
daichuli_0=Count('id', filter=Q(ApplyStatus=0)),
shensuzhong_3=Count('id', filter=Q(ApplyStatus=3)),
yichufa_1=Count('id', filter=Q(ApplyStatus=1)),
yibohui_2=Count('id', filter=Q(ApplyStatus=2)),
)
data = {
'fakuan': {
'total': fadan_agg['total'] or 0,
'total_jine': _money_str(fadan_agg['total_jine']),
'daijiaona': fadan_agg['daijiaona'] or 0,
'daijiaona_jine': _money_str(fadan_agg['daijiaona_jine']),
'yijiaona': fadan_agg['yijiaona'] or 0,
'yijiaona_jine': _money_str(fadan_agg['yijiaona_jine']),
'shensuzhong': fadan_agg['shensuzhong'] or 0,
'shensuzhong_jine': _money_str(fadan_agg['shensuzhong_jine']),
'yibohui': fadan_agg['yibohui'] or 0,
'yibohui_jine': _money_str(fadan_agg['yibohui_jine']),
'shijidaozhang_jine': _money_str(fadan_agg['shijidaozhang_jine']),
},
'jifen': {
'total': jifen_agg['total'] or 0,
'total_jifen': jifen_agg['total_jifen'] or 0,
'daichuli': jifen_agg['daichuli'] or 0,
'daichuli_jifen': jifen_agg['daichuli_jifen'] or 0,
'yichuli': jifen_agg['yichuli'] or 0,
'yichuli_jifen': jifen_agg['yichuli_jifen'] or 0,
'daichuli_0': jifen_agg['daichuli_0'] or 0,
'shensuzhong_3': jifen_agg['shensuzhong_3'] or 0,
'yichufa_1': jifen_agg['yichufa_1'] or 0,
'yibohui_2': jifen_agg['yibohui_2'] or 0,
},
}
return Response({'code': 0, 'msg': '获取统计成功', 'data': data})
except Exception as e:
logger.error(f"商家处罚统计异常: {e}", exc_info=True)
return Response({'code': 99, 'msg': '系统繁忙'}, status=500)
class ShangjiaFakuanLieBiaoView(APIView):
"""
商家端金额罚单列表
路径: POST /yonghu/sjfklbhq
"""
permission_classes = [IsAuthenticated]
def post(self, request):
try:
yonghuid, err = _merchant_penalty_auth(request.user)
if err:
return err
page = int(request.data.get('page', 1))
page_size = int(request.data.get('page_size', 10))
if page_size > 50:
page_size = 50
if page_size < 1:
page_size = 10
zhuangtai = request.data.get('zhuangtai')
sousuo_dingdan_id = str(request.data.get('sousuo_dingdan_id', '')).strip()
qs = Penalty.query.filter(ApplicantID=yonghuid)
if zhuangtai is not None and int(zhuangtai) in [1, 2, 3, 4]:
qs = qs.filter(Status=int(zhuangtai))
if sousuo_dingdan_id:
qs = qs.filter(RelatedOrderID__icontains=sousuo_dingdan_id)
qs = qs.order_by('-CreateTime')
paginator = Paginator(qs, page_size)
try:
page_obj = paginator.page(page)
except Exception:
return Response({
'code': 0, 'msg': '获取成功',
'data': {'list': [], 'has_more': False, 'page': page, 'page_size': page_size},
})
records = list(page_obj)
fadan_ids = [r.id for r in records]
staff_ids = list({r.ShopStaffUserID for r in records if r.ShopStaffUserID})
staff_name_map = {}
if staff_ids:
from merchant_ops.models import MerchantStaffMember
for m in MerchantStaffMember.query.filter(
merchant_id=yonghuid, staff_user_id__in=staff_ids
):
staff_name_map[m.staff_user_id] = m.display_name or m.staff_user_id
zhengju_map = {}
shensu_map = {}
if fadan_ids:
tupians = PenaltyAppealImage.query.filter(Penalty_id__in=fadan_ids).values(
'id', 'Penalty_id', 'ImageURL', 'Purpose'
)
for t in tupians:
fid = t['Penalty_id']
img = {'id': t['id'], 'url': t['ImageURL']}
if t['Purpose'] == 1:
zhengju_map.setdefault(fid, []).append(img)
else:
shensu_map.setdefault(fid, []).append(img)
chufa_list = []
for r in records:
rid = r.id
chufa_list.append({
'id': rid,
'beichufa_id': r.PenalizedUserID,
'guanliandingdan_id': r.RelatedOrderID or '',
'chufaliyou': r.Reason or '',
'fakuanjine': str(r.FineAmount),
'zhuangtai': r.Status,
'yingxiang_qiangdan': r.AffectsGrabbing,
'shensuliyou': r.AppealReason or '',
'bohuiliyou': r.RejectReason or '',
'applicant_bonus_amount': str(r.ApplicantBonusAmount or 0),
'shop_staff_user_id': r.ShopStaffUserID or '',
'staff_display_name': staff_name_map.get(r.ShopStaffUserID or '', ''),
'zhengju_tupian': zhengju_map.get(rid, []),
'shensu_tupian': shensu_map.get(rid, []),
'CreateTime': r.CreateTime.strftime('%Y-%m-%d %H:%M:%S') if r.CreateTime else '',
'UpdateTime': r.UpdateTime.strftime('%Y-%m-%d %H:%M:%S') if r.UpdateTime else '',
})
return Response({
'code': 0,
'msg': '获取成功',
'data': {
'list': chufa_list,
'has_more': page_obj.has_next(),
'page': page,
'page_size': page_size,
},
})
except Exception as e:
logger.error(f"商家罚款列表异常: {e}", exc_info=True)
return Response({'code': 99, 'msg': '系统繁忙'}, status=500)
class FaKuanShenSuView(APIView):
"""
罚款申诉提交/修改接口