master
cody 3 months ago
parent d903e9aeef
commit a01fccfbcd

@ -217,7 +217,7 @@ class OtherController extends CommonController
foreach ($yearConfigs as $config) { foreach ($yearConfigs as $config) {
// 根据配置获取日期范围 // 根据配置获取日期范围
$configStartDate = $config->start_date; $configStartDate = $config->start_date;
$configEndDate = $config->end_date ? $config->end_date : date('Y-m-d'); $configEndDate = $config->end_date ? $config->end_date : date('Y-m-d', strtotime('+10 year'));
// 复制 CourseType 集合(避免引用问题) // 复制 CourseType 集合(避免引用问题)
$courseTypes = $allCourseTypes->map(function ($item) { $courseTypes = $allCourseTypes->map(function ($item) {
@ -226,16 +226,27 @@ class OtherController extends CommonController
// 对每个 CourseType 进行统计 // 对每个 CourseType 进行统计
foreach ($courseTypes as $courseType) { foreach ($courseTypes as $courseType) {
// 历史已开设期数 // 历史已开设期数(添加时间范围限制)
$historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) { $historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) {
$query->where('name', 'like', '%' . $courseType->name . '%'); $query->where('name', 'like', '%' . $courseType->name . '%');
})->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_time', [$configStartDate, $configEndDate])
->orWhereBetween('end_time', [$configStartDate, $configEndDate]);
})->get(); })->get();
// 课程 // 课程(添加时间范围限制)
$courses = Course::where('type', $courseType->id)->where('is_chart', 1)->get(); $courses = Course::where('type', $courseType->id)->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
})->get();
// 历史课程期数 // 历史课程期数
$courseType->history_course_periods_total = $historyCourse->count(); $courseType->history_course_periods_total = $historyCourse->count();
// 现在课程期数 // 现在课程期数(添加时间范围限制)
$courseType->now_course_periods_total = Course::where('type', $courseType->id)->where('is_chart', 1)->count(); $courseType->now_course_periods_total = Course::where('type', $courseType->id)->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
})->count();
// 历史课程培养人数去重 // 历史课程培养人数去重
$courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique'); $courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique');
@ -253,7 +264,12 @@ class OtherController extends CommonController
// 总期数 // 总期数
$config->course_periods_total = $courseTypes->sum('course_periods_total'); $config->course_periods_total = $courseTypes->sum('course_periods_total');
// 总去重人数 // 总去重人数
$coursesAll = Course::whereIn('type', $allCourseTypes->pluck('id'))->where('is_chart', 1)->get(); $coursesAll = Course::whereIn('type', $allCourseTypes->pluck('id'))
->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
})->get();
$config->course_signs_unique_total = $courseTypes->sum('history_course_signs_total') + CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $coursesAll->pluck('id'), false, false); $config->course_signs_unique_total = $courseTypes->sum('history_course_signs_total') + CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $coursesAll->pluck('id'), false, false);
} }

Loading…
Cancel
Save