diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 44dc670..dd9ac61 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -217,7 +217,7 @@ class OtherController extends CommonController foreach ($yearConfigs as $config) { // 根据配置获取日期范围 $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 集合(避免引用问题) $courseTypes = $allCourseTypes->map(function ($item) { @@ -226,16 +226,27 @@ class OtherController extends CommonController // 对每个 CourseType 进行统计 foreach ($courseTypes as $courseType) { - // 历史已开设期数 + // 历史已开设期数(添加时间范围限制) $historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) { $query->where('name', 'like', '%' . $courseType->name . '%'); + })->where(function ($query) use ($configStartDate, $configEndDate) { + $query->whereBetween('start_time', [$configStartDate, $configEndDate]) + ->orWhereBetween('end_time', [$configStartDate, $configEndDate]); })->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->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'); @@ -253,7 +264,12 @@ class OtherController extends CommonController // 总期数 $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); }