fix: 二次迁移名额可列表展示,保存后跳转用户页
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1110,3 +1110,50 @@ def serialize_token(token_row: ClubMigrateToken) -> dict:
|
||||
'expire_at': token_row.expire_at.isoformat() if token_row.expire_at else '',
|
||||
'asset_snapshot': token_row.asset_snapshot or {},
|
||||
}
|
||||
|
||||
|
||||
def lookup_migrate_user_brief(uid: str) -> dict:
|
||||
"""后台二次名额:校验用户并返回简要资料。"""
|
||||
uid = str(uid or '').strip()
|
||||
user = _load_user(uid)
|
||||
if not user:
|
||||
return {'exists': False, 'from_uid': uid, 'nicheng': '', 'phone': ''}
|
||||
nicheng = ''
|
||||
try:
|
||||
ds = getattr(user, 'DashouProfile', None)
|
||||
if ds and getattr(ds, 'nicheng', None):
|
||||
nicheng = str(ds.nicheng)
|
||||
except Exception:
|
||||
pass
|
||||
if not nicheng:
|
||||
nicheng = str(getattr(user, 'UserName', '') or getattr(user, 'Phone', '') or '')
|
||||
return {
|
||||
'exists': True,
|
||||
'from_uid': uid,
|
||||
'nicheng': nicheng,
|
||||
'phone': str(getattr(user, 'Phone', '') or ''),
|
||||
'club_id': str(getattr(user, 'ClubID', '') or ''),
|
||||
}
|
||||
|
||||
|
||||
def serialize_user_quota(row: ClubMigrateUserQuota, plan: Optional[ClubMigratePlan] = None, user_info: Optional[dict] = None) -> dict:
|
||||
plan = plan or ClubMigratePlan.query.filter(plan_id=row.plan_id).first()
|
||||
info = user_info if user_info is not None else lookup_migrate_user_brief(row.from_uid)
|
||||
used = success_count(row.plan_id, row.from_uid)
|
||||
allowed = max_allowed_success(plan, row.from_uid) if plan else (1 + int(row.max_extra_times or 0))
|
||||
return {
|
||||
'plan_id': row.plan_id,
|
||||
'from_uid': row.from_uid,
|
||||
'max_extra_times': int(row.max_extra_times or 0),
|
||||
'reason': row.reason or '',
|
||||
'updated_by': row.updated_by or '',
|
||||
'created_at': row.CreateTime.isoformat() if row.CreateTime else '',
|
||||
'updated_at': row.UpdateTime.isoformat() if row.UpdateTime else '',
|
||||
'nicheng': info.get('nicheng') or '',
|
||||
'phone': info.get('phone') or '',
|
||||
'user_club_id': info.get('club_id') or '',
|
||||
'success_count': used,
|
||||
'max_allowed': allowed,
|
||||
'remaining': max(0, int(allowed) - int(used)),
|
||||
'can_migrate_again': used < allowed,
|
||||
}
|
||||
|
||||
@@ -358,10 +358,16 @@ class ClubMigrateAdminView(APIView):
|
||||
from_uid = (request.data.get('from_uid') or '').strip()
|
||||
if not plan_id or not from_uid:
|
||||
return Response({'code': 400, 'msg': '缺少 plan_id/from_uid'})
|
||||
plan = ClubMigratePlan.query.filter(plan_id=plan_id).first()
|
||||
if not plan:
|
||||
return Response({'code': 404, 'msg': '计划不存在'})
|
||||
try:
|
||||
extra = int(request.data.get('max_extra_times') or 1)
|
||||
except (TypeError, ValueError):
|
||||
return Response({'code': 400, 'msg': 'max_extra_times 无效'})
|
||||
user_info = migrate_svc.lookup_migrate_user_brief(from_uid)
|
||||
if not user_info.get('exists'):
|
||||
return Response({'code': 404, 'msg': f'用户不存在:{from_uid}'})
|
||||
row, _ = ClubMigrateUserQuota.query.get_or_create(
|
||||
plan_id=plan_id,
|
||||
from_uid=from_uid,
|
||||
@@ -374,10 +380,27 @@ class ClubMigrateAdminView(APIView):
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': '已设置二次名额',
|
||||
'data': migrate_svc.serialize_user_quota(row, plan=plan, user_info=user_info),
|
||||
})
|
||||
|
||||
if action == 'list_quota':
|
||||
plan_id = (request.data.get('plan_id') or '').strip()
|
||||
if not plan_id:
|
||||
return Response({'code': 400, 'msg': '缺少 plan_id'})
|
||||
plan = ClubMigratePlan.query.filter(plan_id=plan_id).first()
|
||||
if not plan:
|
||||
return Response({'code': 404, 'msg': '计划不存在'})
|
||||
rows = list(
|
||||
ClubMigrateUserQuota.query.filter(plan_id=plan_id).order_by('-id')[:200]
|
||||
)
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': 'ok',
|
||||
'data': {
|
||||
'plan_id': plan_id,
|
||||
'from_uid': from_uid,
|
||||
'max_extra_times': row.max_extra_times,
|
||||
'list': [
|
||||
migrate_svc.serialize_user_quota(r, plan=plan)
|
||||
for r in rows
|
||||
],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user