diff --git a/backend/shop/__pycache__/views.cpython-312.pyc b/backend/shop/__pycache__/views.cpython-312.pyc index c0de843..995e413 100644 Binary files a/backend/shop/__pycache__/views.cpython-312.pyc and b/backend/shop/__pycache__/views.cpython-312.pyc differ diff --git a/backend/shop/views.py b/backend/shop/views.py index 2c9886a..26f830f 100644 --- a/backend/shop/views.py +++ b/backend/shop/views.py @@ -269,6 +269,9 @@ def pay(request): from .models import Salesperson salesperson = Salesperson.objects.filter(code=ref_code).first() + # 尝试获取当前登录用户 (如果请求头带有 Authorization) + wechat_user = get_current_wechat_user(request) + total_price = product.price * quantity amount_in_cents = int(total_price * 100) @@ -279,6 +282,7 @@ def pay(request): 'phone_number': phone_number, 'shipping_address': shipping_address, 'salesperson': salesperson, + 'wechat_user': wechat_user, 'status': 'pending' } @@ -860,8 +864,12 @@ class OrderViewSet(viewsets.ModelViewSet): """ 主动向微信查询订单支付状态 URL: /api/orders/{id}/query_status/ + 注意:绕过 get_queryset 的过滤,以便未登录或未绑定用户的订单也能查询 """ - order = self.get_object() + try: + order = Order.objects.get(pk=pk) + except Order.DoesNotExist: + return Response({'error': '订单不存在'}, status=status.HTTP_404_NOT_FOUND) # 如果已经支付了,直接返回 if order.status == 'paid':