This commit is contained in:
@@ -268,8 +268,8 @@ def pay(request):
|
||||
product = None
|
||||
if order_type == 'course':
|
||||
try:
|
||||
product = VBCourse.objects.get(id=good_id)
|
||||
except VBCourse.DoesNotExist:
|
||||
product = VCCourse.objects.get(id=good_id)
|
||||
except VCCourse.DoesNotExist:
|
||||
print(f"课程不存在: {good_id}")
|
||||
return Response({'error': f'找不到 ID 为 {good_id} 的课程'}, status=status.HTTP_404_NOT_FOUND)
|
||||
else:
|
||||
@@ -355,7 +355,8 @@ def pay(request):
|
||||
print(f"微信支付 V3 Native 下单成功!")
|
||||
print(f"订单 ID: {order.id}")
|
||||
print(f"商户订单号: {out_trade_no}")
|
||||
print(f"商品: {product.name} x {quantity}")
|
||||
product_name = getattr(product, 'name', getattr(product, 'title', 'Unknown Product'))
|
||||
print(f"商品: {product_name} x {quantity}")
|
||||
print(f"总额: {total_price} 元")
|
||||
print(f"code_url: {code_url}")
|
||||
print(f"========================================")
|
||||
@@ -596,6 +597,16 @@ class OrderViewSet(viewsets.ModelViewSet):
|
||||
return queryset.filter(wechat_user=user).order_by('-created_at')
|
||||
return queryset.order_by('-created_at')
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
print(f"Creating order with data: {request.data}")
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
if not serializer.is_valid():
|
||||
print(f"Order validation failed: {serializer.errors}")
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
self.perform_create(serializer)
|
||||
headers = self.get_success_headers(serializer.data)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
||||
|
||||
def perform_create(self, serializer):
|
||||
"""
|
||||
创建订单时自动关联当前微信用户
|
||||
|
||||
Reference in New Issue
Block a user