fix: 订单列表、超管1383714110、财务szjilu累计、俱乐部配置API

This commit is contained in:
XingQue
2026-06-24 06:27:01 +08:00
parent b33bd3eb18
commit 5ae01a9ff2
9 changed files with 183 additions and 22 deletions

View File

@@ -10,8 +10,7 @@ from rest_framework.views import APIView
from rest_framework.throttling import AnonRateThrottle
from rest_framework_simplejwt.tokens import RefreshToken
from jituan.models import Club, AdminAssignment
from jituan.constants import ADMIN_ROLE_LABELS
from jituan.constants import SUPER_ADMIN_PHONES
from jituan.services.admin_context import build_admin_club_context
from jituan.services.wechat_login import login_or_register_by_club
from jituan.services.caiwu_stats import build_caiwu_payload
@@ -94,7 +93,7 @@ class ClubKefuLoginView(APIView):
if not user_mains:
admin_candidates = User.query.filter(Phone=phone)
for admin_user in admin_candidates:
if admin_user.IsSuperuser or admin_user.UserType == 'admin':
if admin_user.IsSuperuser or admin_user.UserType == 'admin' or admin_user.Phone in SUPER_ADMIN_PHONES:
user_mains = [admin_user]
break
@@ -110,7 +109,7 @@ class ClubKefuLoginView(APIView):
if not user.CheckPassword(password):
continue
password_matched = True
is_admin = user.IsSuperuser or user.UserType == 'admin'
is_admin = user.IsSuperuser or user.UserType == 'admin' or user.Phone in SUPER_ADMIN_PHONES
if is_admin:
target_user = user
target_kefu = None
@@ -210,7 +209,12 @@ class ClubAdminAssignmentListView(APIView):
return permissions
user = request.user
is_super = bool(user.IsSuperuser) or user.UserType == 'admin'
from jituan.constants import SUPER_ADMIN_PHONES
is_super = (
bool(user.IsSuperuser)
or user.UserType == 'admin'
or getattr(user, 'Phone', '') in SUPER_ADMIN_PHONES
)
if is_super:
qs = AdminAssignment.query.filter(status=1).order_by('yonghuid', '-is_primary', 'club_id')
else:
@@ -259,6 +263,95 @@ class ClubAdminAssignmentListView(APIView):
return Response({'code': 99, 'msg': '加载任职数据失败,请确认已执行 migrate jituan'}, status=500)
class ClubManageView(APIView):
"""POST /jituan/houtai/club-manage — 俱乐部主数据与密钥配置(超级管理员)。"""
permission_classes = [IsAuthenticated]
parser_classes = [JSONParser]
_EDITABLE_FIELDS = (
'name', 'status', 'wx_appid', 'wx_secret', 'mch_id', 'pay_app_id', 'api_v3_key',
'cert_serial_no', 'private_key_path', 'platform_cert_dir',
'official_appid', 'official_secret', 'official_token', 'encoding_aes_key',
'template_id', 'template_max_per_minute', 'h5_domain', 'oss_prefix',
'goeasy_appkey', 'goeasy_secret', 'sort_order',
)
def _serialize(self, club, full=False):
base = {
'club_id': club.club_id,
'name': club.name,
'status': club.status,
'wx_appid': club.wx_appid,
'h5_domain': club.h5_domain,
'oss_prefix': club.oss_prefix,
'mch_id': club.mch_id,
'pay_app_id': club.pay_app_id,
'goeasy_appkey': club.goeasy_appkey,
'template_id': club.template_id,
'sort_order': club.sort_order,
}
if full:
base.update({
'wx_secret': club.wx_secret,
'api_v3_key': club.api_v3_key,
'cert_serial_no': club.cert_serial_no,
'private_key_path': club.private_key_path,
'platform_cert_dir': club.platform_cert_dir,
'official_appid': club.official_appid,
'official_secret': club.official_secret,
'official_token': club.official_token,
'encoding_aes_key': club.encoding_aes_key,
'goeasy_secret': club.goeasy_secret,
'template_max_per_minute': club.template_max_per_minute,
})
return base
def post(self, request):
from jituan.constants import CLUB_ID_DEFAULT, SUPER_ADMIN_PHONES
username = (request.data.get('phone') or request.data.get('username') or '').strip()
if not username:
return Response({'code': 401, 'msg': '缺少账号'}, status=401)
kefu_obj, permissions = verify_kefu_permission(request, username)
if kefu_obj is None:
return permissions
if '000001' not in permissions:
return Response({'code': 403, 'msg': '仅超级管理员可管理俱乐部配置'}, status=403)
action = (request.data.get('action') or 'get').strip()
club_id = (request.data.get('club_id') or '').strip() or CLUB_ID_DEFAULT
if action == 'list':
clubs = Club.query.order_by('sort_order', 'club_id')
return Response({
'code': 0,
'data': [self._serialize(c, full=False) for c in clubs],
})
club = Club.query.filter(club_id=club_id).first()
if not club and action != 'create':
return Response({'code': 1, 'msg': f'俱乐部 {club_id} 不存在'})
if action == 'get':
return Response({'code': 0, 'data': self._serialize(club, full=True)})
if action == 'update':
update_fields = []
for field in self._EDITABLE_FIELDS:
if field in request.data:
setattr(club, field, request.data[field])
update_fields.append(field)
if update_fields:
club.save(update_fields=update_fields)
return Response({
'code': 0,
'msg': '保存成功',
'data': self._serialize(club, full=True),
})
return Response({'code': 400, 'msg': '无效 action支持 list/get/update'})
class ClubCaiwuView(APIView):
"""
俱乐部维度财务(新接口)。