|
@@ -2,29 +2,22 @@
|
|
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
|
|
-use App\Model\AuxiliaryAccount;
|
|
|
|
|
use App\Model\AuxiliaryAccountDetails;
|
|
use App\Model\AuxiliaryAccountDetails;
|
|
|
-use App\Model\CalendarDetails;
|
|
|
|
|
use App\Model\DailyDwOrderDetails;
|
|
use App\Model\DailyDwOrderDetails;
|
|
|
use App\Model\DailyPwOrderDetails;
|
|
use App\Model\DailyPwOrderDetails;
|
|
|
use App\Model\Device;
|
|
use App\Model\Device;
|
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
|
-use App\Model\ExpenseClaims;
|
|
|
|
|
use App\Model\ExpenseClaimsDetails;
|
|
use App\Model\ExpenseClaimsDetails;
|
|
|
use App\Model\Fee;
|
|
use App\Model\Fee;
|
|
|
use App\Model\Item;
|
|
use App\Model\Item;
|
|
|
-use App\Model\ItemDetails;
|
|
|
|
|
use App\Model\MonthlyDdOrder;
|
|
use App\Model\MonthlyDdOrder;
|
|
|
use App\Model\MonthlyDdOrderDetails;
|
|
use App\Model\MonthlyDdOrderDetails;
|
|
|
use App\Model\MonthlyPsOrder;
|
|
use App\Model\MonthlyPsOrder;
|
|
|
use App\Model\MonthlyPsOrderDetails;
|
|
use App\Model\MonthlyPsOrderDetails;
|
|
|
-use App\Model\MonthlyPwOrderDetails;
|
|
|
|
|
-use App\Model\RuleSet;
|
|
|
|
|
-use App\Model\RuleSetDetails;
|
|
|
|
|
-use Carbon\Carbon;
|
|
|
|
|
|
|
+use App\Service\Statistic\StatisticCommonService;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
-class StatisticService extends Service
|
|
|
|
|
|
|
+class StatisticService extends StatisticCommonService
|
|
|
{
|
|
{
|
|
|
public function employeeDayHourStatistic($data, $user)
|
|
public function employeeDayHourStatistic($data, $user)
|
|
|
{
|
|
{
|
|
@@ -32,68 +25,33 @@ class StatisticService extends Service
|
|
|
//项目编码、项目名称、人员名称、工时、日期
|
|
//项目编码、项目名称、人员名称、工时、日期
|
|
|
list($status, $month_start, $month_end) = $this->commonRule($data);
|
|
list($status, $month_start, $month_end) = $this->commonRule($data);
|
|
|
if (!$status) return [false, $month_start];
|
|
if (!$status) return [false, $month_start];
|
|
|
- $month_employee = DailyPwOrderDetails::Clear($user, $data);
|
|
|
|
|
- $month_employee_list = $month_employee->where("order_time", ">=", $month_start)->where("order_time", "<", $month_end)
|
|
|
|
|
- ->where('del_time', 0)
|
|
|
|
|
- ->select(
|
|
|
|
|
- "item_id",
|
|
|
|
|
- "employee_id",
|
|
|
|
|
- // 将时间戳转为 Y-m-d 格式并起别名
|
|
|
|
|
- DB::raw("FROM_UNIXTIME(order_time, '%Y-%m-%d') as order_date"),
|
|
|
|
|
- // 聚合求和
|
|
|
|
|
- DB::raw("SUM(total_work_min) as total_work")
|
|
|
|
|
- )
|
|
|
|
|
- ->groupBy(DB::raw("FROM_UNIXTIME(order_time, '%Y-%m-%d')"), "item_id", "employee_id")
|
|
|
|
|
- ->orderby("order_date", "asc")->get()->toArray();
|
|
|
|
|
-// $month_employee_list = $this->limit($month_employee_list, ['*'], $data);
|
|
|
|
|
- $dataCollection = collect($month_employee_list);
|
|
|
|
|
|
|
+ $day_employee_list = $this->getItemEmployeeDayWorkList($user,$data,$month_start,$month_end);
|
|
|
|
|
+ $dataCollection = collect($day_employee_list);
|
|
|
$item_ids = $dataCollection->pluck('item_id')->unique()->values()->all();
|
|
$item_ids = $dataCollection->pluck('item_id')->unique()->values()->all();
|
|
|
$employee_ids = $dataCollection->pluck('employee_id')->unique()->values()->all();
|
|
$employee_ids = $dataCollection->pluck('employee_id')->unique()->values()->all();
|
|
|
-
|
|
|
|
|
- $employee = Employee::TopClear($user, $data);
|
|
|
|
|
- $employee_key_list = $employee->wherein('id', $employee_ids)->pluck("title", "id")->toArray();
|
|
|
|
|
-
|
|
|
|
|
- $item = Item::TopClear($user, $data);
|
|
|
|
|
- $item_title_key_list = $item->wherein('id', $item_ids)->pluck("title", "id")->toArray();
|
|
|
|
|
- $item_code_key_list = $item->wherein('id', $item_ids)->pluck("code", "id")->toArray();
|
|
|
|
|
- $collect = collect($month_employee_list);
|
|
|
|
|
-
|
|
|
|
|
- $employee_count = $collect->groupBy(function ($item) {
|
|
|
|
|
- // 这里的 $item 是集合中的每一行数据
|
|
|
|
|
- return $item['employee_id'] . '_' . $item['order_date'];
|
|
|
|
|
- })->map(function ($group) {
|
|
|
|
|
- return $group->count();
|
|
|
|
|
- })->toArray();
|
|
|
|
|
- $employee_work_count = $collect->groupBy(fn($item) => $item['employee_id'] . '_' . $item['order_date'])
|
|
|
|
|
- ->map(function ($group) {
|
|
|
|
|
- // 1. 算出小时并保留两位小数(例如 26.08)
|
|
|
|
|
- $hours = round($group->sum('total_work') / 60, 2);
|
|
|
|
|
-
|
|
|
|
|
- // 2. 乘以 100 并强转为整数(例如 2608)
|
|
|
|
|
- // 使用 round 是为了再次修正 26.08 * 100 可能产生的 2607.9999 误差
|
|
|
|
|
- return (int)round($hours * 100);
|
|
|
|
|
- })
|
|
|
|
|
- ->toArray();
|
|
|
|
|
- $collection = collect($month_employee_list);
|
|
|
|
|
- // 注意:这里使用 transform,参数名建议写准确
|
|
|
|
|
- // 关键点:use 后面加了 & 符号
|
|
|
|
|
- $month_employee_list = $collection->transform(function ($item, $index) use ($employee_key_list, $item_title_key_list, $item_code_key_list, &$employee_work_count, &$employee_count) {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $employee_key_list = Employee::wherein('id', $employee_ids)->pluck("title", "id")->toArray();
|
|
|
|
|
+ $item_title_key_list = Item::wherein('id', $item_ids)->pluck("title", "id")->toArray();
|
|
|
|
|
+ $item_code_key_list = Item::wherein('id', $item_ids)->pluck("code", "id")->toArray();
|
|
|
|
|
+ $keys = ["employee_id","order_date"];
|
|
|
|
|
+ list($employee_count,$employee_work_count) = $this->calculateCount($day_employee_list,$keys,"total_work");
|
|
|
|
|
+ $collection = collect($day_employee_list);
|
|
|
|
|
+ $month_employee_list = $collection->transform(function ($item) use ($employee_key_list, $item_title_key_list, $item_code_key_list, &$employee_work_count, &$employee_count,$keys) {
|
|
|
$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_title_key_list[$item['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']})";
|
|
|
-
|
|
|
|
|
// 如果不是最后一条
|
|
// 如果不是最后一条
|
|
|
- $key = $item['employee_id'] . '_' . $item['order_date'];
|
|
|
|
|
- if (--$employee_count[$key] > 0) {
|
|
|
|
|
- $current_hours = round($item['total_work'] / 60, 2);
|
|
|
|
|
- $item['total_work_hours'] = $current_hours;
|
|
|
|
|
- // 关键:递减外部的 $absolute_total_hours
|
|
|
|
|
- $employee_work_count[$key] -= $current_hours * 100;
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- $item['total_work_hours'] = round($employee_work_count[$key] / 100, 2);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $key = collect($keys)->map(fn($k) => $item[$k] ?? '')->implode('_');
|
|
|
|
|
+ $counts = ["employee_work_count"=>$employee_count];
|
|
|
|
|
+ $sums = ["employee_work_count"=>$employee_work_count];
|
|
|
|
|
+ $word_keys = [
|
|
|
|
|
+ "employee_work_count" =>
|
|
|
|
|
+ [
|
|
|
|
|
+ "key" => "total_work",
|
|
|
|
|
+ "value" => "total_work_hours",
|
|
|
|
|
+ "type" => "hour",
|
|
|
|
|
+ ]
|
|
|
|
|
+ ];
|
|
|
|
|
+ $this->calculateClosure($key,$item,$counts,$sums,$word_keys);
|
|
|
return $item;
|
|
return $item;
|
|
|
})->all();
|
|
})->all();
|
|
|
return [true, $month_employee_list];
|
|
return [true, $month_employee_list];
|
|
@@ -128,7 +86,7 @@ class StatisticService extends Service
|
|
|
->pluck('month_str', 'id')
|
|
->pluck('month_str', 'id')
|
|
|
->toArray();
|
|
->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",DB::raw("(base_salary + performance_salary + bonus + other) as salary"), "main_id")
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|
|
@@ -258,7 +216,7 @@ class StatisticService extends Service
|
|
|
->select('id', DB::raw("FROM_UNIXTIME(month, '%Y-%m') as month_str"))
|
|
->select('id', DB::raw("FROM_UNIXTIME(month, '%Y-%m') as month_str"))
|
|
|
->pluck('month_str', 'id')->toArray();
|
|
->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",DB::raw("(base_salary + performance_salary + bonus + other) as salary"), "main_id")
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|
|
@@ -639,7 +597,7 @@ class StatisticService extends Service
|
|
|
->pluck('month_str', 'id')
|
|
->pluck('month_str', 'id')
|
|
|
->toArray();
|
|
->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", DB::raw("(base_salary + performance_salary + bonus + other) as salary"), "main_id")
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|
|
@@ -1111,7 +1069,7 @@ class StatisticService extends Service
|
|
|
->pluck('month_str', 'id')
|
|
->pluck('month_str', 'id')
|
|
|
->toArray();
|
|
->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",DB::raw("(base_salary + performance_salary + bonus + other) as salary"), "main_id")
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|
|
@@ -1330,7 +1288,7 @@ class StatisticService extends Service
|
|
|
->pluck('month_str', 'id')
|
|
->pluck('month_str', 'id')
|
|
|
->toArray();
|
|
->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", "social_insurance", "public_housing_fund")
|
|
|
|
|
|
|
+ ->select("employee_id",DB::raw("(base_salary + performance_salary + bonus + other) as salary"), "main_id", "social_insurance", "public_housing_fund")
|
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
|
//查询所有项目人员的工时比例
|
|
//查询所有项目人员的工时比例
|
|
|
//汇总每个人每个月工资
|
|
//汇总每个人每个月工资
|