gogs 2 месяцев назад
Родитель
Сommit
b2aeabf37b
3 измененных файлов с 21 добавлено и 11 удалено
  1. 3 0
      app/Service/ExpenseClaimsService.php
  2. 14 7
      app/Service/StatisticService.php
  3. 4 4
      routes/api.php

+ 3 - 0
app/Service/ExpenseClaimsService.php

@@ -91,6 +91,9 @@ class ExpenseClaimsService extends Service
                     'entrust_type' => $value['entrust_type'],
                     'expense_type' => $value['expense_type'],
                     'expense_attachments' => $value['expense_attachments'],
+                    'voucher_no' => $data['voucher_no']??"",
+                    'file_url' => $data['file_url']??"",
+                    'file_name' => $data['file_name']??"",
                     'top_depart_id' => $data['top_depart_id'],
                     'crt_time' => $time,
                 ];

+ 14 - 7
app/Service/StatisticService.php

@@ -41,7 +41,7 @@ class StatisticService extends Service
                 // 聚合求和
                 DB::raw("SUM(total_work_min) as total_work")
             )
-            ->groupBy("order_date", "item_id", "employee_id")
+            ->groupBy(DB::raw("FROM_UNIXTIME(order_time, '%Y-%m-%d')"), "item_id", "employee_id")
             ->orderby("order_date", "asc");
         $month_employee_list = $this->limit($month_employee_list, ['*'], $data);
         $dataCollection = collect($month_employee_list['data']);
@@ -56,7 +56,7 @@ class StatisticService extends Service
         $item_code_key_list = $item->wherein('id', $item_ids)->pluck("code", "id")->toArray();
         $month_employee_list['data'] = collect($month_employee_list['data'])->transform(function ($item) use ($employee_key_list, $item_title_key_list, $item_code_key_list) {
             $item['employee_name'] = $employee_key_list[$item['employee_id']] ?? "未知员工({$item['employee_id']})";
-            $item['item_title'] = $item_key_list[$item_title_key_list['item_id']] ?? "未知项目({$item['item_id']})";
+            $item['item_title'] = $item_title_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             $item['item_code'] = $item_code_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             $item['total_work_hours'] = round($item['total_work'] / 60, 2);
             return $item;
@@ -81,12 +81,17 @@ class StatisticService extends Service
                 // 聚合求和
                 DB::raw("SUM(total_work_min) as total_work")
             )
-            ->groupBy("order_month", "item_id", "employee_id")->toArray();
+            ->groupBy("order_month", "item_id", "employee_id")->get()->toArray();
         //查询所有人员工资
         $monthly_ps_order_ids = MonthlyPsOrder::Clear($user, $data)->where('del_time', 0)->where("month", ">=", $month_start)->where("month", "<", $month_end)
             ->pluck('id')->toArray();
-        $monthly_ps_order_key_list = MonthlyPsOrder::Clear($user, $data)->where('del_time', 0)->where("month", ">=", $month_start)->where("month", "<", $month_end)
-            ->pluck(DB::raw("FROM_UNIXTIME(month, '%Y-%m') as month"), 'id')->toArray();
+        $monthly_ps_order_key_list = MonthlyPsOrder::Clear($user, $data)
+            ->where('del_time', 0)
+            ->where("month", ">=", $month_start)
+            ->where("month", "<", $month_end)
+            ->select('id', DB::raw("FROM_UNIXTIME(month, '%Y-%m') as month_str"))
+            ->pluck('month_str', 'id')
+            ->toArray();
         $month_employee_salary = MonthlyPsOrderDetails::wherein('main_id', $monthly_ps_order_ids)
             ->select("employee_id", "salary", "main_id")
             ->get()->toArray();
@@ -99,6 +104,7 @@ class StatisticService extends Service
                 $salary_map[$val['employee_id'] . '_' . $month] = $val['salary'];
             }
         }
+//        var_dump($salary_map);die;
         // 2. 计算每个员工在每个月的全月总工时
         $employee_monthly_total_min = [];
         foreach ($month_employee_list as $row) {
@@ -119,6 +125,7 @@ class StatisticService extends Service
                     "month" => $item['order_month'],
                     "allocated_salary" => 0,
                     "work_minutes" => 0,
+                    "item_id" => $item['item_id'],
                 ];
             }
             $total_salary = $salary_map[$key] ?? 0;
@@ -146,7 +153,7 @@ class StatisticService extends Service
         $item_title_key_list = $item->wherein('id', $items)->pluck("title", "id")->toArray();
         $item_code_key_list = $item->wherein('id', $items)->pluck("code", "id")->toArray();
         $item_month_list = collect($item_month_list)->transform(function ($item) use ($item_title_key_list, $item_code_key_list) {
-            $item['item_title'] = $item_key_list[$item_title_key_list['item_id']] ?? "未知项目({$item['item_id']})";
+            $item['item_title'] = $item_title_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             $item['item_code'] = $item_code_key_list[$item['item_id']] ?? "未知项目({$item['item_id']})";
             return $item;
         })->all();
@@ -365,7 +372,7 @@ class StatisticService extends Service
             if ($start_year != $end_year) return [false, "查询不得跨年!", ""];
             $month_end = date('Y-m-01', strtotime($data['month_end'] . ' +1 month'));
         }
-        return [true, $month_start, $month_end];
+        return [true, strtotime($month_start), strtotime($month_end)];
     }
 
 }

+ 4 - 4
routes/api.php

@@ -184,13 +184,13 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
 
     //统计类
     ///人员月度工时统计表(日维度)
-    $route->any('employeeDayHourStatistic', 'Api\StatisticsController@employeeDayHourStatistic');
+    $route->any('employeeDayHourStatistic', 'Api\StatisticController@employeeDayHourStatistic');
     ///人员工资统计表(月维度)
-    $route->any('employeeMonthSalaryStatistic', 'Api\StatisticsController@employeeMonthSalaryStatistic');
+    $route->any('employeeMonthSalaryStatistic', 'Api\StatisticController@employeeMonthSalaryStatistic');
     ///项目工资分摊统计表(月)
-    $route->any('itemDaySalaryStatistic', 'Api\StatisticsController@itemDaySalaryStatistic');
+    $route->any('itemDaySalaryStatistic', 'Api\StatisticController@itemDaySalaryStatistic');
     ///项目设备折旧费用统计表(月)
-    $route->any('itemDeviceMonthStatistic', 'Api\StatisticsController@itemDeviceMonthStatistic');
+    $route->any('itemDeviceMonthStatistic', 'Api\StatisticController@itemDeviceMonthStatistic');