进行了 GVSDSDK 迁移,可能存在诸多问题

This commit is contained in:
2026-06-17 20:37:47 +08:00
parent 72770ad73b
commit d00f0d08e5
132 changed files with 161593 additions and 4827 deletions

View File

@@ -56,9 +56,10 @@ from backend.models import Role, Permission, RolePermission, UserRole, TixianRiT
## users
from users.models import (
UserMain, UserGuanshi, UserBoss, UserZuzhang,
UserGuanshi, UserBoss, UserZuzhang,
UserKefu, UserDashou, Xiugaijilu, UserShangjia, UserShenheguan
)
from gvsdsdk.models import User
## orders
from orders.models import (
@@ -315,7 +316,7 @@ class GetAdminUserListView(APIView):
page = int(request.data.get('page', 1))
page_size = int(request.data.get('pageSize', 20))
users = UserMain.query.filter(
users = User.query.filter(
user_type='kefu',
kefu_profile__isnull=False
).select_related('kefu_profile')
@@ -420,7 +421,7 @@ class GetAdminRolesView(APIView):
page_size = int(request.data.get('pageSize', 20))
# 基础查询user_type='kefu' 且存在客服扩展表
users = UserMain.query.filter(user_type='kefu', kefu_profile__isnull=False).select_related('kefu_profile')
users = User.query.filter(user_type='kefu', kefu_profile__isnull=False).select_related('kefu_profile')
if phone:
users = users.filter(phone__icontains=phone)
if nicheng:
@@ -487,9 +488,9 @@ class ModifyAdminUserView(APIView):
return Response({'code': 400, 'msg': '缺少目标用户账号'})
try:
target_user = UserMain.query.get(phone=target_phone, user_type='kefu')
target_user = User.query.get(phone=target_phone, user_type='kefu')
target_kefu = target_user.kefu_profile
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '用户不存在'})
except UserKefu.DoesNotExist:
return Response({'code': 404, 'msg': '用户扩展信息缺失'})
@@ -574,25 +575,25 @@ class AddAdminUserView(APIView):
return Response({'code': 400, 'msg': '密码和二级密码至少6位'})
# 校验手机号是否已被占用(且 user_type='kefu'
if UserMain.query.filter(phone=phone, user_type='kefu').exists():
if User.query.filter(phone=phone, user_type='kefu').exists():
return Response({'code': 400, 'msg': '该账号已存在'})
# 生成唯一的 yonghuid7位数字
while True:
yonghuid = str(random.randint(1000000, 9999999))
if not UserMain.query.filter(yonghuid=yonghuid).exists():
if not User.query.filter(yonghuid=yonghuid).exists():
break
# 生成唯一的 openid格式admin_{时间戳}_{随机6位}
timestamp = str(int(time.time() * 1000))
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6))
openid = f"admin_{timestamp}_{random_suffix}"
while UserMain.query.filter(openid=openid).exists():
while User.query.filter(openid=openid).exists():
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=6))
openid = f"admin_{timestamp}_{random_suffix}"
with transaction.atomic():
user_main = UserMain.query.create(
user_main = User.query.create(
yonghuid=yonghuid,
openid=openid,
phone=phone,
@@ -756,10 +757,10 @@ class KefuGetDashouDetailView(APIView):
# 4. 查询打手主表和扩展表
try:
user_main = UserMain.query.select_related('dashou_profile').get(
user_main = User.query.select_related('dashou_profile').get(
yonghuid=uid
)
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'})
try:
@@ -913,10 +914,10 @@ class KefuGetDashouDetailView(APIView):
# 3. 查询打手主表和扩展表
try:
# 使用 select_related 预加载 dashou_profile减少数据库查询
user_main = UserMain.query.select_related('dashou_profile').get(
user_main = User.query.select_related('dashou_profile').get(
yonghuid=uid
)
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'}, status=status.HTTP_404_NOT_FOUND)
# 验证用户类型是否为打手(可选,但建议验证)
@@ -1063,9 +1064,9 @@ class KefuUpdateDashouView(APIView):
# 3. 查询打手
try:
dashou_user = UserMain.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_profile = dashou_user.dashou_profile
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'})
except UserDashou.DoesNotExist:
return Response({'code': 404, 'msg': '打手扩展信息缺失'})
@@ -2837,8 +2838,8 @@ class GetGuanliListView(APIView):
invite_count_value = request.data.get('invite_count_value')
status = request.data.get('status')
# 构建查询:从 UserMain 开始,关联 UserGuanshi 和 UserBoss左连接获取昵称
qs = UserMain.query.filter(
# 构建查询:从 User 开始,关联 UserGuanshi 和 UserBoss左连接获取昵称
qs = User.query.filter(
guanshi_profile__isnull=False # 确保是管事
).select_related('guanshi_profile').select_related('boss_profile')
@@ -2967,10 +2968,10 @@ class GetGuanliDetailView(APIView):
# 查询用户主表和管事扩展表
try:
user = UserMain.query.select_related('guanshi_profile', 'boss_profile').get(yonghuid=yonghuid)
user = User.query.select_related('guanshi_profile', 'boss_profile').get(yonghuid=yonghuid)
guanshi = user.guanshi_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '管事不存在'})
except UserGuanshi.DoesNotExist:
return Response({'code': 404, 'msg': '用户不是管事'})
@@ -3088,10 +3089,10 @@ class UpdateGuanliView(APIView):
# 查询管事对象(不在事务外加锁,事务内加锁)
try:
user = UserMain.query.get(yonghuid=yonghuid)
user = User.query.get(yonghuid=yonghuid)
guanshi = user.guanshi_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '用户不存在'})
except UserGuanshi.DoesNotExist:
return Response({'code': 404, 'msg': '用户不是管事'})
@@ -3099,7 +3100,7 @@ class UpdateGuanliView(APIView):
# 开始事务,内部使用 select_for_update
with transaction.atomic():
# 重新获取加锁对象
user = UserMain.objects.select_for_update().get(yonghuid=yonghuid)
user = User.objects.select_for_update().get(yonghuid=yonghuid)
guanshi = user.guanshi_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
@@ -3659,10 +3660,10 @@ class GetZuzhangDetailView(APIView):
# 查询组长主表、扩展表、老板扩展表(昵称)
try:
user = UserMain.query.select_related('zuzhang_profile', 'boss_profile').get(yonghuid=yonghuid)
user = User.query.select_related('zuzhang_profile', 'boss_profile').get(yonghuid=yonghuid)
zuzhang = user.zuzhang_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '组长不存在'})
except UserZuzhang.DoesNotExist:
return Response({'code': 404, 'msg': '用户不是组长'})
@@ -3672,7 +3673,7 @@ class GetZuzhangDetailView(APIView):
'yonghuid': user.yonghuid,
'nickname': boss.nickname if boss else '',
'avatar': user.avatar or '',
'dianhua': '', # 组长表无电话字段?组长扩展表没有电话/微信但前端可能需要可从UserMain关联?实际上组长表无电话字段,这里留空或从其他表获取
'dianhua': '', # 组长表无电话字段?组长扩展表没有电话/微信但前端可能需要可从User关联实际上组长表无电话字段这里留空或从其他表获取
'wechat': '',
'zhuangtai': zuzhang.zhuangtai,
'yaoqingma': zuzhang.yaoqingma,
@@ -3782,10 +3783,10 @@ class UpdateZuzhangView(APIView):
# 查询组长对象
try:
user = UserMain.query.get(yonghuid=yonghuid)
user = User.query.get(yonghuid=yonghuid)
zuzhang = user.zuzhang_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '用户不存在'})
except UserZuzhang.DoesNotExist:
return Response({'code': 404, 'msg': '用户不是组长'})
@@ -3820,7 +3821,7 @@ class UpdateZuzhangView(APIView):
if avatar:
user.avatar = avatar
user.save()
# 组长表没有电话/微信字段如需存储可暂存到UserMain或忽略
# 组长表没有电话/微信字段如需存储可暂存到User或忽略
# 这里不处理
# ---------- 2. 可提现金额修改6600a6600b----------
@@ -5025,7 +5026,7 @@ class ShopModifyView(APIView):
return Response({'code': 400, 'msg': '必填字段缺失用户ID、账号、密码、店铺名称'})
# 检查用户是否存在
if not UserMain.query.filter(yonghuid=yonghu_id).exists():
if not User.query.filter(yonghuid=yonghu_id).exists():
return Response({'code': 404, 'msg': '用户不存在'})
# 检查凭证是否已存在
@@ -5961,11 +5962,11 @@ class FaKuanChuangJianView(APIView):
# 验证用户是否存在对应的扩展表
try:
user = UserMain.query.get(yonghuid=beichufa_id)
user = User.query.get(yonghuid=beichufa_id)
profile_attr = SHENFEN_PROFILE_MAP.get(shenfen)
if not profile_attr or not hasattr(user, profile_attr):
return Response({'code': 400, 'msg': '该用户不是所选身份'})
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '用户不存在'})
# 处理图片上传
@@ -6161,9 +6162,9 @@ class PunishDashouView(APIView):
# 查询打手
try:
dashou_user = UserMain.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(yonghuid=dashou_id)
dashou = dashou_user.dashou_profile
except UserMain.DoesNotExist:
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手用户不存在'})
except ObjectDoesNotExist:
return Response({'code': 400, 'msg': '该用户不是打手'})
@@ -8188,7 +8189,7 @@ class ZxkfghdsView(APIView):
shangjia_ext = old_order.shangjia_kuozhan
shangjia_id = shangjia_ext.shangjia_id
# 获取商家昵称用于新订单扩展表
shangjia_user = UserMain.query.get(yonghuid=shangjia_id)
shangjia_user = User.query.get(yonghuid=shangjia_id)
shangjia_nicheng = shangjia_user.shop_profile.nicheng or f"商家{shangjia_id}"
except (ObjectDoesNotExist, UserShangjia.DoesNotExist):
logger.error(f"商家信息缺失,订单: {dingdan_id}")
@@ -8205,12 +8206,12 @@ class ZxkfghdsView(APIView):
dashou_id = old_order.jiedan_dashou_id
if dashou_id:
try:
dashou_user = UserMain.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile.tuikuanliang += 1 # 退款次数+1
dashou_profile.zhuangtai = 1 # 设为空闲
dashou_profile.save()
except (UserMain.DoesNotExist, ObjectDoesNotExist):
except (User.DoesNotExist, ObjectDoesNotExist):
logger.warning(f"打手 {dashou_id} 不存在,跳过更新")
# 5.3 更新退款记录表