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 diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index ba42a4d..03e75e2 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -127,7 +127,7 @@ class OtherController extends CommonController // 今年新增校友数 $list['schoolmate_year'] = User::where('is_schoolmate', 1)->where('created_at', 'like', '%' . date('Y') . '%')->count(); // 投后企业 - $list['company_invested_total'] = CourseSign::yhInvested(); + $list['company_invested_total'] = CourseSign::yhInvestedTotal(CourseType::START_DATE, date('Y-m-d'), null); // 元和员工参与人数 $list['company_join_total'] = CourseSign::companyJoin(); // 全市干部参与企业 @@ -142,20 +142,31 @@ class OtherController extends CommonController $list['cover_stock_total'] = CourseSign::shangshi(); // 本月课程 $monthCourses = Calendar::with('course.teacher') - ->where('date', 'like', '%' . date('Y-m') . '%') + ->where('start_time', 'like', '%' . date('Y-m') . '%') ->get(); // 课程统计 - $courseTypes = CourseType::where('is_chart', 1)->get(); + $courseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->get(); $start_date = CourseType::START_DATE; $end_date = date('Y-m-d'); foreach ($courseTypes as $courseType) { + // 历史已开设期数 + $historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) { + $query->where('name', 'like', '%' . $courseType->name . '%'); + })->get(); + // 历史课程期数 + $courseType->history_course_periods_total = $historyCourse->count(); + // 历史课程培养人数去重 + $courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique'); + // 课程 $courses = Course::where('type', $courseType->id)->get(); // 已开设期数 - $courseType->course_periods_total = Course::where('type', $courseType->id)->count(); + $courseType->course_periods_total = Course::where('type', $courseType->id)->count() + $courseType->history_course_periods_total; // 培养人数去重 - $courseType->course_signs_total = CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null); + $courseType->course_signs_total = $courseType->history_course_signs_total + CourseSign::courseSignsTotalByUnique($start_date, $end_date, 1, $courses->pluck('id'), null); } + + // 苏州区域数据 $suzhouArea = Company::where('company_city', '苏州市')->groupBy('company_area') ->whereNotNull('company_area') @@ -340,10 +351,10 @@ class OtherController extends CommonController $courseTypesSum[] = [ 'course_type' => $historyCourse->name, 'course_name' => $course->course_name, - // 培养人数 - 'course_type_signs_pass' => $course->course_type_signs_pass, - // 去重培养人数 - 'course_type_signs_pass_unique' => $course->course_type_signs_pass_unique, + // 课程类型培养人数 + 'course_type_signs_pass' => $courses3->sum('course_type_signs_pass'), + // 课程类型去重培养人数 + 'course_type_signs_pass_unique' => $courses3->sum('course_type_signs_pass_unique'), // 课程人数 'course_signs_pass' => $course->course_signs_pass, // 跟班学员数量 diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index 2683f4f..607ad6a 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -176,7 +176,7 @@ class CourseSign extends SoftDeletesModel * @param array|null $course_ids 课程ID(仅在自定义时间时生效) * @param bool $retList 是否返回列表 */ - public static function yhInvestedTotal($start_date = null, $end_date = null, $course_ids, $retList = false) + public static function yhInvestedTotal($start_date = null, $end_date = null, $course_ids = null, $retList = false) { // 默认时间:获取所有学员,不限制课程 $userIds = self::getStudentList($start_date, $end_date, 1, $course_ids)->get()->pluck('user_id');