Procházet zdrojové kódy

封装的报表类方法

gogs před 1 měsícem
rodič
revize
6e72a2f393
1 změnil soubory, kde provedl 32 přidání a 34 odebrání
  1. 32 34
      app/Service/StatisticService.php

+ 32 - 34
app/Service/StatisticService.php

@@ -350,31 +350,25 @@ class StatisticService extends StatisticCommonService
             return $group->count();
         })->toArray();
 
-        $month_employee_list = $collect->transform(function ($item) use (&$employee_count,&$salary_map) {
+        $sums = [
+            "salary_map" => $salary_map
+        ];
+        $employee_counts = [
+            "salary_map" => $employee_count
+        ];
+        $word_keys = [
+            "salary_map" => [
+                "key" => "allocated_salary",
+                "value" => "allocated_salary",
+                "type" => "money",
+            ]
+        ];
+
+        $month_employee_list = $collect->transform(function ($item) use (&$employee_counts,&$sums,$word_keys) {
 
             // 如果不是最后一条
             $key = $item['employee_id'] . '_' . $item['month'];
-            $sums = [
-                "salary_map" => $salary_map
-            ];
-            $word_keys = [
-                "salary_map" => [
-                    "key" => "allocated_salary",
-                    "value" => "allocated_salary",
-                    "type" => "money",
-                ]
-            ];
-            $this->calculateClosure($key,$item,$employee_count,$sums,$word_keys);
-
-//            if(!isset($all_salary[$key])) $item['allocated_salary'] = 0;
-//            else{
-//                if (--$employee_count[$key] > 0) {
-//                    $all_salary[$key] -= $item['allocated_salary'];
-//                } else {
-//                    $item['allocated_salary'] = $all_salary[$key];
-//                }
-//            }
-
+            $this->calculateClosure($key,$item,$employee_counts,$sums,$word_keys);
             return $item;
         })->all();
 
@@ -407,21 +401,25 @@ class StatisticService extends StatisticCommonService
             return $group->count();
         })->toArray();
 
-        $month_employee_list = $collect->transform(function ($item) use (&$device_count,&$month_device_salary) {
+        $sums = [
+            "salary_map" => $month_device_salary
+        ];
+        $word_keys = [
+            "salary_map" => [
+                "key" => "allocated_depreciation",
+                "value" => "allocated_depreciation",
+                "type" => "money",
+            ]
+        ];
+        $device_counts = [
+            "salary_map" => $device_count
+        ];
+        $month_employee_list = $collect->transform(function ($item) use (&$device_counts,&$sums,$word_keys) {
 
             // 如果不是最后一条
             $key = $item['device_id'] . '_' . $item['month'];
-            $sums = [
-                "salary_map" => $month_device_salary
-            ];
-            $word_keys = [
-                "salary_map" => [
-                    "key" => "allocated_depreciation",
-                    "value" => "allocated_depreciation",
-                    "type" => "money",
-                ]
-            ];
-            $this->calculateClosure($key,$item,$device_count,$sums,$word_keys);
+
+            $this->calculateClosure($key,$item,$device_counts,$sums,$word_keys);
             return $item;
         })->all();
         $return_item_list = [];