修复了已知的生产环境问题

This commit is contained in:
2026-06-17 21:25:45 +08:00
parent d00f0d08e5
commit 4aca437d2b
25 changed files with 13547 additions and 13423 deletions

View File

@@ -581,7 +581,7 @@ class AddAdminUserView(APIView):
# 生成唯一的 yonghuid7位数字
while True:
yonghuid = str(random.randint(1000000, 9999999))
if not User.query.filter(yonghuid=yonghuid).exists():
if not User.query.filter(UserUID=yonghuid).exists():
break
# 生成唯一的 openid格式admin_{时间戳}_{随机6位}
@@ -1064,7 +1064,7 @@ class KefuUpdateDashouView(APIView):
# 3. 查询打手
try:
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(UserUID=dashou_id)
dashou_profile = dashou_user.dashou_profile
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手不存在'})
@@ -1496,7 +1496,7 @@ class KefuGetShangjiaDetailView(APIView):
# 查询商家
try:
shangjia = UserShangjia.query.select_related('user').get(user__yonghuid=yonghuid)
shangjia = UserShangjia.query.select_related('user').get(user__UserUID=yonghuid)
except UserShangjia.DoesNotExist:
return Response({'code': 404, 'msg': '商家不存在'})
@@ -1566,7 +1566,7 @@ class KefuUpdateShangjiaView(APIView):
# 使用事务select_for_update 必须在事务内
with transaction.atomic():
try:
shangjia = UserShangjia.objects.select_for_update().get(user__yonghuid=yonghuid)
shangjia = UserShangjia.objects.select_for_update().get(user__UserUID=yonghuid)
except UserShangjia.DoesNotExist:
return Response({'code': 404, 'msg': '商家不存在'})
@@ -2968,7 +2968,7 @@ class GetGuanliDetailView(APIView):
# 查询用户主表和管事扩展表
try:
user = User.query.select_related('guanshi_profile', 'boss_profile').get(yonghuid=yonghuid)
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
except User.DoesNotExist:
@@ -3015,7 +3015,7 @@ class GetGuanliDetailView(APIView):
# 获取多次分红配置(按次数和会员组织)
# 查询该管事的所有多次分红记录
duoci_records = DuociFenhong.query.filter(yonghuid=yonghuid).order_by('cishu')
duoci_records = DuociFenhong.query.filter(UserUID=yonghuid).order_by('cishu')
custom_first = {} # 首次分红定制cishu=1
extra_map = {} # 其他次数 { cishu: { huiyuan_id: { guanshi_fenhong, jieshao, jiage } } }
@@ -3089,7 +3089,7 @@ class UpdateGuanliView(APIView):
# 查询管事对象(不在事务外加锁,事务内加锁)
try:
user = User.query.get(yonghuid=yonghuid)
user = User.query.get(UserUID=yonghuid)
guanshi = user.guanshi_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except User.DoesNotExist:
@@ -3100,7 +3100,7 @@ class UpdateGuanliView(APIView):
# 开始事务,内部使用 select_for_update
with transaction.atomic():
# 重新获取加锁对象
user = User.objects.select_for_update().get(yonghuid=yonghuid)
user = User.objects.select_for_update().get(UserUID=yonghuid)
guanshi = user.guanshi_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
@@ -3196,7 +3196,7 @@ class UpdateGuanliView(APIView):
# 4.2 首次定制分红cishu=1
if custom_first is not None and isinstance(custom_first, dict):
# 获取当前所有首次定制记录
existing_first = DuociFenhong.query.filter(yonghuid=yonghuid, cishu=1)
existing_first = DuociFenhong.query.filter(UserUID=yonghuid, cishu=1)
# 前端传来的定制字典 {会员ID: 金额}
for huiyuan_id, amount in custom_first.items():
try:
@@ -3205,7 +3205,7 @@ class UpdateGuanliView(APIView):
continue
if amount <= 0:
# 金额为0或负数表示删除定制
DuociFenhong.query.filter(yonghuid=yonghuid, huiyuan=huiyuan_id, cishu=1).delete()
DuociFenhong.query.filter(UserUID=yonghuid, huiyuan=huiyuan_id, cishu=1).delete()
else:
DuociFenhong.query.update_or_create(
yonghuid=yonghuid,
@@ -3256,7 +3256,7 @@ class UpdateGuanliView(APIView):
}
)
# 删除不在 keep_set 中的额外次数记录
existing_extra = DuociFenhong.query.filter(yonghuid=yonghuid, cishu__gte=2)
existing_extra = DuociFenhong.query.filter(UserUID=yonghuid, cishu__gte=2)
for record in existing_extra:
if (record.cishu, record.huiyuan) not in keep_set:
record.delete()
@@ -3660,7 +3660,7 @@ class GetZuzhangDetailView(APIView):
# 查询组长主表、扩展表、老板扩展表(昵称)
try:
user = User.query.select_related('zuzhang_profile', 'boss_profile').get(yonghuid=yonghuid)
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
except User.DoesNotExist:
@@ -3706,7 +3706,7 @@ class GetZuzhangDetailView(APIView):
m['zuzhangfc'] = str(m['zuzhangfc'])
# 获取多次分红配置(按次数和会员组织)
duoci_records = DuociFenhong.query.filter(yonghuid=yonghuid).order_by('cishu')
duoci_records = DuociFenhong.query.filter(UserUID=yonghuid).order_by('cishu')
custom_first = {} # 首次分红定制cishu=1
extra_map = {} # 其他次数 { cishu: { huiyuan_id: { zuzhang_fenhong, jieshao, jiage } } }
@@ -3783,7 +3783,7 @@ class UpdateZuzhangView(APIView):
# 查询组长对象
try:
user = User.query.get(yonghuid=yonghuid)
user = User.query.get(UserUID=yonghuid)
zuzhang = user.zuzhang_profile
boss = user.boss_profile if hasattr(user, 'boss_profile') else None
except User.DoesNotExist:
@@ -3879,7 +3879,7 @@ class UpdateZuzhangView(APIView):
# 4.2 首次定制分红cishu=1
if custom_first is not None and isinstance(custom_first, dict):
existing_first = DuociFenhong.query.filter(yonghuid=yonghuid, cishu=1)
existing_first = DuociFenhong.query.filter(UserUID=yonghuid, cishu=1)
for huiyuan_id, amount in custom_first.items():
try:
amount = Decimal(str(amount))
@@ -3887,7 +3887,7 @@ class UpdateZuzhangView(APIView):
continue
if amount <= 0:
# 删除定制(恢复默认)
DuociFenhong.query.filter(yonghuid=yonghuid, huiyuan=huiyuan_id, cishu=1).delete()
DuociFenhong.query.filter(UserUID=yonghuid, huiyuan=huiyuan_id, cishu=1).delete()
else:
DuociFenhong.query.update_or_create(
yonghuid=yonghuid,
@@ -3936,7 +3936,7 @@ class UpdateZuzhangView(APIView):
}
)
# 删除不在 keep_set 中的额外次数记录
existing_extra = DuociFenhong.query.filter(yonghuid=yonghuid, cishu__gte=2)
existing_extra = DuociFenhong.query.filter(UserUID=yonghuid, cishu__gte=2)
for record in existing_extra:
if (record.cishu, record.huiyuan) not in keep_set:
record.delete()
@@ -5026,7 +5026,7 @@ class ShopModifyView(APIView):
return Response({'code': 400, 'msg': '必填字段缺失用户ID、账号、密码、店铺名称'})
# 检查用户是否存在
if not User.query.filter(yonghuid=yonghu_id).exists():
if not User.query.filter(UserUID=yonghu_id).exists():
return Response({'code': 404, 'msg': '用户不存在'})
# 检查凭证是否已存在
@@ -5962,7 +5962,7 @@ class FaKuanChuangJianView(APIView):
# 验证用户是否存在对应的扩展表
try:
user = User.query.get(yonghuid=beichufa_id)
user = User.query.get(UserUID=beichufa_id)
profile_attr = SHENFEN_PROFILE_MAP.get(shenfen)
if not profile_attr or not hasattr(user, profile_attr):
return Response({'code': 400, 'msg': '该用户不是所选身份'})
@@ -6162,7 +6162,7 @@ class PunishDashouView(APIView):
# 查询打手
try:
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(UserUID=dashou_id)
dashou = dashou_user.dashou_profile
except User.DoesNotExist:
return Response({'code': 404, 'msg': '打手用户不存在'})
@@ -6484,7 +6484,7 @@ class CaiwuView(APIView):
amount_sum = Czjilu.query.filter(
create_time__gte=today_start,
create_time__lt=today_end,
yonghuid__in=new_huiyuan_user_ids,
UserUID__in=new_huiyuan_user_ids,
leixing=1,
zhuangtai=3
).aggregate(total=Sum('jine'))
@@ -7946,7 +7946,7 @@ class KhgglView(APIView):
queryset = UserShenheguan.query.select_related('user__dashou_profile')
if filter_yonghuid:
queryset = queryset.filter(user__yonghuid=filter_yonghuid)
queryset = queryset.filter(user__UserUID=filter_yonghuid)
if filter_zhuangtai is not None:
queryset = queryset.filter(zhuangtai=filter_zhuangtai)
if filter_shenhe_zhuangtai is not None:
@@ -7960,7 +7960,7 @@ class KhgglView(APIView):
shenheguan_ids = KaoheguanBankuai.query.filter(
bankuai_id__in=bankuai_ids
).values_list('kaoheguan_id', flat=True)
queryset = queryset.filter(user__yonghuid__in=shenheguan_ids)
queryset = queryset.filter(user__UserUID__in=shenheguan_ids)
total = queryset.count()
start = (page - 1) * page_size
@@ -8070,7 +8070,7 @@ class ShgxgsjView(APIView):
return Response({'code': 1, 'msg': '缺少用户ID'}, status=400)
try:
shenheguan = UserShenheguan.query.select_related('user').get(user__yonghuid=yonghuid)
shenheguan = UserShenheguan.query.select_related('user').get(user__UserUID=yonghuid)
except UserShenheguan.DoesNotExist:
return Response({'code': 1, 'msg': '审核官不存在'}, status=404)
@@ -8189,7 +8189,7 @@ class ZxkfghdsView(APIView):
shangjia_ext = old_order.shangjia_kuozhan
shangjia_id = shangjia_ext.shangjia_id
# 获取商家昵称用于新订单扩展表
shangjia_user = User.query.get(yonghuid=shangjia_id)
shangjia_user = User.query.get(UserUID=shangjia_id)
shangjia_nicheng = shangjia_user.shop_profile.nicheng or f"商家{shangjia_id}"
except (ObjectDoesNotExist, UserShangjia.DoesNotExist):
logger.error(f"商家信息缺失,订单: {dingdan_id}")
@@ -8206,7 +8206,7 @@ class ZxkfghdsView(APIView):
dashou_id = old_order.jiedan_dashou_id
if dashou_id:
try:
dashou_user = User.query.get(yonghuid=dashou_id)
dashou_user = User.query.get(UserUID=dashou_id)
dashou_profile = dashou_user.dashou_profile
dashou_profile.tuikuanliang += 1 # 退款次数+1
dashou_profile.zhuangtai = 1 # 设为空闲