Browse Source

date to excel

zhangdehua 8 months ago
parent
commit
9c84622f95
1 changed files with 18 additions and 20 deletions
  1. 18 20
      app/index/controller/User.php

+ 18 - 20
app/index/controller/User.php

@@ -956,8 +956,8 @@ class User extends Controller
 
     public function pullAccessLogs()
     {
-        $path = $this->request->param('path','');
-        $ip = strval($this->request->param('ip',''));
+        $path = $this->request->param('path', '');
+        $ip = strval($this->request->param('ip', ''));
 
         $from = $this->request->param('from');
         $to = $this->request->param('to');
@@ -980,7 +980,7 @@ class User extends Controller
             $toInt = time();
         }
 
-         $data = UserAccessLog::getAccessLog($path, $fromInt, $toInt, $page, $size, $ip);
+        $data = UserAccessLog::getAccessLog($path, $fromInt, $toInt, $page, $size, $ip);
 
         return $this->renderSuccess($data);
     }
@@ -999,55 +999,53 @@ class User extends Controller
         $spreadsheet->getActiveSheet()->setCellValue('A1', '');
 
         $fromDate = $this->request->param('from');
-        $from = strtotime($fromDate);
-        if (!$from){
+        $from = $fromInit = strtotime($fromDate);
+        if (!$from) {
             return $this->renderError('input valid from date');
         }
 
         //$from = intval($this->request->param('from'));//要统计的起始时间戳
         //$to = 86400;
-        if ($from > time()){
+        if ($from > time()) {
             return $this->renderError('input valid ck');
         }
 
-        if (bcdiv(time() - $from,86400,0) > 15){
+        if (bcdiv(time() - $from, 86400, 0) > 15) {
             return $this->renderError('from too old');
         }
 
         $ck = $this->request->param('ck');
-        if ($ck != 'free9999'){
+        if ($ck != 'free9999') {
             return $this->renderError('input valid ck');
         }
 
         $data = [];
 
 
-        while ($from < time()){
+        while ($from < time()) {
             $to = $from + 86399;
-            $data[date('Y-m-d',$from)] = UserAccessLog::getAccessLogPathes($from,$to);
+            $data[date('Y-m-d', $from)] = UserAccessLog::getAccessLogPathes($from, $to);
 
             $from = $from + 86400;
         }
-
-        $data['total_ips'] = [UserAccessLog::getAccessLogDistinctIps($from,time())];
-
+        $data['total_ips'] = [0 => UserAccessLog::getAccessLogDistinctIps($fromInit, time())];
         $i = 2;
 
-        foreach ($data as $date => $datum){
+        foreach ($data as $date => $datum) {
             $col = 'A';
-            $spreadsheet->getActiveSheet()->setCellValue($col.$i, $date);
-            foreach ($datum as $v){
-                $col = chr(ord($col) +1);
-                $spreadsheet->getActiveSheet()->setCellValue($col.$i, $v);
+            $spreadsheet->getActiveSheet()->setCellValue($col . $i, $date);
+            foreach ($datum as $v) {
+                $col = chr(ord($col) + 1);
+                $spreadsheet->getActiveSheet()->setCellValue($col . $i, $v);
             }
             $i++;
         }
 
-        $spreadsheet->getActiveSheet()->setCellValue('A'.$i, '说明:数量均为独立IP数量');
+        $spreadsheet->getActiveSheet()->setCellValue('A' . $i, '说明:数量均为独立IP数量');
 
         $writer = new Xlsx($spreadsheet);
         $filePath = 'uploads/05featuredemo.xlsx';
-        if (file_exists($filePath)){
+        if (file_exists($filePath)) {
             unlink($filePath);
         }