修复了管理员无法进后台的问题
This commit is contained in:
100
config/views.py
100
config/views.py
@@ -185,7 +185,7 @@ class AdminConfigQueryView(APIView):
|
||||
user_main = request.user
|
||||
|
||||
# 验证账号:比较user_main的phone与前端传递的zhanghao
|
||||
if user_main.phone != zhanghao:
|
||||
if user_main.Phone != zhanghao:
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '账号不匹配',
|
||||
@@ -193,7 +193,7 @@ class AdminConfigQueryView(APIView):
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# 验证用户类型是否为管理员
|
||||
if user_main.user_type != 'admin':
|
||||
if user_main.UserType != 'admin':
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '无权限',
|
||||
@@ -202,7 +202,7 @@ class AdminConfigQueryView(APIView):
|
||||
|
||||
# 验证管理员扩展表是否存在
|
||||
try:
|
||||
admin_profile = user_main.admin_profile
|
||||
admin_profile = user_main.AdminProfile
|
||||
except AdminProfile.DoesNotExist:
|
||||
return Response({
|
||||
'code': 1,
|
||||
@@ -307,14 +307,14 @@ class AdminUploadImageView(APIView):
|
||||
|
||||
# 验证用户权限
|
||||
user_main = request.user
|
||||
if user_main.phone != zhanghao:
|
||||
if user_main.Phone != zhanghao:
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '账号不匹配',
|
||||
'data': None
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
if user_main.user_type != 'admin':
|
||||
if user_main.UserType != 'admin':
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '无权限',
|
||||
@@ -322,7 +322,7 @@ class AdminUploadImageView(APIView):
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
admin_profile = user_main.admin_profile
|
||||
admin_profile = user_main.AdminProfile
|
||||
except AdminProfile.DoesNotExist:
|
||||
return Response({
|
||||
'code': 1,
|
||||
@@ -419,14 +419,14 @@ class AdminUpdateConfigView(APIView):
|
||||
|
||||
# 验证用户权限
|
||||
user_main = request.user
|
||||
if user_main.phone != zhanghao:
|
||||
if user_main.Phone != zhanghao:
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '账号不匹配',
|
||||
'data': None
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
if user_main.user_type != 'admin':
|
||||
if user_main.UserType != 'admin':
|
||||
return Response({
|
||||
'code': 1,
|
||||
'msg': '无权限',
|
||||
@@ -434,7 +434,7 @@ class AdminUpdateConfigView(APIView):
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
admin_profile = user_main.admin_profile
|
||||
admin_profile = user_main.AdminProfile
|
||||
except AdminProfile.DoesNotExist:
|
||||
return Response({
|
||||
'code': 1,
|
||||
@@ -817,7 +817,7 @@ class DashouPaihangView(APIView):
|
||||
dashou_nicheng = dashou.nicheng or '未设置昵称'
|
||||
|
||||
# 获取头像(相对URL)
|
||||
touxiang_url = user_main.avatar or ''
|
||||
touxiang_url = user_main.Avatar or ''
|
||||
|
||||
# 获取收入金额
|
||||
if leixing == 1:
|
||||
@@ -826,7 +826,7 @@ class DashouPaihangView(APIView):
|
||||
shouyi_jine = dashou.jinyueshouyi
|
||||
|
||||
paihang_list.append({
|
||||
'uid': user_main.yonghuid,
|
||||
'uid': user_main.UserUID,
|
||||
'touxiang': touxiang_url,
|
||||
'nicheng': dashou_nicheng,
|
||||
'jine': float(shouyi_jine), # 转换为float方便前端处理
|
||||
@@ -884,7 +884,7 @@ class DashouPaihangView(APIView):
|
||||
guanshi_nicheng = boss_profile.nickname if boss_profile else '未设置昵称'
|
||||
|
||||
# 获取头像(相对URL)
|
||||
touxiang_url = user_main.avatar or ''
|
||||
touxiang_url = user_main.Avatar or ''
|
||||
|
||||
# 获取数量
|
||||
if leixing == 1:
|
||||
@@ -893,7 +893,7 @@ class DashouPaihangView(APIView):
|
||||
chongzhi_shuliang = guanshi.jinyuechongzhi
|
||||
|
||||
paihang_list.append({
|
||||
'uid': user_main.yonghuid,
|
||||
'uid': user_main.UserUID,
|
||||
'touxiang': touxiang_url,
|
||||
'nicheng': guanshi_nicheng,
|
||||
'jine': float(chongzhi_shuliang), # 这里jine字段实际存储的是数量
|
||||
@@ -951,7 +951,7 @@ class DashouPaihangView(APIView):
|
||||
shangjia_nicheng = boss_profile.nickname if boss_profile else '未设置昵称'
|
||||
|
||||
# 获取头像(相对URL)
|
||||
touxiang_url = user_main.avatar or ''
|
||||
touxiang_url = user_main.Avatar or ''
|
||||
|
||||
# 获取流水金额
|
||||
if leixing == 1:
|
||||
@@ -960,7 +960,7 @@ class DashouPaihangView(APIView):
|
||||
liushui_jine = shangjia.jinyueliushui
|
||||
|
||||
paihang_list.append({
|
||||
'uid': user_main.yonghuid,
|
||||
'uid': user_main.UserUID,
|
||||
'touxiang': touxiang_url,
|
||||
'nicheng': shangjia_nicheng,
|
||||
'jine': float(liushui_jine),
|
||||
@@ -1016,7 +1016,7 @@ class GetAdminZhanghaoView(APIView):
|
||||
user_type = getattr(user, 'user_type', '')
|
||||
if user_type != 'admin':
|
||||
# 检查是否有管理员扩展表
|
||||
if not hasattr(user, 'admin_profile'):
|
||||
if not hasattr(user, 'AdminProfile'):
|
||||
return Response({
|
||||
'code': 403,
|
||||
'message': '无管理员权限',
|
||||
@@ -1032,12 +1032,12 @@ class GetAdminZhanghaoView(APIView):
|
||||
um.id,
|
||||
um.phone,
|
||||
um.yonghuid,
|
||||
um.user_type,
|
||||
um.UserType,
|
||||
COALESCE(COUNT(xjl.id), 0) as jilushuliang
|
||||
FROM user_main um
|
||||
LEFT JOIN xiugaijilu xjl ON um.phone = xjl.xiugaiid
|
||||
WHERE um.user_type = 'admin'
|
||||
GROUP BY um.id, um.phone, um.yonghuid, um.user_type
|
||||
WHERE um.UserType = 'admin'
|
||||
GROUP BY um.id, um.phone, um.yonghuid, um.UserType
|
||||
ORDER BY um.create_time DESC
|
||||
"""
|
||||
|
||||
@@ -1116,7 +1116,7 @@ class GetXiugaiJiluView(APIView):
|
||||
# 🔥 2. 验证是否为管理员(user_type='admin'字符串)
|
||||
user_type = getattr(user, 'user_type', '')
|
||||
if user_type != 'admin':
|
||||
if not hasattr(user, 'admin_profile'):
|
||||
if not hasattr(user, 'AdminProfile'):
|
||||
return Response({
|
||||
'code': 403,
|
||||
'message': '无管理员权限',
|
||||
@@ -1330,7 +1330,7 @@ class ShangjiaMobanListView(APIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
user = request.user
|
||||
yonghu_id = user.yonghuid
|
||||
yonghu_id = user.UserUID
|
||||
|
||||
leixing_id = request.data.get('shangpinTypeId')
|
||||
if not leixing_id:
|
||||
@@ -1463,7 +1463,7 @@ class ShangjiaTianjiaMobanView(APIView):
|
||||
try:
|
||||
# 1. 获取当前商家用户ID
|
||||
user = request.user
|
||||
yonghu_id = user.yonghuid
|
||||
yonghu_id = user.UserUID
|
||||
|
||||
# 2. 接收并清洗参数,避免类型错误
|
||||
leixing_id = request.data.get('shangpinTypeId')
|
||||
@@ -1590,7 +1590,7 @@ class ShangjiaShanchuMobanView(APIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
user = request.user
|
||||
yonghu_id = user.yonghuid
|
||||
yonghu_id = user.UserUID
|
||||
|
||||
moban_id = request.data.get('mobanId')
|
||||
leixing_id = request.data.get('shangpinTypeId')
|
||||
@@ -1627,7 +1627,7 @@ class ShangjiaGengxinMobanView(APIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
user = request.user
|
||||
yonghu_id = user.yonghuid
|
||||
yonghu_id = user.UserUID
|
||||
|
||||
moban_id = request.data.get('mobanId')
|
||||
leixing_id = request.data.get('shangpinTypeId')
|
||||
@@ -1764,7 +1764,7 @@ class ShangjiaGenerateLinkView(APIView):
|
||||
|
||||
# 商家信息
|
||||
try:
|
||||
shangjia = user.shop_profile
|
||||
shangjia = user.ShopProfile
|
||||
except UserShangjia.DoesNotExist:
|
||||
return Response({'code': 403, 'msg': '商家信息未完善', 'data': {}}, status=403)
|
||||
if shangjia.zhuangtai != 1:
|
||||
@@ -1778,7 +1778,7 @@ class ShangjiaGenerateLinkView(APIView):
|
||||
|
||||
# 查询模板
|
||||
try:
|
||||
moban = ShangjiaMoban.query.get(id=moban_id, yonghu_id=user.yonghuid, leixing_id=shangpin_type_id)
|
||||
moban = ShangjiaMoban.query.get(id=moban_id, yonghu_id=user.UserUID, leixing_id=shangpin_type_id)
|
||||
except ShangjiaMoban.DoesNotExist:
|
||||
return Response({'code': 400, 'msg': '模板不存在', 'data': {}}, status=400)
|
||||
|
||||
@@ -1835,7 +1835,7 @@ class ShangjiaGenerateLinkView(APIView):
|
||||
|
||||
with transaction.atomic():
|
||||
dingdan_id = generate_dingdan_id()
|
||||
secure_token = generate_secure_token(dingdan_id, user.yonghuid)
|
||||
secure_token = generate_secure_token(dingdan_id, user.UserUID)
|
||||
|
||||
# 创建订单主表
|
||||
dingdan = Order.query.create(
|
||||
@@ -1849,15 +1849,15 @@ class ShangjiaGenerateLinkView(APIView):
|
||||
huiyuan_id=final_huiyuan_id,
|
||||
yongjin=final_yongjin,
|
||||
Description=moban.moban_jieshao[:2000],
|
||||
user1_id=f"Sj{user.yonghuid}",
|
||||
ImageURL=user.avatar or '',
|
||||
user1_id=f"Sj{user.UserUID}",
|
||||
ImageURL=user.Avatar or '',
|
||||
)
|
||||
|
||||
# 商家扩展表
|
||||
MerchantOrderExt.query.create(
|
||||
Order=dingdan,
|
||||
MerchantID=user.yonghuid,
|
||||
MerchantNickname=shangjia.nicheng or f"商家{user.yonghuid}",
|
||||
MerchantID=user.UserUID,
|
||||
MerchantNickname=shangjia.nicheng or f"商家{user.UserUID}",
|
||||
)
|
||||
|
||||
# 关联标签
|
||||
@@ -1881,7 +1881,7 @@ class ShangjiaGenerateLinkView(APIView):
|
||||
# 生成链接并保存
|
||||
link_url = generate_link_url(secure_token)
|
||||
lianjie_obj = ShangjiaLianjie.query.create(
|
||||
yonghu_id=user.yonghuid,
|
||||
yonghu_id=user.UserUID,
|
||||
leixing_id=shangpin_type_id,
|
||||
moban_id=moban_id,
|
||||
lianjie=link_url,
|
||||
@@ -1926,7 +1926,7 @@ class ShangjiaLianjieListView(APIView):
|
||||
def post(self, request):
|
||||
try:
|
||||
user = request.user
|
||||
yonghu_id = user.yonghuid
|
||||
yonghu_id = user.UserUID
|
||||
|
||||
moban_id = request.data.get('mobanId')
|
||||
used = int(request.data.get('used', 0)) # 0未使用,1已使用
|
||||
@@ -2192,7 +2192,7 @@ class KehuGetDingdanLianjieView(APIView):
|
||||
shangjia_nicheng = ''
|
||||
try:
|
||||
user_main = User.query.get(UserUID=lianjie_obj.yonghu_id)
|
||||
shangjia_obj = user_main.shop_profile
|
||||
shangjia_obj = user_main.ShopProfile
|
||||
shangjia_nicheng = shangjia_obj.nicheng
|
||||
except (User.DoesNotExist, UserShangjia.DoesNotExist):
|
||||
logger.warning(f"商家信息不存在 - 用户ID: {lianjie_obj.yonghu_id}")
|
||||
@@ -2478,7 +2478,7 @@ class KehuTianxieDingdanView(APIView):
|
||||
|
||||
# 通过反向关系获取打手扩展信息
|
||||
try:
|
||||
dashou_profile = dashou_user.dashou_profile
|
||||
dashou_profile = dashou_user.DashouProfile
|
||||
|
||||
# 检查打手状态(zhuangtai)
|
||||
if dashou_profile.zhuangtai != 1:
|
||||
@@ -2572,7 +2572,7 @@ class KehuTianxieDingdanView(APIView):
|
||||
# 获取商家信息用于返回
|
||||
try:
|
||||
user_main = User.query.get(UserUID=lianjie_obj.yonghu_id)
|
||||
shangjia_obj = user_main.shop_profile
|
||||
shangjia_obj = user_main.ShopProfile
|
||||
shangjia_mingcheng = shangjia_obj.nicheng
|
||||
except:
|
||||
shangjia_mingcheng = f"商家{lianjie_obj.yonghu_id}"
|
||||
@@ -2753,21 +2753,21 @@ class GuanshiQRCodeView(APIView):
|
||||
def post(self, request):
|
||||
logger.info("===== 开始生成管事二维码 =====")
|
||||
current_user = request.user
|
||||
logger.info(f"当前用户ID: {current_user.yonghuid}")
|
||||
logger.info(f"当前用户ID: {current_user.UserUID}")
|
||||
|
||||
try:
|
||||
try:
|
||||
guanshi = current_user.guanshi_profile
|
||||
guanshi = current_user.GuanshiProfile
|
||||
logger.info(f"管事扩展表查询成功,状态: {guanshi.zhuangtai}")
|
||||
except UserGuanshi.DoesNotExist:
|
||||
logger.warning(f"用户 {current_user.yonghuid} 不是管事身份")
|
||||
logger.warning(f"用户 {current_user.UserUID} 不是管事身份")
|
||||
return Response(
|
||||
{'code': 403, 'message': '当前用户不是管事身份', 'data': None},
|
||||
status=status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
|
||||
if guanshi.zhuangtai != 1:
|
||||
logger.warning(f"用户 {current_user.yonghuid} 管事状态异常: {guanshi.zhuangtai}")
|
||||
logger.warning(f"用户 {current_user.UserUID} 管事状态异常: {guanshi.zhuangtai}")
|
||||
return Response(
|
||||
{'code': 403, 'message': '管事账号状态异常', 'data': None},
|
||||
status=status.HTTP_403_FORBIDDEN
|
||||
@@ -2775,10 +2775,10 @@ class GuanshiQRCodeView(APIView):
|
||||
|
||||
invite_code = guanshi.yaoqingma
|
||||
if not invite_code:
|
||||
logger.info(f"用户 {current_user.yonghuid} 无邀请码,开始生成")
|
||||
invite_code = CreateInvitationCode(str(current_user.yonghuid))
|
||||
logger.info(f"用户 {current_user.UserUID} 无邀请码,开始生成")
|
||||
invite_code = CreateInvitationCode(str(current_user.UserUID))
|
||||
if not VerifyInvitationCode(invite_code):
|
||||
logger.error(f"邀请码唯一性校验失败,用户: {current_user.yonghuid}")
|
||||
logger.error(f"邀请码唯一性校验失败,用户: {current_user.UserUID}")
|
||||
return Response(
|
||||
{'code': 500, 'message': '邀请码生成失败', 'data': None},
|
||||
status=status.HTTP_500_INTERNAL_SERVER_ERROR
|
||||
@@ -2854,7 +2854,7 @@ class GuanshiQRCodeView(APIView):
|
||||
)
|
||||
|
||||
timestamp = int(time.time())
|
||||
filename = f"{current_user.yonghuid}_{timestamp}.png"
|
||||
filename = f"{current_user.UserUID}_{timestamp}.png"
|
||||
oss_path = f"erweima/guanshi/{filename}"
|
||||
file_obj = io.BytesIO(wx_resp.content)
|
||||
logger.info(f"开始上传图片到COS: {oss_path}")
|
||||
@@ -2971,7 +2971,7 @@ class ZuzhangHaibaoView(APIView):
|
||||
|
||||
# 1. 验证组长身份
|
||||
try:
|
||||
zuzhang = current_user.zuzhang_profile
|
||||
zuzhang = current_user.ZuzhangProfile
|
||||
except UserZuzhang.DoesNotExist:
|
||||
return Response({
|
||||
'code': 403,
|
||||
@@ -2990,9 +2990,9 @@ class ZuzhangHaibaoView(APIView):
|
||||
# 3. 获取或生成邀请码
|
||||
invite_code = zuzhang.yaoqingma
|
||||
if not invite_code:
|
||||
invite_code = CreateInvitationCode(str(current_user.yonghuid))
|
||||
invite_code = CreateInvitationCode(str(current_user.UserUID))
|
||||
if not VerifyInvitationCode(invite_code):
|
||||
logger.error(f"组长邀请码生成失败,用户: {current_user.yonghuid}")
|
||||
logger.error(f"组长邀请码生成失败,用户: {current_user.UserUID}")
|
||||
return Response({
|
||||
'code': 500,
|
||||
'message': '邀请码生成失败',
|
||||
@@ -3066,7 +3066,7 @@ class ZuzhangHaibaoView(APIView):
|
||||
|
||||
# 5. 上传到腾讯云 COS
|
||||
timestamp = int(time.time())
|
||||
filename = f"{current_user.yonghuid}_{timestamp}.png"
|
||||
filename = f"{current_user.UserUID}_{timestamp}.png"
|
||||
oss_path = f"erweima/zuzhang/{filename}"
|
||||
file_obj = io.BytesIO(wx_resp.content)
|
||||
|
||||
@@ -3247,7 +3247,7 @@ class CheckPhoneAuthView(APIView):
|
||||
user = request.user # User 实例
|
||||
|
||||
# 已经认证过手机号,直接放行
|
||||
if user.shoujihao_renzheng:
|
||||
if user.PhoneVerified:
|
||||
return Response({'need_auth': False})
|
||||
|
||||
# 检查各角色是否满足阈值条件
|
||||
@@ -3277,7 +3277,7 @@ class CheckPhoneAuthView(APIView):
|
||||
except UserDashou.DoesNotExist:
|
||||
return False
|
||||
# 检查是否有任意会员购买记录
|
||||
return Huiyuangoumai.query.filter(yonghu_id=user.yonghuid).exists()
|
||||
return Huiyuangoumai.query.filter(yonghu_id=user.UserUID).exists()
|
||||
|
||||
def _shangjia_meets_threshold(self, user):
|
||||
"""商家条件:发布订单总数 fabu >= 5"""
|
||||
|
||||
Reference in New Issue
Block a user