Ver Fonte

首页统计

hujingpei há 4 anos atrás
pai
commit
735ce928bc
2 ficheiros alterados com 25 adições e 0 exclusões
  1. 1 0
      apps/account/urls.py
  2. 24 0
      apps/account/views.py

+ 1 - 0
apps/account/urls.py

@@ -6,6 +6,7 @@ urlpatterns = [
     url(r'^login/$', LoginView.as_view()),
     url(r'^token_refresh/$', RefreshTokenView.as_view()),
     url(r'^employee/change_password/$', ChangePassword.as_view()),
+    url(r'^statistics/$', HomeStatisticsView.as_view()),
 
     url(r'^permission/dict/$', PermissionDictView.as_view()), # 人员管理,编辑,权限组
     url(r'^permission/all/$', PermissionsListView.as_view()), # 权限管理,编辑,加载所有权限

+ 24 - 0
apps/account/views.py

@@ -23,6 +23,7 @@ from apps.account.consts import PermissionMenu
 from collections import OrderedDict
 from apps.agent.models import Store, Agent,GeneralAgent
 from utils.exceptions import CustomError
+from apps.customer.models import ReportCustomer
 
 class LoginView(ObtainJSONWebToken):
     serializer_class = JWTSerializer
@@ -377,3 +378,26 @@ class EmployeeTreeView(APIView):
         # if len(data) == 1:
         #     data = data[0]['children']
         return response_ok(data)
+
+
+class HomeStatisticsView(APIView):
+    # 首页统计
+    permission_classes = [isLogin, ]
+
+    def get(self, request):
+        print(111111111111,request.user)
+        statistics = {
+            'today_report': 0,  # 本日新增报备
+            'mouth_report': 0,  # 本月新增报备
+            'general_report': 0,  # 总报备
+        }
+        if request.user or request.user.is_authenticated:
+            today = timezone.now().date()
+            reports = ReportCustomer.objects.filter(store__in=request.user.get_manager_range(),
+                                                    report_status=ReportCustomer.CHECKED)
+            statistics['today_report'] = reports.filter(check_time__gte=str(today) + ' 00:00:00').count()
+            statistics['mouth_report'] = reports.filter(check_time__year=today.year, check_time__month=today.month).count()
+            statistics['general_report'] = reports.count()
+            return response_ok(statistics)
+        else:
+            return response_ok(statistics)