浏览代码

修改推送消息的日统计逻辑

tanghongbin 4 年之前
父节点
当前提交
5b3945d69a
共有 2 个文件被更改,包括 15 次插入22 次删除
  1. 11 10
      Controller/AdminManage.py
  2. 4 12
      Controller/StatisticsController.py

+ 11 - 10
Controller/AdminManage.py

@@ -464,21 +464,23 @@ class AdminManage(TemplateView):
     def query_push_day_statistics(self, level, response):
         start_time = 0
         end_time = 0
-        localtime = time.localtime()
-        current_day = localtime.tm_mday
-
-        time_struct = [localtime.tm_year, localtime.tm_mon, current_day, 0, 0, 0, 0, 0, 0]
-        current_time = int(time.mktime(tuple(time_struct)))
-        current_time = current_time - time.timezone - 8 * 60 * 60
+        # localtime = time.localtime()
+        # current_day = localtime.tm_mday
+        #
+        # time_struct = [localtime.tm_year, localtime.tm_mon, current_day, 0, 0, 0, 0, 0, 0]
+        # current_time = int(time.mktime(tuple(time_struct)))
+        current_time = int(time.time())
+        count = int(current_time / (24 * 3600))
+        current_time = count * 24 * 3600 - 8 * 3600
         count = 0
         if level == 0: # 七天
-            start_time = current_time - 6 * 24 * 60 * 60
+            start_time = current_time - 6 * 24 * 3600
             count = 6
         elif level == 1:
-            start_time = current_time - 13 * 24 * 60 * 60
+            start_time = current_time - 13 * 24 * 3600
             count = 13
         elif level == 2:
-            start_time = current_time - 29 * 24 * 60 * 60
+            start_time = current_time - 29 * 24 * 3600
             count = 29
 
         end_time = current_time
@@ -607,7 +609,6 @@ class AdminManage(TemplateView):
             return response.json(444)
 
         date = datetime.datetime(2020, 9, 15)
-        tmp_time = 3600 * float(tz)
         start_time = date.fromtimestamp((int(start_time)))
         end_time = date.fromtimestamp(int(end_time))
         tz = int(tz)

+ 4 - 12
Controller/StatisticsController.py

@@ -156,18 +156,10 @@ def statistcsPushDay(request):
     if token.code != 0:
         return response.json(token.code)
 
-    localtime = time.localtime()
-    current_day = localtime.tm_mday
-    print(current_day)
-
-    distance_time = 8 * 60 * 60
-    time_struct = [localtime.tm_year, localtime.tm_mon, current_day - 1, 0, 0, 0, 0, 0, 0]
-    start_time = int(time.mktime(tuple(time_struct)))
-    start_time = start_time - time.timezone - distance_time
-
-    print(start_time)
-
-    end_time = start_time + 24 * 60 * 60
+    current_time = int(time.time())
+    count = current_time / (24 * 3600)
+    end_time = count * 24 * 3600 - 8 * 3600
+    start_time = end_time - 24 * 3600
     print(end_time)
 
     eq_qs = Equipment_Info.objects.filter(addTime__gte=start_time, addTime__lte=end_time)