Browse Source

饼状报表展示

DYaiu 4 years ago
parent
commit
2479082314
2 changed files with 15 additions and 2 deletions
  1. 3 2
      basic/urls.py
  2. 12 0
      basic/views.py

+ 3 - 2
basic/urls.py

@@ -1,6 +1,6 @@
 from rest_framework_bulk.routes import BulkRouter
-
-from basic.views import MenuView
+from django.conf.urls import url
+from basic.views import MenuView, StatisticsView
 
 router = BulkRouter()
 router.register(r'menu', MenuView)
@@ -8,4 +8,5 @@ router.register(r'menu', MenuView)
 urlpatterns = router.urls
 
 urlpatterns += [
+    url('statistics', StatisticsView.as_view())
 ]

+ 12 - 0
basic/views.py

@@ -1,7 +1,12 @@
+from django.db.models import Sum
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
 from rest_framework.viewsets import ModelViewSet
 
 from basic.models import Menu
 from basic.serializer import MenuSerializer
+from payment.models import Payment
 
 
 class MenuView(ModelViewSet):
@@ -9,3 +14,10 @@ class MenuView(ModelViewSet):
     serializer_class = MenuSerializer
     pagination_class = None
     filter_fields = {'code': ['exact'], 'parent': ['exact']}
+
+
+class StatisticsView(APIView):
+    def get(self, request):
+        data = list(
+            Payment.objects.values('payment_type').annotate(price_sum=Sum('index_price')).order_by('-price_sum'))
+        return Response(data, status=status.HTTP_200_OK)