From 5c6b331a1c1341591b780d1e5ce931df6e6c19a0 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Thu, 9 Apr 2026 14:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A9=BE=E9=A9=B6=E8=88=B1=20=E8=AF=BE?= =?UTF-8?q?=E7=A8=8B=E4=BD=93=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/OtherController.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 23b6186..8cdeb09 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -264,22 +264,25 @@ class OtherController extends CommonController if ($children && $children->count() > 0) { $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 口径一致」块统计,避免重复) // 口径升级:history_courses.type 存的是课程体系ID字符串,直接按 includedTypeIds 归集(避免名称匹配漂移) $historyCourse = HistoryCourse::whereIn('type', $includedTypeIds) - ->whereHas('typeDetail', function ($query) { - $query->where('is_history', 0); - })->where(function ($query) use ($configStartDate, $configEndDate) { - $query->whereBetween('start_time', [$configStartDate, $configEndDate]) - ->orWhereBetween('end_time', [$configStartDate, $configEndDate]); - })->get(); + ->where(function ($query) use ($configStartDate, $configEndDate) { + // 采用“区间相交”口径,避免漏掉跨越整个区间的课程 + $query->where('start_time', '<=', $configEndDate) + ->where('end_time', '>=', $configStartDate); + })->get(); // 实际课程数据(添加时间范围限制) $courses = Course::whereIn('type', $includedTypeIds)->where('is_chart', 1) ->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(); $configCourseIds = $configCourseIds->merge($courses->pluck('id')); // 历史课程期数