gogs 2 месяцев назад
Родитель
Сommit
567cf3336c
1 измененных файлов с 9 добавлено и 6 удалено
  1. 9 6
      app/Service/StatisticService.php

+ 9 - 6
app/Service/StatisticService.php

@@ -743,10 +743,12 @@ class StatisticService extends Service
         //查询所有项目人员的工时比例
         //汇总每个人每个月工资
         $depreciatio_map = [];
+        $all_depreciatio = [];
         foreach ($month_device_salary as $val) {
             $month = $monthly_dd_order_key_list[$val['main_id']] ?? '';
             if ($month) {
                 $depreciatio_map[$val['device_id'] . '_' . $month] = $val['depreciation_amount'];
+                $all_depreciatio[$val['device_id'] . '_' . $month] = $val['depreciation_amount']*100;
             }
         }
         // 2. 计算每个员工在每个月的全月总工时
@@ -774,13 +776,13 @@ class StatisticService extends Service
             // B. 计算工资分摊:(项目工时 / 月总工时) * 月工资
             if ($total_min > 0) {
                 $ratio = round($item['total_work'] / $total_min, 3);
-                $allocated_salary = round($ratio * $total_depreciatio, 2);
+                $allocated_salary = round($ratio * $total_depreciatio, 2)*100;
             } else {
                 $allocated_salary = 0;
             }
             $item_list[] = [
                 'device_id' => $item['device_id'],
-                'depreciation' => $allocated_salary*100,
+                'depreciation' => $allocated_salary,
                 'month' => $item['order_month'],
                 'item_id' => $item['item_id'],
             ];
@@ -793,14 +795,14 @@ class StatisticService extends Service
             return $group->count();
         })->toArray();
 
-        $month_employee_list = $collect->transform(function ($item, $index) use (&$device_count,&$depreciatio_map) {
+        $month_employee_list = $collect->transform(function ($item) use (&$device_count,&$all_depreciatio) {
 
             // 如果不是最后一条
             $key = $item['device_id'] . '_' . $item['month'];
             if (--$device_count[$key] > 0) {
-                $depreciatio_map[$key] -= $item['depreciation'];
+                $all_depreciatio[$key] -= $item['depreciation'];
             } else {
-                $item['depreciation'] = $depreciatio_map[$key];
+                $item['depreciation'] = $all_depreciatio[$key];
             }
             return $item;
         })->all();
@@ -810,7 +812,8 @@ class StatisticService extends Service
             if(!isset($return_item_list[$key])) $return_item_list[$key]['depreciation'] = 0;
             $return_item_list[$key]['depreciation'] += $v['depreciation'];
         }
-        return $item_list;
+//        var_dump($return_item_list);die;
+        return $return_item_list;
     }
 
     private function getFeeItemSalary($month_start, $month_end, $data, $user)