|
@@ -69,7 +69,7 @@ class ExportFileService extends Service
|
|
|
protected static $fuc = [
|
|
|
self::type_one => 'kqCollect',
|
|
|
self::type_two => 'kqSummary',
|
|
|
- self::type_three => '',
|
|
|
+ self::type_three => 'kqMonthlyReport',
|
|
|
self::type_four => '',
|
|
|
self::type_five => '',
|
|
|
];
|
|
@@ -77,12 +77,13 @@ class ExportFileService extends Service
|
|
|
protected static $special = [
|
|
|
self::type_one,
|
|
|
self::type_two,
|
|
|
+ self::type_three,
|
|
|
];
|
|
|
|
|
|
protected static $fuc_name = [
|
|
|
self::type_one => '考勤统计',
|
|
|
self::type_two => '每日考勤数据汇总',
|
|
|
- self::type_three => '',
|
|
|
+ self::type_three => '月度考勤表',
|
|
|
self::type_four => '',
|
|
|
self::type_five => '',
|
|
|
];
|
|
@@ -94,10 +95,10 @@ class ExportFileService extends Service
|
|
|
self::$filename = self::$fuc_name[$data['type']] ?? "";
|
|
|
if(! in_array($data['type'], self::$special)) if(empty($data['id'])) return [false,'请选择导出数据'];
|
|
|
|
|
|
- //不超时
|
|
|
- ini_set('max_execution_time', 0);
|
|
|
- //内存设置
|
|
|
- ini_set('memory_limit', -1);
|
|
|
+// //不超时
|
|
|
+// ini_set('max_execution_time', 0);
|
|
|
+// //内存设置
|
|
|
+// ini_set('memory_limit', -1);
|
|
|
|
|
|
$function = self::$fuc[$data['type']];
|
|
|
list($status, $return) = $this->$function($data,$user);
|
|
@@ -176,6 +177,89 @@ class ExportFileService extends Service
|
|
|
return $this->saveExportData($return,$header,'kq');
|
|
|
}
|
|
|
|
|
|
+ // 新增方法
|
|
|
+ public function kqMonthlyReport($ergs, $user){
|
|
|
+ if(empty($ergs['month'])) return [false, '请选择导出月份']; // 格式: 2023-01
|
|
|
+
|
|
|
+ $month = $ergs['month'];
|
|
|
+ list($year, $mon) = explode('-', $month);
|
|
|
+
|
|
|
+ $weekMap = [
|
|
|
+ 'Sun' => '周日',
|
|
|
+ 'Mon' => '周一',
|
|
|
+ 'Tue' => '周二',
|
|
|
+ 'Wed' => '周三',
|
|
|
+ 'Thu' => '周四',
|
|
|
+ 'Fri' => '周五',
|
|
|
+ 'Sat' => '周六'
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 获取该月所有天数
|
|
|
+ $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $mon, $year);
|
|
|
+ $dates = [];
|
|
|
+ $weekdays = [];
|
|
|
+ for($d=1;$d<=$daysInMonth;$d++){
|
|
|
+ $dates[] = $d;
|
|
|
+ $dayOfWeek = date('D', strtotime("$year-$mon-" . str_pad($d, 2, '0', STR_PAD_LEFT)));
|
|
|
+ $weekdays[] = $weekMap[$dayOfWeek];
|
|
|
+ }
|
|
|
+
|
|
|
+ $employee_id = $ergs['employee_id'] ?? [];
|
|
|
+ // 获取员工列表
|
|
|
+ $employees = Employee::where('del_time',0)
|
|
|
+ ->when(! empty($employee_id) , fn($q) => $q->whereIn('id', $employee_id))
|
|
|
+ ->select('number','emp_name')
|
|
|
+ ->orderBy('number','asc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $employee_number = array_column($employees,'number');
|
|
|
+
|
|
|
+ // 获取该月考勤数据
|
|
|
+ $start_time = strtotime("$year-$mon-01 00:00:00");
|
|
|
+ $end_time = strtotime("$year-$mon-$daysInMonth 23:59:59");
|
|
|
+
|
|
|
+ //数据
|
|
|
+ $kqList = KqList::where('crt_time', '>=', $start_time)
|
|
|
+ ->where('crt_time', '<=', $end_time)
|
|
|
+ ->when(! empty($employee_number), function ($query) use ($employee_number) {
|
|
|
+ return $query->whereIn('number', $employee_number);
|
|
|
+ })
|
|
|
+ ->select('number', DB::raw('FROM_UNIXTIME(crt_time, "%d") as day'), DB::raw('ROUND((MAX(crt_time) - MIN(crt_time)) / 3600, 2) AS work_hour'))
|
|
|
+ ->groupBy('number', DB::raw('FROM_UNIXTIME(crt_time, "%d")'))
|
|
|
+ ->orderBy('number','asc')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // 重组数据
|
|
|
+ $kqData = [];
|
|
|
+ foreach($employees as $emp){
|
|
|
+ $row = [$emp['number'], $emp['emp_name']];
|
|
|
+ for($d=1;$d<=$daysInMonth;$d++){
|
|
|
+ $workHour = "";
|
|
|
+ foreach($kqList as $k){
|
|
|
+ if($k['number']==$emp['number'] && intval($k['day'])==$d && $k['work_hour'] > 0){
|
|
|
+ $workHour = $k['work_hour'];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $row[] = $workHour;
|
|
|
+ }
|
|
|
+ $kqData[] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建导出表头
|
|
|
+ $header = [];
|
|
|
+ // 第一行: 年月
|
|
|
+ $header[] = ["$year-$mon"];
|
|
|
+ // 第二行: 日期
|
|
|
+ $header[] = array_merge(['日期',''],$dates);
|
|
|
+ // 第三行: 星期
|
|
|
+ $header[] = array_merge(['星期',''],$weekdays);
|
|
|
+ $header[] = ['工号','姓名'];
|
|
|
+//dd($header);
|
|
|
+ return $this->saveExportData($kqData, $header,'kq2');
|
|
|
+ }
|
|
|
+
|
|
|
public function saveExportData($data, $headers, $type = 'default',$file_name = ''){
|
|
|
if(empty($file_name)) $file_name = self::$filename . "_". date("Y-m-d") . "_". rand(1000,9999);
|
|
|
$filename = $file_name . '.' . 'xlsx';
|