From 005469e69914216ec2c6a2fbf8c10ec5c31843a1 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Tue, 13 Jan 2026 15:33:38 +0800 Subject: [PATCH] update --- .../Controllers/Admin/OtherController.php | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index ec7ad64..c1a57d5 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -292,8 +292,10 @@ class OtherController extends CommonController // 3. 总计 = 现在课程去重人数 + 历史课程去重人数 $config->course_signs_unique_total = $nowCourseSignsUniqueTotal + $historyCourseSignsUniqueTotal; - // 去重总计 - $config->course_signs_unique_total = Course::where('type', $courseType->id) + + // 计算总期数统计 + // 1. 现在课程的总期数(所有课程类型,在配置的日期范围内) + $nowCoursePeriodsTotal = Course::whereIn('type', $allCourseTypes->pluck('id')) ->where('is_chart', 1) ->where(function ($query) use ($configStartDate, $configEndDate) { // 开始结束日期的筛选。or查询 @@ -301,7 +303,29 @@ class OtherController extends CommonController $query->whereBetween('start_date', [$configStartDate, $configEndDate]) ->orWhereBetween('end_date', [$configStartDate, $configEndDate]); } - })->count(); + }) + ->count(); + + // 2. 历史课程的总期数(在配置的日期范围内,针对所有课程类型) + $historyCoursePeriodsTotal = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseTypeNames) { + // 使用名称匹配所有课程类型(与循环中的逻辑保持一致) + $query->where(function ($q) use ($courseTypeNames) { + foreach ($courseTypeNames as $name) { + $q->orWhere('name', 'like', '%' . $name . '%'); + } + }); + }) + ->where(function ($query) use ($configStartDate, $configEndDate) { + // 开始结束日期的筛选。or查询 + if ($configStartDate && $configEndDate) { + $query->whereBetween('start_time', [$configStartDate, $configEndDate]) + ->orWhereBetween('end_time', [$configStartDate, $configEndDate]); + } + }) + ->count(); + + // 3. 总期数 = 现在课程期数 + 历史课程期数 + $config->course_periods_total = $nowCoursePeriodsTotal + $historyCoursePeriodsTotal; } return $this->success(compact('list', 'suzhou', 'country', 'monthCourses', 'time_axis', 'article', 'yearConfigs'));