驾驶舱 课程体系

master
lion 2 weeks ago
parent b73e314ef0
commit 5c6b331a1c

@ -264,22 +264,25 @@ class OtherController extends CommonController
if ($children && $children->count() > 0) { if ($children && $children->count() > 0) {
$includedTypeIds = $includedTypeIds->merge($children->pluck('id')); $includedTypeIds = $includedTypeIds->merge($children->pluck('id'));
} }
$includedTypeIds = $includedTypeIds->unique()->values(); // history_courses.type 是字符串,统一按字符串比对更稳定
$includedTypeIds = $includedTypeIds->unique()->values()->map(function ($id) {
return (string)$id;
});
// 历史课程数据(添加时间范围限制;仅统计 type 为 is_history=0 的is_history=1 的由下方「与 courses-home 口径一致」块统计,避免重复) // 历史课程数据(添加时间范围限制;仅统计 type 为 is_history=0 的is_history=1 的由下方「与 courses-home 口径一致」块统计,避免重复)
// 口径升级history_courses.type 存的是课程体系ID字符串直接按 includedTypeIds 归集(避免名称匹配漂移) // 口径升级history_courses.type 存的是课程体系ID字符串直接按 includedTypeIds 归集(避免名称匹配漂移)
$historyCourse = HistoryCourse::whereIn('type', $includedTypeIds) $historyCourse = HistoryCourse::whereIn('type', $includedTypeIds)
->whereHas('typeDetail', function ($query) { ->where(function ($query) use ($configStartDate, $configEndDate) {
$query->where('is_history', 0); // 采用“区间相交”口径,避免漏掉跨越整个区间的课程
})->where(function ($query) use ($configStartDate, $configEndDate) { $query->where('start_time', '<=', $configEndDate)
$query->whereBetween('start_time', [$configStartDate, $configEndDate]) ->where('end_time', '>=', $configStartDate);
->orWhereBetween('end_time', [$configStartDate, $configEndDate]); })->get();
})->get();
// 实际课程数据(添加时间范围限制) // 实际课程数据(添加时间范围限制)
$courses = Course::whereIn('type', $includedTypeIds)->where('is_chart', 1) $courses = Course::whereIn('type', $includedTypeIds)->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) { ->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate]) // 采用“区间相交”口径,避免漏掉跨越整个区间的课程
->orWhereBetween('end_date', [$configStartDate, $configEndDate]); $query->where('start_date', '<=', $configEndDate)
->where('end_date', '>=', $configStartDate);
})->get(); })->get();
$configCourseIds = $configCourseIds->merge($courses->pluck('id')); $configCourseIds = $configCourseIds->merge($courses->pluck('id'));
// 历史课程期数 // 历史课程期数

Loading…
Cancel
Save