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

+ 8 - 6
app/Service/StatisticService.php

@@ -643,10 +643,12 @@ class StatisticService extends Service
         //查询所有项目人员的工时比例
         //汇总每个人每个月工资
         $salary_map = [];
+        $all_salary = [];
         foreach ($month_employee_salary as $val) {
             $month = $monthly_ps_order_key_list[$val['main_id']] ?? '';
             if ($month) {
-                $salary_map[$val['employee_id'] . '_' . $month] = $val['salary']*100;
+                $salary_map[$val['employee_id'] . '_' . $month] = $val['salary'];
+                $all_salary[$val['employee_id'] . '_' . $month] = $val['salary']*100;
             }
         }
         // 2. 计算每个员工在每个月的全月总工时
@@ -675,13 +677,13 @@ class StatisticService extends Service
             // B. 计算工资分摊:(项目工时 / 月总工时) * 月工资
             if ($total_min > 0) {
                 $ratio = $item['total_work'] / $total_min;
-                $allocated_salary = round($ratio * $total_salary, 2);
+                $allocated_salary = round($ratio * $total_salary, 2)*100;
             } else {
                 $allocated_salary = 0;
             }
             $item_list[] = [
                 'employee_id' => $item['employee_id'],
-                'allocated_salary' => $allocated_salary*100,
+                'allocated_salary' => $allocated_salary,
                 'month' => $item['order_month'],
                 'item_id' => $item['item_id'],
             ];
@@ -694,14 +696,14 @@ class StatisticService extends Service
             return $group->count();
         })->toArray();
 
-        $month_employee_list = $collect->transform(function ($item, $index) use (&$employee_count,&$salary_map) {
+        $month_employee_list = $collect->transform(function ($item, $index) use (&$employee_count,&$all_salary) {
 
             // 如果不是最后一条
             $key = $item['employee_id'] . '_' . $item['month'];
             if (--$employee_count[$key] > 0) {
-                $salary_map[$key] -= $item['allocated_salary'];
+                $all_salary[$key] -= $item['allocated_salary'];
             } else {
-                $item['allocated_salary'] = $salary_map[$key];
+                $item['allocated_salary'] = $all_salary[$key];
             }
             return $item;
         })->all();