修复了管理员无法进后台的问题
This commit is contained in:
224
backend/view.py
224
backend/view.py
@@ -322,13 +322,13 @@ class GetAdminUserListView(APIView):
|
||||
|
||||
users = User.query.filter(
|
||||
user_type='kefu',
|
||||
kefu_profile__isnull=False
|
||||
).select_related('kefu_profile')
|
||||
KefuProfile__isnull=False
|
||||
).select_related('KefuProfile')
|
||||
|
||||
if phone:
|
||||
users = users.filter(phone__icontains=phone)
|
||||
if nicheng:
|
||||
users = users.filter(kefu_profile__nicheng__icontains=nicheng)
|
||||
users = users.filter(KefuProfile__nicheng__icontains=nicheng)
|
||||
|
||||
# 关键修正:先求值为列表,再传入 phone__in
|
||||
if role_code:
|
||||
@@ -365,11 +365,11 @@ class GetAdminUserListView(APIView):
|
||||
for r in user_roles
|
||||
]
|
||||
data_list.append({
|
||||
'phone': user.phone,
|
||||
'nicheng': user.kefu_profile.nicheng,
|
||||
'phone': user.Phone,
|
||||
'nicheng': user.KefuProfile.nicheng,
|
||||
'roles': roles_data,
|
||||
'status': user.kefu_profile.zhuangtai,
|
||||
'create_time': user.create_time.strftime('%Y-%m-%d %H:%M:%S') if hasattr(user, 'create_time') else '',
|
||||
'status': user.KefuProfile.zhuangtai,
|
||||
'create_time': user.UserCreateTime.strftime('%Y-%m-%d %H:%M:%S') if hasattr(user, 'UserCreateTime') else '',
|
||||
'update_time': user.update_time.strftime('%Y-%m-%d %H:%M:%S') if hasattr(user, 'update_time') else '',
|
||||
})
|
||||
|
||||
@@ -440,11 +440,11 @@ class GetAdminRolesView(APIView):
|
||||
page_size = int(request.data.get('pageSize', 20))
|
||||
|
||||
# 基础查询:存在客服扩展表
|
||||
users = User.query.filter(kefu_profile__isnull=False).select_related('kefu_profile')
|
||||
users = User.query.filter(KefuProfile__isnull=False).select_related('KefuProfile')
|
||||
if phone:
|
||||
users = users.filter(Phone__icontains=phone)
|
||||
if nicheng:
|
||||
users = users.filter(kefu_profile__nicheng__icontains=nicheng)
|
||||
users = users.filter(KefuProfile__nicheng__icontains=nicheng)
|
||||
if role_code:
|
||||
# 筛选拥有该角色的用户
|
||||
user_ids_with_role = UserRole.query.filter(role__role_code=role_code).values_list('account_id', flat=True)
|
||||
@@ -461,14 +461,14 @@ class GetAdminRolesView(APIView):
|
||||
data_list = []
|
||||
for user in page_obj:
|
||||
# 获取用户的所有角色
|
||||
user_roles = UserRole.query.filter(account_id=user.phone).select_related('role')
|
||||
user_roles = UserRole.query.filter(account_id=user.Phone).select_related('role')
|
||||
roles_data = [{'role_code': ur.role.role_code, 'role_name': ur.role.role_name} for ur in user_roles]
|
||||
data_list.append({
|
||||
'phone': user.phone,
|
||||
'nicheng': user.kefu_profile.nicheng,
|
||||
'phone': user.Phone,
|
||||
'nicheng': user.KefuProfile.nicheng,
|
||||
'roles': roles_data,
|
||||
'status': user.kefu_profile.zhuangtai,
|
||||
'create_time': user.create_time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'status': user.KefuProfile.zhuangtai,
|
||||
'create_time': user.UserCreateTime.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'update_time': user.update_time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
})
|
||||
|
||||
@@ -508,7 +508,7 @@ class ModifyAdminUserView(APIView):
|
||||
|
||||
try:
|
||||
target_user = User.query.get(Phone=target_phone)
|
||||
target_kefu = target_user.kefu_profile
|
||||
target_kefu = target_user.KefuProfile
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '用户不存在'})
|
||||
except UserKefu.DoesNotExist:
|
||||
@@ -600,7 +600,7 @@ class AddAdminUserView(APIView):
|
||||
return Response({'code': 400, 'msg': '密码和二级密码至少6位'})
|
||||
|
||||
# 校验手机号是否已被客服占用
|
||||
if User.query.filter(Phone=phone, kefu_profile__isnull=False).exists():
|
||||
if User.query.filter(Phone=phone, KefuProfile__isnull=False).exists():
|
||||
return Response({'code': 400, 'msg': '该账号已存在'})
|
||||
|
||||
# 生成唯一的 yonghuid(7位数字)
|
||||
@@ -743,8 +743,8 @@ class KefuGetDashouListView(APIView):
|
||||
for dashou in dashou_list:
|
||||
user = dashou.user
|
||||
result.append({
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'zaixianzhuangtai': dashou.zaixianzhuangtai,
|
||||
'zhanghaozhuangtai': dashou.zhanghaozhuangtai,
|
||||
'nicheng': dashou.nicheng or '',
|
||||
@@ -799,19 +799,19 @@ class KefuGetDashouDetailView(APIView):
|
||||
|
||||
# 4. 查询打手主表和扩展表
|
||||
try:
|
||||
user_main = User.query.select_related('dashou_profile').get(
|
||||
user_main = User.query.select_related('DashouProfile').get(
|
||||
UserUID=uid
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '打手不存在'})
|
||||
|
||||
try:
|
||||
dashou = user_main.dashou_profile
|
||||
dashou = user_main.DashouProfile
|
||||
except ObjectDoesNotExist:
|
||||
# 用户存在但未注册打手身份,返回基本信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.yonghuid,
|
||||
'avatar': user_main.avatar or '',
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': 0,
|
||||
'zhanghaozhuangtai': 0,
|
||||
'zhuangtai': 0,
|
||||
@@ -819,9 +819,9 @@ class KefuGetDashouDetailView(APIView):
|
||||
'chenghao': '',
|
||||
'dianhua': '',
|
||||
'wechat': '',
|
||||
'phone': user_main.phone or '',
|
||||
'create_time': user_main.create_time,
|
||||
'ip': user_main.ip or '',
|
||||
'phone': user_main.Phone or '',
|
||||
'create_time': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': 0,
|
||||
'chengjiaozongliang': 0,
|
||||
'tuikuanliang': 0,
|
||||
@@ -850,8 +850,8 @@ class KefuGetDashouDetailView(APIView):
|
||||
|
||||
# 5. 构建打手信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.yonghuid,
|
||||
'avatar': user_main.avatar or '',
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': dashou.zaixianzhuangtai,
|
||||
'zhanghaozhuangtai': dashou.zhanghaozhuangtai,
|
||||
'zhuangtai': dashou.zhuangtai,
|
||||
@@ -859,9 +859,9 @@ class KefuGetDashouDetailView(APIView):
|
||||
'chenghao': dashou.chenghao or '',
|
||||
'dianhua': dashou.dianhua or '',
|
||||
'wechat': dashou.wechat or '',
|
||||
'phone': user_main.phone or '',
|
||||
'create_time': user_main.create_time,
|
||||
'ip': user_main.ip or '',
|
||||
'phone': user_main.Phone or '',
|
||||
'create_time': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': dashou.jiedanzongliang,
|
||||
'chengjiaozongliang': dashou.chengjiaozongliang,
|
||||
'tuikuanliang': dashou.tuikuanliang,
|
||||
@@ -956,7 +956,7 @@ class KefuGetDashouDetailView(APIView):
|
||||
# 3. 查询打手主表和扩展表
|
||||
try:
|
||||
# 使用 select_related 预加载 dashou_profile,减少数据库查询
|
||||
user_main = User.query.select_related('dashou_profile').get(
|
||||
user_main = User.query.select_related('DashouProfile').get(
|
||||
UserUID=uid
|
||||
)
|
||||
except User.DoesNotExist:
|
||||
@@ -965,12 +965,12 @@ class KefuGetDashouDetailView(APIView):
|
||||
# 验证用户类型是否为打手(可选,但建议验证)
|
||||
# 如果该用户没有打手扩展表,则返回空信息(但前端会显示未注册)
|
||||
try:
|
||||
dashou = user_main.dashou_profile
|
||||
dashou = user_main.DashouProfile
|
||||
except ObjectDoesNotExist:
|
||||
# 用户存在但未注册打手身份,返回基本信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.yonghuid,
|
||||
'avatar': user_main.avatar or '',
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': 0,
|
||||
'zhanghaozhuangtai': 0,
|
||||
'zhuangtai': 0,
|
||||
@@ -978,9 +978,9 @@ class KefuGetDashouDetailView(APIView):
|
||||
'chenghao': '',
|
||||
'dianhua': '',
|
||||
'wechat': '',
|
||||
'phone': user_main.phone or '',
|
||||
'create_time': user_main.create_time,
|
||||
'ip': user_main.ip or '',
|
||||
'phone': user_main.Phone or '',
|
||||
'create_time': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': 0,
|
||||
'chengjiaozongliang': 0,
|
||||
'tuikuanliang': 0,
|
||||
@@ -1005,8 +1005,8 @@ class KefuGetDashouDetailView(APIView):
|
||||
|
||||
# 4. 构建打手信息
|
||||
user_info = {
|
||||
'yonghuid': user_main.yonghuid,
|
||||
'avatar': user_main.avatar or '',
|
||||
'yonghuid': user_main.UserUID,
|
||||
'avatar': user_main.Avatar or '',
|
||||
'zaixianzhuangtai': dashou.zaixianzhuangtai,
|
||||
'zhanghaozhuangtai': dashou.zhanghaozhuangtai,
|
||||
'zhuangtai': dashou.zhuangtai,
|
||||
@@ -1014,9 +1014,9 @@ class KefuGetDashouDetailView(APIView):
|
||||
'chenghao': dashou.chenghao or '',
|
||||
'dianhua': dashou.dianhua or '',
|
||||
'wechat': dashou.wechat or '',
|
||||
'phone': user_main.phone or '',
|
||||
'create_time': user_main.create_time,
|
||||
'ip': user_main.ip or '',
|
||||
'phone': user_main.Phone or '',
|
||||
'create_time': user_main.UserCreateTime,
|
||||
'ip': user_main.IP or '',
|
||||
'jiedanzongliang': dashou.jiedanzongliang,
|
||||
'chengjiaozongliang': dashou.chengjiaozongliang,
|
||||
'tuikuanliang': dashou.tuikuanliang,
|
||||
@@ -1107,7 +1107,7 @@ class KefuUpdateDashouView(APIView):
|
||||
# 3. 查询打手
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=dashou_id)
|
||||
dashou_profile = dashou_user.dashou_profile
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '打手不存在'})
|
||||
except UserDashou.DoesNotExist:
|
||||
@@ -1137,7 +1137,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.yue
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
xiugaitijiao=after,
|
||||
xiugaitijiaoq=before['yue'],
|
||||
@@ -1153,7 +1153,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.yue
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
xiugaitijiao=after,
|
||||
xiugaitijiaoq=before['yue'],
|
||||
@@ -1172,7 +1172,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.yajin
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
yajin=after,
|
||||
yyajin=before['yajin'],
|
||||
@@ -1188,7 +1188,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.yajin
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
yajin=after,
|
||||
yyajin=before['yajin'],
|
||||
@@ -1207,7 +1207,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.jifen
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
jifen=after,
|
||||
yjifen=before['jifen'],
|
||||
@@ -1223,7 +1223,7 @@ class KefuUpdateDashouView(APIView):
|
||||
after = dashou_profile.jifen
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
jifen=after,
|
||||
yjifen=before['jifen'],
|
||||
@@ -1241,7 +1241,7 @@ class KefuUpdateDashouView(APIView):
|
||||
dashou_profile.save()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
qitashuoming=f'修改账号状态为{new_status}',
|
||||
)
|
||||
@@ -1257,7 +1257,7 @@ class KefuUpdateDashouView(APIView):
|
||||
dashou_profile.save()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
qitashuoming=f'修改在线状态为{new_status}',
|
||||
)
|
||||
@@ -1273,7 +1273,7 @@ class KefuUpdateDashouView(APIView):
|
||||
dashou_profile.save()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
qitashuoming=f'修改接单状态为{new_status}',
|
||||
)
|
||||
@@ -1306,7 +1306,7 @@ class KefuUpdateDashouView(APIView):
|
||||
record.save()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
huiyuants=days,
|
||||
huiyuan_id=huiyuan_id,
|
||||
@@ -1326,7 +1326,7 @@ class KefuUpdateDashouView(APIView):
|
||||
record.delete()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
huiyuan_id=huiyuan_id,
|
||||
qitashuoming=f'移除会员 {huiyuan_id}',
|
||||
@@ -1345,7 +1345,7 @@ class KefuUpdateDashouView(APIView):
|
||||
dashou_profile.save()
|
||||
Xiugaijilu.query.create(
|
||||
yonghuid=dashou_id,
|
||||
xiugaiid=kefu.user.phone,
|
||||
xiugaiid=kefu.user.Phone,
|
||||
leixing=2,
|
||||
qitashuoming=f'修改称号:{before["chenghao"] or "无"} → {new_chenghao}',
|
||||
)
|
||||
@@ -1479,8 +1479,8 @@ class KefuGetShangjiaListView(APIView):
|
||||
for shangjia in shangjia_list:
|
||||
user = shangjia.user
|
||||
result.append({
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'nicheng': shangjia.nicheng or '',
|
||||
'yue': str(shangjia.yue), # 转换为字符串,避免前端精度问题
|
||||
'fabu': shangjia.fabu,
|
||||
@@ -1545,8 +1545,8 @@ class KefuGetShangjiaDetailView(APIView):
|
||||
user = shangjia.user
|
||||
|
||||
data = {
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'nicheng': shangjia.nicheng,
|
||||
'zhuangtai': shangjia.zhuangtai, # 1正常,2禁用
|
||||
'dianhua': shangjia.dianhua,
|
||||
@@ -2882,14 +2882,14 @@ class GetGuanliListView(APIView):
|
||||
|
||||
# 构建查询:从 User 开始,关联 UserGuanshi 和 UserBoss(左连接获取昵称)
|
||||
qs = User.query.filter(
|
||||
guanshi_profile__isnull=False # 确保是管事
|
||||
).select_related('guanshi_profile').select_related('boss_profile')
|
||||
GuanshiProfile__isnull=False # 确保是管事
|
||||
).select_related('GuanshiProfile').select_related('BossProfile')
|
||||
|
||||
# 关键词搜索(用户ID 或 昵称来自 boss_profile.nickname)
|
||||
if keyword:
|
||||
qs = qs.filter(
|
||||
Q(UserUID__icontains=keyword) |
|
||||
Q(boss_profile__nickname__icontains=keyword)
|
||||
Q(BossProfile__nickname__icontains=keyword)
|
||||
)
|
||||
|
||||
# 余额筛选(使用 guanshi_profile.yue)
|
||||
@@ -2897,9 +2897,9 @@ class GetGuanliListView(APIView):
|
||||
try:
|
||||
balance_val = Decimal(str(balance_value))
|
||||
if balance_op == 'gte':
|
||||
qs = qs.filter(guanshi_profile__yue__gte=balance_val)
|
||||
qs = qs.filter(GuanshiProfile__yue__gte=balance_val)
|
||||
elif balance_op == 'lte':
|
||||
qs = qs.filter(guanshi_profile__yue__lte=balance_val)
|
||||
qs = qs.filter(GuanshiProfile__yue__lte=balance_val)
|
||||
else:
|
||||
return Response({'code': 400, 'msg': '余额比较符无效'})
|
||||
except:
|
||||
@@ -2910,9 +2910,9 @@ class GetGuanliListView(APIView):
|
||||
try:
|
||||
commission_val = Decimal(str(commission_value))
|
||||
if commission_op == 'gte':
|
||||
qs = qs.filter(guanshi_profile__chongzhifenrun__gte=commission_val)
|
||||
qs = qs.filter(GuanshiProfile__chongzhifenrun__gte=commission_val)
|
||||
elif commission_op == 'lte':
|
||||
qs = qs.filter(guanshi_profile__chongzhifenrun__lte=commission_val)
|
||||
qs = qs.filter(GuanshiProfile__chongzhifenrun__lte=commission_val)
|
||||
else:
|
||||
return Response({'code': 400, 'msg': '分佣比较符无效'})
|
||||
except:
|
||||
@@ -2923,9 +2923,9 @@ class GetGuanliListView(APIView):
|
||||
try:
|
||||
invite_val = int(invite_count_value)
|
||||
if invite_count_op == 'gte':
|
||||
qs = qs.filter(guanshi_profile__yaogingshuliang__gte=invite_val)
|
||||
qs = qs.filter(GuanshiProfile__yaogingshuliang__gte=invite_val)
|
||||
elif invite_count_op == 'lte':
|
||||
qs = qs.filter(guanshi_profile__yaogingshuliang__lte=invite_val)
|
||||
qs = qs.filter(GuanshiProfile__yaogingshuliang__lte=invite_val)
|
||||
else:
|
||||
return Response({'code': 400, 'msg': '邀请数量比较符无效'})
|
||||
except:
|
||||
@@ -2937,7 +2937,7 @@ class GetGuanliListView(APIView):
|
||||
status_val = int(status)
|
||||
if status_val not in (0, 1):
|
||||
raise ValueError
|
||||
qs = qs.filter(guanshi_profile__zhuangtai=status_val)
|
||||
qs = qs.filter(GuanshiProfile__zhuangtai=status_val)
|
||||
except:
|
||||
return Response({'code': 400, 'msg': '状态值无效'})
|
||||
|
||||
@@ -2951,11 +2951,11 @@ class GetGuanliListView(APIView):
|
||||
# 构建返回数据
|
||||
result = []
|
||||
for user in users:
|
||||
guanshi = user.guanshi_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
guanshi = user.GuanshiProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
result.append({
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'nickname': boss.nickname if boss else '',
|
||||
'zhuangtai': guanshi.zhuangtai,
|
||||
'yaogingshuliang': guanshi.yaogingshuliang,
|
||||
@@ -3010,9 +3010,9 @@ class GetGuanliDetailView(APIView):
|
||||
|
||||
# 查询用户主表和管事扩展表
|
||||
try:
|
||||
user = User.query.select_related('guanshi_profile', 'boss_profile').get(UserUID=yonghuid)
|
||||
guanshi = user.guanshi_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
user = User.query.select_related('GuanshiProfile', 'BossProfile').get(UserUID=yonghuid)
|
||||
guanshi = user.GuanshiProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '管事不存在'})
|
||||
except UserGuanshi.DoesNotExist:
|
||||
@@ -3020,9 +3020,9 @@ class GetGuanliDetailView(APIView):
|
||||
|
||||
# 基础信息
|
||||
base_data = {
|
||||
'yonghuid': user.yonghuid,
|
||||
'yonghuid': user.UserUID,
|
||||
'nickname': boss.nickname if boss else '',
|
||||
'avatar': user.avatar or '',
|
||||
'avatar': user.Avatar or '',
|
||||
'dianhua': guanshi.dianhua or '',
|
||||
'wechat': guanshi.wechat or '',
|
||||
'zhuangtai': guanshi.zhuangtai,
|
||||
@@ -3132,8 +3132,8 @@ class UpdateGuanliView(APIView):
|
||||
# 查询管事对象(不在事务外加锁,事务内加锁)
|
||||
try:
|
||||
user = User.query.get(UserUID=yonghuid)
|
||||
guanshi = user.guanshi_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
guanshi = user.GuanshiProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '用户不存在'})
|
||||
except UserGuanshi.DoesNotExist:
|
||||
@@ -3143,8 +3143,8 @@ class UpdateGuanliView(APIView):
|
||||
with transaction.atomic():
|
||||
# 重新获取加锁对象
|
||||
user = User.objects.select_for_update().get(UserUID=yonghuid)
|
||||
guanshi = user.guanshi_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
guanshi = user.GuanshiProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
|
||||
# ---------- 1. 基础信息修改(需要4400a)----------
|
||||
nickname = request.data.get('nickname')
|
||||
@@ -3176,7 +3176,7 @@ class UpdateGuanliView(APIView):
|
||||
except:
|
||||
pass
|
||||
if avatar is not None:
|
||||
user.avatar = avatar
|
||||
user.Avatar = avatar
|
||||
user.save()
|
||||
guanshi.save()
|
||||
|
||||
@@ -3559,7 +3559,7 @@ class GetZuzhangListView(APIView):
|
||||
# 3. 检查是否拥有组长管理所需权限(6600a ~ 6600e 任一)
|
||||
required_perms = ['6600a', '6600b', '6600c', '6600d', '6600e']
|
||||
if not any(perm in permissions for perm in required_perms):
|
||||
logger.warning(f"用户 {request.user.phone} 尝试访问组长列表但缺少必要权限,已有权限: {permissions}")
|
||||
logger.warning(f"用户 {request.user.Phone} 尝试访问组长列表但缺少必要权限,已有权限: {permissions}")
|
||||
return Response({'code': 403, 'msg': '您无权访问组长管理页面'})
|
||||
|
||||
# 4. 提取请求参数(分页 + 筛选)
|
||||
@@ -3579,7 +3579,7 @@ class GetZuzhangListView(APIView):
|
||||
commission_value = request.data.get('commission_value')
|
||||
|
||||
# 5. 构建基础 QuerySet(预加载关联表)
|
||||
queryset = UserZuzhang.query.select_related('user', 'user__boss_profile').all()
|
||||
queryset = UserZuzhang.query.select_related('user', 'user__BossProfile').all()
|
||||
|
||||
# 6. 应用筛选条件(使用 ORM 安全过滤)
|
||||
if keyword:
|
||||
@@ -3633,12 +3633,12 @@ class GetZuzhangListView(APIView):
|
||||
for zu in paged_queryset:
|
||||
user = zu.user
|
||||
nickname = ''
|
||||
if hasattr(user, 'boss_profile') and user.boss_profile:
|
||||
nickname = user.boss_profile.nickname or ''
|
||||
if hasattr(user, 'BossProfile') and user.BossProfile:
|
||||
nickname = user.BossProfile.nickname or ''
|
||||
|
||||
data_list.append({
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'nickname': nickname,
|
||||
'fenyong_zonge': float(zu.fenyong_zonge),
|
||||
'ketixian_jine': float(zu.ketixian_jine),
|
||||
@@ -3702,9 +3702,9 @@ class GetZuzhangDetailView(APIView):
|
||||
|
||||
# 查询组长主表、扩展表、老板扩展表(昵称)
|
||||
try:
|
||||
user = User.query.select_related('zuzhang_profile', 'boss_profile').get(UserUID=yonghuid)
|
||||
zuzhang = user.zuzhang_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
user = User.query.select_related('ZuzhangProfile', 'BossProfile').get(UserUID=yonghuid)
|
||||
zuzhang = user.ZuzhangProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '组长不存在'})
|
||||
except UserZuzhang.DoesNotExist:
|
||||
@@ -3712,9 +3712,9 @@ class GetZuzhangDetailView(APIView):
|
||||
|
||||
# 基础信息
|
||||
base_data = {
|
||||
'yonghuid': user.yonghuid,
|
||||
'yonghuid': user.UserUID,
|
||||
'nickname': boss.nickname if boss else '',
|
||||
'avatar': user.avatar or '',
|
||||
'avatar': user.Avatar or '',
|
||||
'dianhua': '', # 组长表无电话字段?组长扩展表没有电话/微信,但前端可能需要,可从User关联?实际上组长表无电话字段,这里留空或从其他表获取
|
||||
'wechat': '',
|
||||
'zhuangtai': zuzhang.zhuangtai,
|
||||
@@ -3826,8 +3826,8 @@ class UpdateZuzhangView(APIView):
|
||||
# 查询组长对象
|
||||
try:
|
||||
user = User.query.get(UserUID=yonghuid)
|
||||
zuzhang = user.zuzhang_profile
|
||||
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
|
||||
zuzhang = user.ZuzhangProfile
|
||||
boss = user.BossProfile if hasattr(user, 'BossProfile') else None
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '用户不存在'})
|
||||
except UserZuzhang.DoesNotExist:
|
||||
@@ -3861,7 +3861,7 @@ class UpdateZuzhangView(APIView):
|
||||
boss.nickname = nickname
|
||||
boss.save()
|
||||
if avatar:
|
||||
user.avatar = avatar
|
||||
user.Avatar = avatar
|
||||
user.save()
|
||||
# 组长表没有电话/微信字段,如需存储可暂存到User或忽略
|
||||
# 这里不处理
|
||||
@@ -5944,7 +5944,7 @@ class FaKuanChuLiView(APIView):
|
||||
return Response({'code': 400, 'msg': '无效的操作类型'})
|
||||
|
||||
# 记录处理者(使用 request.user 的 phone)
|
||||
penalty.ProcessorID = request.user.phone
|
||||
penalty.ProcessorID = request.user.Phone
|
||||
penalty.ProcessorIdentity = 2 # 这里假设处理者是售后身份,可根据实际业务获取
|
||||
penalty.save()
|
||||
|
||||
@@ -6033,7 +6033,7 @@ class FaKuanChuangJianView(APIView):
|
||||
penalty = Penalty.query.create(
|
||||
PenalizedUserID=PenalizedUserID,
|
||||
Identity=shenfen,
|
||||
ApplicantID=request.user.phone, # 申请人(客服)手机号
|
||||
ApplicantID=request.user.Phone, # 申请人(客服)手机号
|
||||
ApplicantIdentity=2, # 售后身份
|
||||
Reason=Reason,
|
||||
FineAmount=FineAmount,
|
||||
@@ -6134,7 +6134,7 @@ class FineApplyView(APIView):
|
||||
with transaction.atomic():
|
||||
penalty = Penalty.query.create(
|
||||
PenalizedUserID=dashou_id,
|
||||
ApplicantID=request.user.phone,
|
||||
ApplicantID=request.user.Phone,
|
||||
Identity=1, # 被处罚人身份:1 打手
|
||||
Reason=Reason,
|
||||
FineAmount=FineAmount,
|
||||
@@ -6204,7 +6204,7 @@ class PunishDashouView(APIView):
|
||||
# 查询打手
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=dashou_id)
|
||||
dashou = dashou_user.dashou_profile
|
||||
dashou = dashou_user.DashouProfile
|
||||
except User.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '打手用户不存在'})
|
||||
except ObjectDoesNotExist:
|
||||
@@ -7984,7 +7984,7 @@ class KhgglView(APIView):
|
||||
filter_bankuai_name = request.data.get('bankuai_name', '').strip()
|
||||
|
||||
# 基础查询:所有审核官,预加载用户及打手扩展表
|
||||
queryset = UserShenheguan.query.select_related('user__dashou_profile')
|
||||
queryset = UserShenheguan.query.select_related('user__DashouProfile')
|
||||
|
||||
if filter_yonghuid:
|
||||
queryset = queryset.filter(user__UserUID=filter_yonghuid)
|
||||
@@ -8015,7 +8015,7 @@ class KhgglView(APIView):
|
||||
tag_ids = Chenghao.query.filter(bankuai=bk, leixing='dashou').values_list('id', flat=True)
|
||||
count = YonghuChenghao.query.filter(
|
||||
chenghao_id__in=tag_ids,
|
||||
yonghu__dashou_profile__isnull=False
|
||||
yonghu__DashouProfile__isnull=False
|
||||
).values('yonghu').distinct().count()
|
||||
bankuai_dashou_count_map[bk.bankuai_id] = count
|
||||
|
||||
@@ -8042,7 +8042,7 @@ class KhgglView(APIView):
|
||||
for sg in shenheguan_list:
|
||||
user = sg.user
|
||||
# 获取该审核官关联的板块
|
||||
bk_qs = KaoheguanBankuai.query.filter(kaoheguan_id=user.yonghuid).select_related('bankuai')
|
||||
bk_qs = KaoheguanBankuai.query.filter(kaoheguan_id=user.UserUID).select_related('bankuai')
|
||||
bankuai_info = []
|
||||
for bk in bk_qs:
|
||||
bid = bk.bankuai.bankuai_id
|
||||
@@ -8052,12 +8052,12 @@ class KhgglView(APIView):
|
||||
'dashou_count': bankuai_dashou_count_map.get(bid, 0)
|
||||
})
|
||||
|
||||
dashou_nick = user.dashou_profile.nicheng if hasattr(user, 'dashou_profile') and user.dashou_profile else ''
|
||||
dashou_nick = user.DashouProfile.nicheng if hasattr(user, 'DashouProfile') and user.DashouProfile else ''
|
||||
|
||||
data_list.append({
|
||||
'yonghuid': user.yonghuid,
|
||||
'avatar': user.avatar or '',
|
||||
'phone': user.phone or '',
|
||||
'yonghuid': user.UserUID,
|
||||
'avatar': user.Avatar or '',
|
||||
'phone': user.Phone or '',
|
||||
'zhuangtai': sg.zhuangtai,
|
||||
'shenhe_zhuangtai': sg.shenhe_zhuangtai,
|
||||
'shenhe_zongshu': sg.shenhe_zongshu,
|
||||
@@ -8231,7 +8231,7 @@ class ZxkfghdsView(APIView):
|
||||
shangjia_id = shangjia_ext.MerchantID
|
||||
# 获取商家昵称用于新订单扩展表
|
||||
shangjia_user = User.query.get(UserUID=shangjia_id)
|
||||
shangjia_nicheng = shangjia_user.shop_profile.nicheng or f"商家{shangjia_id}"
|
||||
shangjia_nicheng = shangjia_user.ShopProfile.nicheng or f"商家{shangjia_id}"
|
||||
except (ObjectDoesNotExist, UserShangjia.DoesNotExist):
|
||||
logger.error(f"商家信息缺失,订单: {OrderID}")
|
||||
return Response({'code': 500, 'msg': '商家数据异常'})
|
||||
@@ -8240,7 +8240,7 @@ class ZxkfghdsView(APIView):
|
||||
with transaction.atomic():
|
||||
# 5.1 订单状态改为已退款
|
||||
old_order.Status = 5
|
||||
old_order.AssignedCS = current_user.phone
|
||||
old_order.AssignedCS = current_user.Phone
|
||||
old_order.save()
|
||||
|
||||
# 5.2 处理接单打手(若有)
|
||||
@@ -8248,7 +8248,7 @@ class ZxkfghdsView(APIView):
|
||||
if dashou_id:
|
||||
try:
|
||||
dashou_user = User.query.get(UserUID=dashou_id)
|
||||
dashou_profile = dashou_user.dashou_profile
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
dashou_profile.tuikuanliang += 1 # 退款次数+1
|
||||
dashou_profile.zhuangtai = 1 # 设为空闲
|
||||
dashou_profile.save()
|
||||
@@ -8261,7 +8261,7 @@ class ZxkfghdsView(APIView):
|
||||
defaults={
|
||||
'PlayerID': dashou_id or '',
|
||||
'ApplicantID': '',
|
||||
'ProcessorID': current_user.phone,
|
||||
'ProcessorID': current_user.Phone,
|
||||
'Reason': '客服更换打手退款',
|
||||
'ApplyStatus': 1,
|
||||
'Amount': old_order.Amount or 0,
|
||||
|
||||
Reference in New Issue
Block a user