Explorar el Código

Merge branch 'master' of http://git.bocai108.com:10180/Ethan/Customer-Service

Jonlin hace 6 años
padre
commit
8aaf0b3ed5
Se han modificado 3 ficheros con 165 adiciones y 52 borrados
  1. 30 7
      application/admin/controller/Report.php
  2. 97 8
      application/common.php
  3. 38 37
      composer.json

+ 30 - 7
application/admin/controller/Report.php

@@ -103,10 +103,11 @@ class Report extends Base
 
     public function attendancereport()
     {
+
         $goups = (new GroupsModel)->where(['status' => 1])->select();
-        $serday1 = date("Y-m-d",strtotime('-8 day'));
-        $serday2 = date("Y-m-d",strtotime('-1 day'));
-        $defday = $serday1.','.$serday2;
+        $serday1 = date("Y-m-d", strtotime('-7 day'));
+        $serday2 = date("Y-m-d", strtotime('-1 day'));
+        $defday = $serday1 . ',' . $serday2;
 
         if (request()->isAjax()) {
 
@@ -120,7 +121,7 @@ class Report extends Base
             }
             list($zone, $sgroup) = explode('|', $param);
             if (empty($zone)) {
-                $zoneArray1 = [$serday1,$serday2];
+                $zoneArray1 = [$serday1, $serday2];
             } else {
                 $zonesarr = explode(',', $zone);
                 $dd = $this->Date_segmentation($zonesarr['0'], $zonesarr['1']);
@@ -150,10 +151,12 @@ class Report extends Base
         return $this->fetch();
     }
 
-    function reportDataFormat($onoffdata, $timesdata, $uobjarr, $dataArray, $limit, $offset)
+    function reportDataFormat($onoffdata, $timesdata, $uobjarr, $dataArray, $limit, $offset, $returnAll = 0)
     {
         $allData = [];
         $all_last = [];
+        $stnulldata = ['0' => 0, '1' => 0, '2' => 0, '3' => 0, 'all' => 0, 's1p' => 0, 's2p' => 0, 's3p' => 0];
+
         foreach ($dataArray as $day) {
             foreach ($uobjarr as $uid => $user) {
                 $kfuid = 'KF' . $uid;
@@ -163,19 +166,39 @@ class Report extends Base
                     $allData[$day][$kfuid] = ['of0' => '', 'of1' => ''];
                 }
 
+                $uinfo_now = ['uname' => $uobjarr[$uid]->user_name, 'account' => $uobjarr[$uid]->user_account, 'day' => $day, 'uid' => $uid];
                 if (isset($timesdata[$day][$kfuid])) {
-                    $all_last[] = array_merge($timesdata[$day][$kfuid], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name, 'account' => $uobjarr[$uid]->user_account, 'day' => $day]);
+                    $all_last[] = array_merge($timesdata[$day][$kfuid], $allData[$day][$kfuid], $uinfo_now);
                 } else {
-                    $all_last[] = array_merge(['0' => 0, '1' => 0, '2' => 0, '3' => 0, 'all' => 0, 's1p' => 0, 'sp2' => 0, 'sp3' => 0], $allData[$day][$kfuid], ['uname' => $uobjarr[$uid]->user_name, 'account' => $uobjarr[$uid]->user_account, 'day' => $day]);
+                    $all_last[] = array_merge($stnulldata, $allData[$day][$kfuid], $uinfo_now);
                 }
             }
         }
 
+        usort($all_last, function ($a, $b) {
+            return $a == $b ? 0 : ($a > $b ? 1 : -1);
+        });
+
+        foreach ($all_last as $key => $val) {
+            $all_last[$key]['1'] = secendToHourMinit($all_last[$key]['1']);
+            $all_last[$key]['2'] = secendToHourMinit($all_last[$key]['2']);
+            $all_last[$key]['3'] = secendToHourMinit($all_last[$key]['3']);
+            $all_last[$key]['s1p'] = perDisplay($all_last[$key]['s1p']);
+            $all_last[$key]['s2p'] = perDisplay($all_last[$key]['s2p']);
+            $all_last[$key]['s3p'] = perDisplay($all_last[$key]['s3p']);
+        }
+
+        //导出数据
+        if ($returnAll) {
+            return $all_last;
+        }
+
         $len = count($all_last);
         $return = ['rows' => [], 'total' => $len];
         if ($offset >= $len) {
             return $return;
         }
+
         $begin = $offset;
         $end = ($offset + $limit);
         $end = ($end > $len) ? $len - 1 : $end;

+ 97 - 8
application/common.php

@@ -54,20 +54,109 @@ function kftoKey($uidArray, $type = 0)
     foreach ($uidArray as $val) {
         if ($type == 0) {
             $return[$val] = 0;
-        } elseif ($type==1) {
+        } elseif ($type == 1) {
             $return[$val] = [];
-        }else{
+        } else {
             $return[$val] = $val;
         }
     }
-    return $return ;
+    return $return;
 }
 
 
 //保留小数位数
-function  floatPointDigit($data,$long=2){
-    $long = intval($long) ;
-    $for1 = "%.".$long."f" ;
-    $for2 = "%.".($long+1)."f" ;
-    return  sprintf($for1,substr(sprintf($for2, $data), 0, -1));
+function floatPointDigit($data, $long = 2)
+{
+    $long = intval($long);
+    $for1 = "%." . $long . "f";
+    $for2 = "%." . ($long + 1) . "f";
+    return sprintf($for1, substr(sprintf($for2, $data), 0, -1));
+}
+
+//秒格式化为 小时分秒
+function secendToHourMinit($sec)
+{
+    $array = ['h' => 0, 'm' => 0, 's' => 0];
+    $sec = intval($sec);
+    $array['h'] = floor($sec / 3600);
+    $array['m'] = floor(($sec - 3600 * $array['h']) / 60);
+    $array['s'] = $sec - 3600 * $array['h'] - 60 * $array['m'];
+
+    $return = '';
+    if ($array['h']) {
+        $return .= $array['h'] . '小时';
+    }
+
+    if ($array['m']) {
+        $return .= $array['m'] . '分';
+    }
+
+    if ($array['s']) {
+        $return .= $array['s'] . '秒';
+    }
+
+    return $return;
+
+}
+
+//小数转百分比显示
+function perDisplay($dit, $xiaos = 2)
+{
+    return floatPointDigit(floor(100 * $dit), $xiaos) . '%';
 }
+
+/**
+ * 导出excel表格
+ *
+ * @param   array $columName 第一行的列名称
+ * @param   array $list 二维数组
+ * @param   string $setTitle sheet名称
+ * @return
+ * @author  Tggui <tggui@vip.qq.com>
+ */
+function exportExcel($columName, $list, $setTitle = 'Sheet1', $fileName = 'demo')
+{
+    if (empty($columName) || empty($list)) {
+        return '列名或者内容不能为空';
+    }
+
+    if (count($list[0]) != count($columName)) {
+        return '列名跟数据的列不一致';
+    }
+
+    //实例化PHPExcel类
+    $PHPExcel = new PHPExcel();
+    //获得当前sheet对象
+    $PHPSheet = $PHPExcel->getActiveSheet();
+    //定义sheet名称
+    $PHPSheet->setTitle($setTitle);
+
+    //excel的列 这么多够用了吧?不够自个加 AA AB AC ……
+    $letter = [
+        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
+        'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
+    ];
+    //把列名写入第1行 A1 B1 C1 ...
+    for ($i = 0; $i < count($list[0]); $i++) {
+        $PHPSheet->setCellValue("$letter[$i]1", "$columName[$i]");
+    }
+    //内容第2行开始
+    foreach ($list as $key => $val) {
+        foreach (array_values($val) as $key2 => $val2) {
+            $PHPSheet->setCellValue($letter[$key2] . ($key + 2), $val2);
+        }
+    }
+    //生成2007版本的xlsx
+    $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel2007');
+    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
+    header('Content-Disposition: attachment;filename=' . $fileName . '.xlsx');
+    header('Cache-Control: max-age=0');
+    $PHPWriter->save("php://output");
+}
+
+/*
+ * 使用方法
+$titlname    =    ['订单号','消费用户','订单金额','订单数量','支付状态','订单时间'];
+exportExcel($titlname,'你的二维数组数据','Sheet1','文件名称');
+*/
+

+ 38 - 37
composer.json

@@ -1,40 +1,41 @@
 {
-    "name": "topthink/think",
-    "description": "the new thinkphp framework",
-    "type": "project",
-    "keywords": [
-        "framework",
-        "thinkphp",
-        "ORM"
-    ],
-    "homepage": "http://thinkphp.cn/",
-    "license": "Apache-2.0",
-    "authors": [
-        {
-            "name": "liu21st",
-            "email": "liu21st@gmail.com"
-        }
-    ],
-    "require": {
-        "php": ">=5.4.0",
-        "topthink/framework": "~5.0.0",
-        "zoujingli/ip2region": "^1.0"
-    },
-    "autoload": {
-        "psr-4": {
-            "app\\": "application/"
-        }
-    },
-    "extra": {
-        "think-path": "thinkphp"
-    },
-    "config": {
-        "preferred-install": "dist"
-    },
-    "repositories": {
-        "packagist": {
-            "type": "composer",
-            "url": "https://packagist.phpcomposer.com"
-        }
+  "name": "topthink/think",
+  "description": "the new thinkphp framework",
+  "type": "project",
+  "keywords": [
+    "framework",
+    "thinkphp",
+    "ORM"
+  ],
+  "homepage": "http://thinkphp.cn/",
+  "license": "Apache-2.0",
+  "authors": [
+    {
+      "name": "liu21st",
+      "email": "liu21st@gmail.com"
     }
+  ],
+  "require": {
+    "php": ">=5.4.0",
+    "topthink/framework": "~5.0.0",
+    "zoujingli/ip2region": "^1.0",
+    "phpoffice/phpexcel": "1.8.2"
+  },
+  "autoload": {
+    "psr-4": {
+      "app\\": "application/"
+    }
+  },
+  "extra": {
+    "think-path": "thinkphp"
+  },
+  "config": {
+    "preferred-install": "dist"
+  },
+  "repositories": {
+    "packagist": {
+      "type": "composer",
+      "url": "https://packagist.phpcomposer.com"
+    }
+  }
 }