From 2e41c9afb3b9dab135d3465bd3713c34fc6ba31a Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Fri, 28 Nov 2025 19:02:10 +0800 Subject: [PATCH] update --- .../Controllers/Admin/OtherController.php | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index c8f96a8..e6c65cc 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -233,27 +233,17 @@ class OtherController extends CommonController $calendar = Calendar::where(function ($query) use ($start_date, $end_date) { $query->whereBetween('start_time', [$start_date, $end_date]) ->orWhereBetween('end_time', [$start_date, $end_date]); - })->where(function ($query) use ($course_type_id) { + })->where(function ($query) use ($course_type_id, $courses) { // 条件1:有 course_id 的数据,通过 course.type 匹配课程体系 // 条件2:没有 course_id 的数据,直接用 course_type_id 字段匹配 // 两个条件是或关系 - + if (request('course_type_id')) { + $query->whereIn('course_id', $courses->pluck('id')); + } if ($course_type_id) { - $course_type_id_array = is_array($course_type_id) ? $course_type_id : explode(',', $course_type_id); - - // 条件1:有 course_id 时,通过关联的 course.type 匹配 - $query->where(function ($q) use ($course_type_id_array) { - $q->whereNotNull('course_id') - ->whereHas('course', function ($subQ) use ($course_type_id_array) { - $subQ->whereIn('type', $course_type_id_array); - }); - }); - - // 条件2:没有 course_id 时,直接用 course_type_id 字段匹配(或关系) - $query->orWhere(function ($q) use ($course_type_id_array) { - $q->whereNull('course_id')->whereIn('course_type_id', $course_type_id_array); - }); + $query->orWhere('course_type_id', $course_type_id); } + })->get(); $list['course_total'] = (clone $calendar)->count();