|
@@ -32,16 +32,17 @@ class OrderViewSet(CustomModelViewSet):
|
|
queryset = self.filter_queryset(self.get_queryset())
|
|
queryset = self.filter_queryset(self.get_queryset())
|
|
if export:
|
|
if export:
|
|
queryset = queryset.filter(status=Order.FINISH).order_by('-student__classes_id',
|
|
queryset = queryset.filter(status=Order.FINISH).order_by('-student__classes_id',
|
|
- '-student__classes__grade_id')
|
|
|
|
|
|
+ '-student__classes__grade_id')
|
|
export_data = OrderResource().export(queryset)
|
|
export_data = OrderResource().export(queryset)
|
|
filename = attachment_save(export_data, '用户订单{}'.format(timezone.now().date()))
|
|
filename = attachment_save(export_data, '用户订单{}'.format(timezone.now().date()))
|
|
|
|
|
|
return response_ok({'filename': filename})
|
|
return response_ok({'filename': filename})
|
|
- total = queryset.aggregate(total_amount=Sum('total_amount'), coupon_deduction=Sum('coupon_deduction'), actual_amount=Sum('actual_amount'))
|
|
|
|
- totalRow = {'totalRow':1,
|
|
|
|
|
|
+ total = queryset.aggregate(total_amount=Sum('total_amount'), coupon_deduction=Sum('coupon_deduction'),
|
|
|
|
+ actual_amount=Sum('actual_amount'))
|
|
|
|
+ totalRow = {'totalRow': 1,
|
|
'total_amount': Formater.formatPriceShow(total['total_amount']),
|
|
'total_amount': Formater.formatPriceShow(total['total_amount']),
|
|
- 'coupon_deduction':Formater.formatPriceShow(total['coupon_deduction']),
|
|
|
|
- 'actual_amount':Formater.formatPriceShow(total['actual_amount'],)}
|
|
|
|
|
|
+ 'coupon_deduction': Formater.formatPriceShow(total['coupon_deduction']),
|
|
|
|
+ 'actual_amount': Formater.formatPriceShow(total['actual_amount'], )}
|
|
page = self.paginate_queryset(queryset)
|
|
page = self.paginate_queryset(queryset)
|
|
if page is not None:
|
|
if page is not None:
|
|
serializer = self.get_serializer(page, many=True)
|
|
serializer = self.get_serializer(page, many=True)
|
|
@@ -59,7 +60,8 @@ class OrderViewSet(CustomModelViewSet):
|
|
queryset = queryset.filter(create_user=self.request.user)
|
|
queryset = queryset.filter(create_user=self.request.user)
|
|
elif self.request.user.type == User.AGENT:
|
|
elif self.request.user.type == User.AGENT:
|
|
# 代理商,筛选代理的类别和学校
|
|
# 代理商,筛选代理的类别和学校
|
|
- queryset = queryset.filter(Q(commodity__cogetory__in=self.request.user.cogetory) | Q(student__school=self.request.user.school))
|
|
|
|
|
|
+ queryset = queryset.filter(
|
|
|
|
+ Q(commodity__cogetory__in=self.request.user.cogetory) | Q(student__school=self.request.user.school))
|
|
|
|
|
|
f = OrderFilter(self.request.GET, queryset=queryset)
|
|
f = OrderFilter(self.request.GET, queryset=queryset)
|
|
return f.qs
|
|
return f.qs
|
|
@@ -84,7 +86,7 @@ class OrderViewSet(CustomModelViewSet):
|
|
if serializer.is_valid(raise_exception=True):
|
|
if serializer.is_valid(raise_exception=True):
|
|
instance = serializer.save()
|
|
instance = serializer.save()
|
|
|
|
|
|
- instance.total_amount = count * commodity.price * commodity.discount/100
|
|
|
|
|
|
+ instance.total_amount = count * commodity.price * commodity.discount / 100
|
|
actual_amount = instance.total_amount
|
|
actual_amount = instance.total_amount
|
|
if coupon:
|
|
if coupon:
|
|
coupon = Coupon.objects.filter(id=coupon).first()
|
|
coupon = Coupon.objects.filter(id=coupon).first()
|
|
@@ -148,16 +150,56 @@ class OrderViewSet(CustomModelViewSet):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response_error(str(e))
|
|
return response_error(str(e))
|
|
|
|
|
|
|
|
+
|
|
class ExportOrderDictView(APIView):
|
|
class ExportOrderDictView(APIView):
|
|
permission_classes = [isLogin]
|
|
permission_classes = [isLogin]
|
|
|
|
|
|
def get(self, request):
|
|
def get(self, request):
|
|
- queryset = Order.objects.filter(status=Order.FINISH).order_by('-student__classes_id','-student__classes__grade_id')
|
|
|
|
|
|
+ queryset = Order.objects.filter(status=Order.FINISH).order_by('-student__classes_id',
|
|
|
|
+ '-student__classes__grade_id')
|
|
export_data = OrderResource().export(queryset)
|
|
export_data = OrderResource().export(queryset)
|
|
- filename = attachment_save(export_data,'用户订单{}'.format(timezone.now().date()))
|
|
|
|
|
|
+ filename = attachment_save(export_data, '用户订单{}'.format(timezone.now().date()))
|
|
|
|
|
|
return response_ok({'filename': filename})
|
|
return response_ok({'filename': filename})
|
|
|
|
|
|
|
|
+
|
|
|
|
+class WXGetCoupon(APIView):
|
|
|
|
+ permission_classes = [isLogin]
|
|
|
|
+
|
|
|
|
+ def get(self, request):
|
|
|
|
+ commodity_id = request.GET.get('commodity')
|
|
|
|
+ student_id = request.GET.get('student')
|
|
|
|
+ commodity = Commodity.objects.filter(id=commodity_id).first()
|
|
|
|
+ data = {
|
|
|
|
+ 'coupon_name': '',
|
|
|
|
+ 'coupon_amount': 0,
|
|
|
|
+ }
|
|
|
|
+ if not commodity:
|
|
|
|
+ return response_ok(data)
|
|
|
|
+ student = Student.objects.filter(id=student_id).first()
|
|
|
|
+ coupons = Coupon.objects.filter(enable=True, begin_date__lte=timezone.now().date(),
|
|
|
|
+ end_date__gte=timezone.now().date())
|
|
|
|
+ for coupon in coupons:
|
|
|
|
+ if coupon.category:
|
|
|
|
+ categorys = coupon.category.split(',')
|
|
|
|
+ if commodity.category and str(commodity.category.id) in categorys:
|
|
|
|
+ data = {
|
|
|
|
+ 'coupon_id': coupon.id,
|
|
|
|
+ 'coupon_name': coupon.name,
|
|
|
|
+ 'coupon_amount': Formater.formatPriceShow(coupon.amount),
|
|
|
|
+ }
|
|
|
|
+ return response_ok(data)
|
|
|
|
+ if student and coupon.school:
|
|
|
|
+ schools = coupon.school.split(',')
|
|
|
|
+ if str(student.school.id) in schools:
|
|
|
|
+ data = {
|
|
|
|
+ 'coupon_id': coupon.id,
|
|
|
|
+ 'coupon_name': coupon.name,
|
|
|
|
+ 'coupon_amount': Formater.formatPriceShow(coupon.amount),
|
|
|
|
+ }
|
|
|
|
+ return response_ok(data)
|
|
|
|
+ return response_ok(data)
|
|
|
|
+
|
|
class ShoppingCartViewSet(CustomModelViewSet):
|
|
class ShoppingCartViewSet(CustomModelViewSet):
|
|
permission_classes = [isLogin]
|
|
permission_classes = [isLogin]
|
|
queryset = ShoppingCart.objects.filter()
|
|
queryset = ShoppingCart.objects.filter()
|
|
@@ -197,6 +239,7 @@ class ShoppingCartViewSet(CustomModelViewSet):
|
|
traceback.print_exc()
|
|
traceback.print_exc()
|
|
return response_error(str(e))
|
|
return response_error(str(e))
|
|
|
|
|
|
|
|
+
|
|
class CouponViewSet(CustomModelViewSet):
|
|
class CouponViewSet(CustomModelViewSet):
|
|
permission_classes = [isLogin]
|
|
permission_classes = [isLogin]
|
|
queryset = Coupon.objects.filter()
|
|
queryset = Coupon.objects.filter()
|