Browse Source

增加payment 统计数据 get接口

liceal 4 years ago
parent
commit
d3fa35e2c4

BIN
basic/__pycache__/models.cpython-37.pyc


BIN
basic/__pycache__/urls.cpython-37.pyc


BIN
basic/__pycache__/views.cpython-37.pyc


+ 1 - 0
basic/models.py

@@ -19,3 +19,4 @@ class Menu(MPTTModel):
         db_table = 'basic_menu'
         verbose_name = '报表菜单'
         verbose_name_plural = '报表菜单列表'
+

+ 2 - 0
basic/urls.py

@@ -15,6 +15,7 @@ Including another URLconf
 """
 
 # 主入口请求出口
+from django.conf.urls import url
 from rest_framework_bulk.routes import BulkRouter
 
 from basic.views import MenuView
@@ -24,4 +25,5 @@ router.register(r'menu', MenuView)
 
 urlpatterns = router.urls
 urlpatterns += [
+
 ]

+ 5 - 0
basic/views.py

@@ -1,6 +1,10 @@
+from django.db.models import Count
 from django.shortcuts import render
 
 # Create your views here.
+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
@@ -11,3 +15,4 @@ class MenuView(ModelViewSet):
     queryset = Menu.objects.all()
     serializer_class = MenuSerializer  # 序列化
     pagination_class = None
+

BIN
payment/__pycache__/urls.cpython-37.pyc


BIN
payment/__pycache__/views.cpython-37.pyc


+ 2 - 1
payment/urls.py

@@ -19,11 +19,12 @@ from django.conf.urls import url
 # 主入口请求出口
 from rest_framework_bulk.routes import BulkRouter
 
-from payment.views import PaymentView
+from payment.views import PaymentView, StatisticsView
 
 router = BulkRouter()
 router.register(r'payment', PaymentView)
 
 urlpatterns = router.urls
 urlpatterns += [
+    url('statistics',StatisticsView.as_view())
 ]

+ 16 - 0
payment/views.py

@@ -1,6 +1,10 @@
+from django.db.models import Count, Sum
 from django.shortcuts import render
 
 # Create your views here.
+from rest_framework import status
+from rest_framework.response import Response
+from rest_framework.views import APIView
 from rest_framework.viewsets import ModelViewSet
 
 from payment.models import Payment
@@ -12,3 +16,15 @@ class PaymentView(ModelViewSet):
     serializer_class = PaymentSerializer
     pagination_class = None
 
+
+# 统计 {order_by:0(默认0升序,1降序)}
+class StatisticsView(APIView):
+    def get(self, request):
+        data = request.GET
+        order_by_value = "price_sum"
+        if 'order_by' in data:
+            if data['order_by'] == 1:
+                order_by_value = "-price_sum"
+        res = Payment.objects.values('payment_type', 'year', 'month').annotate(price_sum=Sum('index_price')).order_by(
+            order_by_value)
+        return Response(data=res, status=status.HTTP_200_OK)