diff --git a/app/Exports/CommonExport.php b/app/Exports/CommonExport.php index 8b1f56b..c4b1a5c 100755 --- a/app/Exports/CommonExport.php +++ b/app/Exports/CommonExport.php @@ -130,6 +130,9 @@ class CommonExport implements FromCollection, WithStyles, WithColumnWidths, With $widths[$letter] = 18; } elseif (str_contains($field, 'partners')) { $widths[$letter] = 50; + } elseif (str_contains($field, 'history_courses')) { + // 历史课程信息通常较长,适当放宽列宽 + $widths[$letter] = 40; } elseif (str_contains($field, 'all_course')) { $widths[$letter] = 40; } elseif (str_contains($field, 'company_name') || str_contains($field, 'address')) { @@ -361,6 +364,9 @@ class CommonExport implements FromCollection, WithStyles, WithColumnWidths, With $temp[$field] = $this->allCourse($info); } elseif (str_contains($field, 'partners')) { $temp[$field] = $this->partners($info); + } elseif (str_contains($field, 'history_courses')) { + // 历史课程信息字段,格式化为多行文本 + $temp[$field] = $this->historyCourses($info); } else { $temp[$field] = $this->getDotValue($info, $field); } @@ -495,6 +501,9 @@ class CommonExport implements FromCollection, WithStyles, WithColumnWidths, With $row[] = $this->allCourse($info); } elseif (str_contains($field, 'partners')) { $row[] = $this->partners($info); + } elseif (str_contains($field, 'history_courses')) { + // 历史课程信息字段,格式化为多行文本 + $row[] = $this->historyCourses($info); } else { $row[] = $this->getDotValue($info, $field); } @@ -542,6 +551,47 @@ class CommonExport implements FromCollection, WithStyles, WithColumnWidths, With return implode("、\r\n", $list); } + /** + * 获取所有历史课程信息(用于日历导出) + * @param $data + * @return string + */ + function historyCourses($data) + { + if (empty($data['history_courses']) || !is_array($data['history_courses'])) { + return ''; + } + + $list = []; + foreach ($data['history_courses'] as $item) { + $courseName = $item['course_name'] ?? ''; + $type = $item['type'] ?? ''; + $pass = $item['course_type_signs_pass'] ?? 0; + $passUnique = $item['course_type_signs_pass_unique'] ?? 0; + $signPass = $item['course_signs_pass'] ?? 0; + $start = $item['start_time'] ?? ''; + $end = $item['end_time'] ?? ''; + + // 构造单行描述:课程名称[体系ID](开始~结束) 培养人数/去重/课程人数 + $parts = []; + if ($courseName !== '') { + $parts[] = $courseName; + } + if ($type !== '') { + $parts[] = "[类型:{$type}]"; + } + if ($start !== '' || $end !== '') { + $parts[] = "({$start}~{$end})"; + } + $parts[] = "培养:{$pass}/去重:{$passUnique}/课程:{$signPass}"; + + $list[] = implode(' ', $parts); + } + + // 每门历史课程占一行 + return implode("\r\n", $list); + } + /** * 获取所有股东信息 * @param $data