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