Parcourir la source

数据统计分页

lizhen il y a 2 jours
Parent
commit
0e25fc27e0
1 fichiers modifiés avec 13 ajouts et 7 suppressions
  1. 13 7
      application/api/controller/Jiankangdata.php

+ 13 - 7
application/api/controller/Jiankangdata.php

@@ -42,23 +42,29 @@ class Jiankangdata extends Api
     public function data(){
         $type = $this->request->post('type','week','trim');
 
+        $page = $this->request->post('page',1,'intval');
+        if($page < 1){ $page = 1;}
+
         if($type == 'week'){
-            $start_date = date('Y-m-d', strtotime('monday this week'));
-            $ended_date = date('Y-m-d', strtotime('sunday this week'));
+            $start_time = strtotime('monday this week') - (7 * 86400 * ($page - 1));
+            $ended_time = strtotime('sunday this week') - (7 * 86400 * ($page - 1));
+            $start_date = date('Y-m-d', $start_time);
+            $ended_date = date('Y-m-d', $ended_time);
 
             $days = 7;
             for($i=0;$i<$days;$i++){
-                $date_array[] = date('m.d', 86400*$i + strtotime('monday this week'));
+                $date_array[] = date('m.d', 86400*$i + $start_time);
             }
 
         }
         if($type == 'month'){
-            $start_date = date('Y-m-01');
-            $ended_date = date('Y-m-t');
+            $start_time =  strtotime('first day of -'.($page - 1).' month');
+            $start_date = date('Y-m-01',$start_time);
+            $ended_date = date('Y-m-t', $start_time);
 
-            $days = date('t');
+            $days = date('t',$start_time);
             for($i=0;$i<$days;$i++){
-                $date_array[] = date('m.d', 86400*$i + strtotime(date('Y-m-01')));
+                $date_array[] = date('m.d', 86400*$i + strtotime($start_date));
             }
 
         }