|
|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use App\Model\DailyDwOrder;
|
|
|
+use App\Model\DailyDwOrderDetails;
|
|
|
use App\Model\DailyPwOrder;
|
|
|
use App\Model\DailyPwOrderDetails;
|
|
|
use App\Model\ExpenseClaims;
|
|
|
@@ -376,4 +378,159 @@ class BIService extends Service
|
|
|
|
|
|
return $return;
|
|
|
}
|
|
|
+
|
|
|
+ public function cockpit($data, $user)
|
|
|
+ {
|
|
|
+ // 1. 声明时区对象
|
|
|
+ $utcZone = new \DateTimeZone('UTC');
|
|
|
+ $localZone = new \DateTimeZone('Asia/Shanghai'); // 你的数据库/服务器本地时区(北京时间)
|
|
|
+
|
|
|
+ if (!empty($data['time'][0]) && !empty($data['time'][1])) {
|
|
|
+ // 【A. 满足 employeeSalarySummary 的 UTC 干净时间】
|
|
|
+ // 提取前端 ISO 串中的纯日期,强制转为 UTC 视角的开始和结束
|
|
|
+ $rawStartUtc = new \DateTime($data['time'][0], $utcZone);
|
|
|
+ $rawEndUtc = new \DateTime($data['time'][1], $utcZone);
|
|
|
+
|
|
|
+ $startDateTimeUtc = new \DateTime($rawStartUtc->format('Y-m-d') . ' 00:00:00', $utcZone);
|
|
|
+ $endDateTimeUtc = new \DateTime($rawEndUtc->format('Y-m-d') . ' 23:59:59', $utcZone);
|
|
|
+
|
|
|
+ // 【B. 满足 getManWork 的本地 00点和23点 时间戳】
|
|
|
+ $startTimestampLocal = (new \DateTime($rawStartUtc->format('Y-m-d') . ' 00:00:00', $localZone))->getTimestamp();
|
|
|
+ $endTimestampLocal = (new \DateTime($rawEndUtc->format('Y-m-d') . ' 23:59:59', $localZone))->getTimestamp();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 【没传参时的默认兜底逻辑】
|
|
|
+ // UTC 视角的当月起止
|
|
|
+ $startDateTimeUtc = new \DateTime('first day of this month 00:00:00', $utcZone);
|
|
|
+ $endDateTimeUtc = new \DateTime('last day of this month 23:59:59', $utcZone);
|
|
|
+
|
|
|
+ // 本地视角的当月起止时间戳
|
|
|
+ $startTimestampLocal = (new \DateTime('first day of this month 00:00:00', $localZone))->getTimestamp();
|
|
|
+ $endTimestampLocal = (new \DateTime('last day of this month 23:59:59', $localZone))->getTimestamp();
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['start_time'] = $startTimestampLocal;
|
|
|
+ $data['end_time'] = $endTimestampLocal;
|
|
|
+
|
|
|
+ $array = $this->getManWork($data, $user);
|
|
|
+ // 当月设备工时信息
|
|
|
+ $array2 = $this->getDeviceWork($data, $user);
|
|
|
+ $array = array_merge_recursive($array, $array2);
|
|
|
+ $array3 = $this->getDeviceOldWork($data, $user);
|
|
|
+ $array = array_merge_recursive($array, $array3);
|
|
|
+ $array3 = $this->getFeeOrder($data, $user);
|
|
|
+ $array = array_merge_recursive($array, $array3);
|
|
|
+
|
|
|
+ $passTime = [
|
|
|
+ $startDateTimeUtc->format('Y-m-d'),
|
|
|
+ $endDateTimeUtc->format('Y-m-d')
|
|
|
+ ];
|
|
|
+
|
|
|
+ list($status, $return) = (new StatisticService())->employeeSalarySummary(['time' => $passTime], $user);
|
|
|
+ if(! $status) return [false, $return];
|
|
|
+ $total = array_sum(array_column($return,'money'));
|
|
|
+ $array['rd_total_money'] = $total;
|
|
|
+
|
|
|
+ return [true, $array];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getManWork($data, $user){
|
|
|
+ $model = DailyPwOrder::Clear($user, $data);
|
|
|
+ $id = $model->where('del_time', 0)
|
|
|
+ ->where('order_time', '>=', $data['start_time'])
|
|
|
+ ->where('order_time', '<=', $data['end_time'])
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $details = DailyPwOrderDetails::where('del_time', 0)
|
|
|
+ ->whereIn('main_id', $id) // 💡 避坑提示:原代码如果是数组 $id,这里建议用 whereIn
|
|
|
+ ->select('employee_id', 'total_work_min')
|
|
|
+ ->get()->toArray();
|
|
|
+ // 1. 计算当月总工时(将二维数组中所有 'total_work_min' 字段求和)
|
|
|
+ $totalWorkMin = array_sum(array_column($details, 'total_work_min'));
|
|
|
+
|
|
|
+ // 2. 如果你需要把分钟数转换为“小时”,可以除以 60(保留两位小数,根据业务需要决定是否转换)
|
|
|
+ $totalWorkHours = round($totalWorkMin / 60, 2);
|
|
|
+
|
|
|
+ // 3. 计算参与人员总数(先提取所有员工ID,再通过 array_unique 去重,最后 count 计算数量)
|
|
|
+ $employeeIds = array_column($details, 'employee_id');
|
|
|
+ $uniqueEmployeeIds = array_unique($employeeIds);
|
|
|
+ $totalEmployees = count($uniqueEmployeeIds);
|
|
|
+
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'man_total_work_hours' => $totalWorkHours, // 当月总工时
|
|
|
+ 'man_total_employees' => $totalEmployees, // 参与人员总数
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getDeviceWork($data, $user){
|
|
|
+ $model = DailyDwOrder::Clear($user, $data);
|
|
|
+ $id = $model->where('del_time', 0)
|
|
|
+ ->where('order_time', '>=', $data['start_time'])
|
|
|
+ ->where('order_time', '<=', $data['end_time'])
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $details = DailyDwOrderDetails::where('del_time', 0)
|
|
|
+ ->whereIn('main_id', $id) // 💡 避坑提示:原代码如果是数组 $id,这里建议用 whereIn
|
|
|
+ ->select('device_id', 'total_work_min')
|
|
|
+ ->get()->toArray();
|
|
|
+ // 1. 计算当月总工时(将二维数组中所有 'total_work_min' 字段求和)
|
|
|
+ $totalWorkMin = array_sum(array_column($details, 'total_work_min'));
|
|
|
+
|
|
|
+ // 2. 如果你需要把分钟数转换为“小时”,可以除以 60(保留两位小数,根据业务需要决定是否转换)
|
|
|
+ $totalWorkHours = round($totalWorkMin / 60, 2);
|
|
|
+
|
|
|
+ $employeeIds = array_column($details, 'device_id');
|
|
|
+ $uniqueEmployeeIds = array_unique($employeeIds);
|
|
|
+ $totalEmployees = count($uniqueEmployeeIds);
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'device_total_work_hours' => $totalWorkHours, // 当月总工时
|
|
|
+ 'device_total_num' => $totalEmployees, // 参与人员总数
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getDeviceOldWork($data, $user){
|
|
|
+ $model = MonthlyDdOrder::Clear($user, $data);
|
|
|
+ $id = $model->where('del_time', 0)
|
|
|
+ ->where('month', '>=', $data['start_time'])
|
|
|
+ ->where('month', '<=', $data['end_time'])
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $details = MonthlyDdOrderDetails::where('del_time', 0)
|
|
|
+ ->whereIn('main_id', $id)
|
|
|
+ ->select('device_id', 'depreciation_amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $totalWorkMin = array_sum(array_column($details, 'depreciation_amount'));
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'device_total_money' => $totalWorkMin,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function getFeeOrder($data, $user){
|
|
|
+ $model = ExpenseClaims::Clear($user, $data);
|
|
|
+ $id = $model->where('del_time', 0)
|
|
|
+ ->where('month', '>=', $data['start_time'])
|
|
|
+ ->where('month', '<=', $data['end_time'])
|
|
|
+ ->pluck('id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $details = ExpenseClaimsDetails::where('del_time', 0)
|
|
|
+ ->whereIn('expense_claims_id', $id)
|
|
|
+ ->select('item_id', 'amount')
|
|
|
+ ->get()->toArray();
|
|
|
+ $totalWorkMin = array_sum(array_column($details, 'amount'));
|
|
|
+
|
|
|
+ $employeeIds = array_column($details, 'item_id');
|
|
|
+ $uniqueEmployeeIds = array_unique($employeeIds);
|
|
|
+ $totalEmployees = count($uniqueEmployeeIds);
|
|
|
+ return [
|
|
|
+ 'fee_total_money' => $totalWorkMin,
|
|
|
+ 'fee_total_num' => $totalEmployees,
|
|
|
+ ];
|
|
|
+ }
|
|
|
}
|