修复了堆栈不可见错误,以及 ORM 错误查询
This commit is contained in:
@@ -3418,7 +3418,7 @@ class CfGuanLi(APIView):
|
||||
offset = (page - 1) * page_size
|
||||
|
||||
# 13. 分页查询
|
||||
chufa_list = list(queryset.order_by('-create_time')[offset:offset + page_size])
|
||||
chufa_list = list(queryset.order_by('-CreateTime')[offset:offset + page_size])
|
||||
|
||||
# 🔴【新增】高效获取图片信息
|
||||
if chufa_list:
|
||||
@@ -3625,7 +3625,7 @@ class AdTongYiChuFa(APIView):
|
||||
chufajilu = PenaltyRecord.query.filter(
|
||||
OrderID=dingdan_id,
|
||||
ApplyStatus__in=[0, 3] # 🔴【修改】包括待处理和申诉中状态
|
||||
).order_by('-create_time').first() # 取最新的一条
|
||||
).order_by('-CreateTime').first() # 取最新的一条
|
||||
|
||||
if not chufajilu:
|
||||
# 如果没有待处理的处罚记录,检查是否有已处理的
|
||||
@@ -6116,7 +6116,7 @@ class ChufaJiluHuoquView(APIView):
|
||||
pass
|
||||
|
||||
# 按创建时间倒序排列(最新在前)
|
||||
queryset = queryset.order_by('-create_time')
|
||||
queryset = queryset.order_by('-CreateTime')
|
||||
|
||||
# 使用游标分页,避免传统分页的性能问题
|
||||
paginator = Paginator(queryset, page_size)
|
||||
@@ -6547,7 +6547,7 @@ class ShangjiaChufaJiluHuoquView(APIView):
|
||||
pass
|
||||
|
||||
# 按创建时间倒序排列
|
||||
queryset = queryset.order_by('-create_time')
|
||||
queryset = queryset.order_by('-CreateTime')
|
||||
|
||||
# 分页逻辑
|
||||
paginator = Paginator(queryset, page_size)
|
||||
@@ -7175,23 +7175,23 @@ class KefuGetShangjiaOrderListView(APIView):
|
||||
|
||||
# ---------- 查询条件 ----------
|
||||
# 基础条件:商家发单 + 非跨平台
|
||||
base_q = Q(fadan_pingtai=2)
|
||||
base_q = Q(Platform=2)
|
||||
|
||||
if dingdan_id:
|
||||
q_conditions = base_q & Q(dingdan_id=dingdan_id)
|
||||
q_conditions = base_q & Q(OrderID=dingdan_id)
|
||||
else:
|
||||
q_conditions = base_q
|
||||
if leixing is not None:
|
||||
try:
|
||||
leixing_int = int(leixing)
|
||||
q_conditions &= Q(leixing_id=leixing_int)
|
||||
q_conditions &= Q(ProductTypeID=leixing_int)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
if zhuangtai and zhuangtai != 'all':
|
||||
try:
|
||||
status_list = [int(s.strip()) for s in zhuangtai.split(',') if s.strip()]
|
||||
if status_list:
|
||||
q_conditions &= Q(zhuangtai__in=status_list)
|
||||
q_conditions &= Q(Status__in=status_list)
|
||||
except (ValueError, TypeError):
|
||||
pass
|
||||
if dashou_id:
|
||||
@@ -8941,26 +8941,26 @@ class KefuPunishmentListView(APIView):
|
||||
# 3. 获取统计信息(不分页)
|
||||
stats = {
|
||||
'zongshu': PenaltyRecord.query.count(),
|
||||
'daichuli': PenaltyRecord.query.filter(sqzhuangtai__in=[0, 3]).count(),
|
||||
'yichuli': PenaltyRecord.query.filter(sqzhuangtai__in=[1, 2]).count(),
|
||||
'daichuli': PenaltyRecord.query.filter(ApplyStatus__in=[0, 3]).count(),
|
||||
'yichuli': PenaltyRecord.query.filter(ApplyStatus__in=[1, 2]).count(),
|
||||
}
|
||||
|
||||
# 4. 构建查询条件
|
||||
queryset = PenaltyRecord.query.all()
|
||||
|
||||
if status_list and isinstance(status_list, list):
|
||||
queryset = queryset.filter(sqzhuangtai__in=status_list)
|
||||
queryset = queryset.filter(ApplyStatus__in=status_list)
|
||||
|
||||
if dingdan_id:
|
||||
queryset = queryset.filter(dingdan_id=dingdan_id)
|
||||
queryset = queryset.filter(OrderID=dingdan_id)
|
||||
|
||||
if dashouid:
|
||||
queryset = queryset.filter(dashouid=dashouid)
|
||||
queryset = queryset.filter(PlayerID=dashouid)
|
||||
|
||||
# 5. 分页
|
||||
total = queryset.count()
|
||||
offset = (page - 1) * page_size
|
||||
records = queryset.order_by('-create_time')[offset:offset + page_size]
|
||||
records = queryset.order_by('-CreateTime')[offset:offset + page_size]
|
||||
|
||||
# 6. 构建返回列表
|
||||
list_data = []
|
||||
@@ -8995,61 +8995,41 @@ class KefuGetOrderDetailView(APIView):
|
||||
parser_classes = [JSONParser]
|
||||
|
||||
def post(self, request):
|
||||
# 强制打印到控制台并立即刷新
|
||||
def p(msg):
|
||||
#print(f"[订单详情] {msg}")
|
||||
sys.stdout.flush()
|
||||
|
||||
#p("========== 视图开始执行 ==========")
|
||||
|
||||
# 1. 打印原始请求数据
|
||||
#p(f"request.data: {request.data}")
|
||||
|
||||
phone = request.data.get('phone', '').strip()
|
||||
dingdan_id = request.data.get('dingdan_id', '').strip()
|
||||
#p(f"phone={phone}, dingdan_id={dingdan_id}")
|
||||
|
||||
if not phone or not dingdan_id:
|
||||
#p("参数不完整,返回401")
|
||||
return Response({'code': 401, 'msg': '认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# 2. 获取当前用户
|
||||
current_user = request.user
|
||||
|
||||
|
||||
# 验证手机号
|
||||
if getattr(current_user, 'phone', '') != phone:
|
||||
#p("手机号不匹配")
|
||||
return Response({'code': 401, 'msg': '认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# 验证用户类型
|
||||
if current_user.user_type != 'kefu':
|
||||
#p("用户类型不是客服")
|
||||
return Response({'code': 401, 'msg': '认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
# 客服扩展表
|
||||
try:
|
||||
kefu = current_user.kefu_profile
|
||||
#p(f"kefu_profile: {kefu}")
|
||||
if kefu.zhuangtai != 1:
|
||||
#p(f"客服状态异常: {kefu.zhuangtai}")
|
||||
return Response({'code': 401, 'msg': '认证失败'}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
except Exception as e:
|
||||
#p(f"获取客服扩展表异常: {e}")
|
||||
logger.exception(f"[kefuhqddxq] 获取客服扩展表异常 user={getattr(current_user, 'yonghuid', '?')}")
|
||||
return Response({'code': 500, 'msg': '服务器错误'}, status=500)
|
||||
|
||||
# 3. 查询订单
|
||||
try:
|
||||
#p(f"开始查询订单: {dingdan_id}")
|
||||
dingdan_obj = Order.query.select_related(
|
||||
'pingtai_kuozhan', 'shangjia_kuozhan'
|
||||
).get(dingdan_id=dingdan_id)
|
||||
#p("订单查询成功")
|
||||
).get(OrderID=dingdan_id)
|
||||
except Order.DoesNotExist:
|
||||
#p("订单不存在")
|
||||
return Response({'code': 404, 'msg': '订单不存在'}, status=404)
|
||||
except Exception as e:
|
||||
#p(f"订单查询异常: {traceback.format_exc()}")
|
||||
logger.exception(f"[kefuhqddxq] 订单查询异常 dingdan_id={dingdan_id}")
|
||||
return Response({'code': 500, 'msg': '服务器错误'}, status=500)
|
||||
|
||||
# 4. 构建基础数据
|
||||
@@ -9074,9 +9054,8 @@ class KefuGetOrderDetailView(APIView):
|
||||
'chuangjianshijian': dingdan_obj.CreateTime.strftime('%Y-%m-%d %H:%M:%S') if dingdan_obj.CreateTime else '',
|
||||
'genggaishijian': dingdan_obj.UpdateTime.strftime('%Y-%m-%d %H:%M:%S') if dingdan_obj.UpdateTime else '',
|
||||
}
|
||||
#p("基础数据构建完成")
|
||||
except Exception as e:
|
||||
#p(f"构建基础数据异常: {traceback.format_exc()}")
|
||||
logger.exception(f"[kefuhqddxq] 构建基础数据异常 dingdan_id={dingdan_id}")
|
||||
return Response({'code': 500, 'msg': '服务器错误'}, status=500)
|
||||
|
||||
# 5. 扩展表数据
|
||||
@@ -9107,30 +9086,26 @@ class KefuGetOrderDetailView(APIView):
|
||||
'shangjia_id': '', 'sjnicheng': '', 'shangjia_pingjia': '',
|
||||
'cfliyou': '', 'sqzhuangtai': 0, 'bhliyou': ''
|
||||
}
|
||||
#p("扩展数据构建成功")
|
||||
except Exception as e:
|
||||
#p(f"扩展数据异常: {traceback.format_exc()}")
|
||||
logger.exception(f"[kefuhqddxq] 扩展数据异常 dingdan_id={dingdan_id}")
|
||||
return Response({'code': 500, 'msg': '服务器错误'}, status=500)
|
||||
|
||||
# 6. 打手图片
|
||||
try:
|
||||
dashou_images = PlayerDeliveryImage.query.filter(OrderID=dingdan_id).values_list('ImageURL', flat=True)
|
||||
response_data['dashou_images'] = [img for img in dashou_images if img]
|
||||
#p(f"打手图片数量: {len(response_data['dashou_images'])}")
|
||||
except Exception as e:
|
||||
#p(f"打手图片异常: {traceback.format_exc()}")
|
||||
logger.exception(f"[kefuhqddxq] 打手图片查询异常 dingdan_id={dingdan_id}")
|
||||
response_data['dashou_images'] = []
|
||||
|
||||
# 7. 退款理由
|
||||
try:
|
||||
tuikuan_record = RefundRecord.query.filter(OrderID=dingdan_id).order_by('-create_time').first()
|
||||
tuikuan_record = RefundRecord.query.filter(OrderID=dingdan_id).order_by('-CreateTime').first()
|
||||
response_data['tuikuan_liyou'] = tuikuan_record.Reason if tuikuan_record and tuikuan_record.Reason else ''
|
||||
#p("退款理由查询完成")
|
||||
except Exception as e:
|
||||
#p(f"退款理由异常: {traceback.format_exc()}")
|
||||
logger.exception(f"[kefuhqddxq] 退款理由查询异常 dingdan_id={dingdan_id}")
|
||||
response_data['tuikuan_liyou'] = ''
|
||||
|
||||
#p("视图正常结束,返回成功")
|
||||
return Response({'code': 0, 'data': response_data})
|
||||
|
||||
|
||||
@@ -9191,7 +9166,7 @@ class KefuPunishmentDetailView(APIView):
|
||||
|
||||
# 查询处罚记录(按创建时间倒序取最新一条)
|
||||
try:
|
||||
record = PenaltyRecord.query.filter(OrderID=dingdan_id).order_by('-create_time').first()
|
||||
record = PenaltyRecord.query.filter(OrderID=dingdan_id).order_by('-CreateTime').first()
|
||||
if not record:
|
||||
return Response({'code': 404, 'msg': '处罚记录不存在'}, status=status.HTTP_404_NOT_FOUND)
|
||||
except Exception as e:
|
||||
@@ -9280,7 +9255,7 @@ class KefuPunishmentActionView(APIView):
|
||||
record = PenaltyRecord.query.filter(
|
||||
OrderID=dingdan_id,
|
||||
ApplyStatus__in=[0, 3]
|
||||
).order_by('-create_time').first()
|
||||
).order_by('-CreateTime').first()
|
||||
if not record:
|
||||
exists = PenaltyRecord.query.filter(OrderID=dingdan_id).exists()
|
||||
if exists:
|
||||
@@ -11265,8 +11240,8 @@ class DashouJianquanView(APIView):
|
||||
# ========== 5. 条件三:存在订单状态为 2 或 8 的订单 ==========
|
||||
# 利用 jiedan_dashou_id + zhuangtai 复合索引,只查 1 条
|
||||
has_valid_order = Order.query.filter(
|
||||
jiedan_dashou_id=user.yonghuid,
|
||||
zhuangtai__in=[2, 8]
|
||||
PlayerID=user.yonghuid,
|
||||
Status__in=[2, 8]
|
||||
).only('id').exists() # exists() 高性能判断,只发 SELECT 1 LIMIT 1
|
||||
|
||||
if has_valid_order:
|
||||
@@ -11447,7 +11422,7 @@ class DaShouFaKuanLieBiaoView(APIView):
|
||||
qs = qs.filter(RelatedOrderID__icontains=sousuo_dingdan_id)
|
||||
|
||||
# 按创建时间倒序
|
||||
qs = qs.order_by('-create_time')
|
||||
qs = qs.order_by('-CreateTime')
|
||||
|
||||
# 分页
|
||||
paginator = Paginator(qs, page_size)
|
||||
|
||||
Reference in New Issue
Block a user