master
cody 3 months ago
parent 005469e699
commit 4deab855fd

@ -201,7 +201,7 @@ class OtherController extends CommonController
$article['yejie'] = Article::where('type', 2)->limit(7)->orderBy('sort', 'desc')->get();
$article['supply_demands'] = SupplyDemand::limit(7)->orderBy('created_at', 'desc')->get();
// 课程体系统计
// 课程体系筛选
// 1. 从配置表读取配置列表
$yearConfigs = CourseTypeDataOverviewConfig::where('status', true)
->orderBy('sort', 'asc')
@ -224,33 +224,18 @@ class OtherController extends CommonController
return clone $item;
});
// 收集所有课程类型的课程ID用于计算去重总计
$allCourseIds = collect();
// 对每个 CourseType 进行统计
foreach ($courseTypes as $courseType) {
// 历史已开设期数
$historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) {
$query->where('name', 'like', '%' . $courseType->name . '%');
})->get();
// 课程(使用配置的日期范围)
$courses = Course::where('type', $courseType->id)
->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
// 开始结束日期的筛选。or查询
if ($configStartDate && $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
}
})
->get();
// 收集课程ID
$allCourseIds = $allCourseIds->merge($courses->pluck('id'));
// 课程
$courses = Course::where('type', $courseType->id)->where('is_chart', 1)->get();
// 历史课程期数
$courseType->history_course_periods_total = $historyCourse->count();
// 现在课程数据(使用配置的日期范围)
$courseType->now_course_periods_total = $courses->count();
// 现在课程期数
$courseType->now_course_periods_total = Course::where('type', $courseType->id)->where('is_chart', 1)->count();
// 历史课程培养人数去重
$courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique');
@ -265,67 +250,11 @@ class OtherController extends CommonController
// 将统计数据直接组合到配置对象中
$config->courseTypes = $courseTypes;
// 计算去重总计数量
// 1. 现在课程的去重学员数(所有课程类型,在配置的日期范围内)
$nowCourseSignsUniqueTotal = CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $allCourseIds->unique(), false, false);
// 2. 历史课程的去重学员数(在配置的日期范围内,针对所有课程类型)
// 收集所有课程类型的名称,用于匹配历史课程
$courseTypeNames = $allCourseTypes->pluck('name');
$historyCourseSignsUniqueTotal = 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]);
}
})
->sum('course_type_signs_pass_unique');
// 3. 总计 = 现在课程去重人数 + 历史课程去重人数
$config->course_signs_unique_total = $nowCourseSignsUniqueTotal + $historyCourseSignsUniqueTotal;
// 计算总期数统计
// 1. 现在课程的总期数(所有课程类型,在配置的日期范围内)
$nowCoursePeriodsTotal = Course::whereIn('type', $allCourseTypes->pluck('id'))
->where('is_chart', 1)
->where(function ($query) use ($configStartDate, $configEndDate) {
// 开始结束日期的筛选。or查询
if ($configStartDate && $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
}
})
->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;
// 总期数
$config->course_periods_total = $courseType->sum('course_periods_total');
// 总去重人数
$coursesAll = Course::whereIn('type', $allCourseTypes->pluck('id'))->where('is_chart', 1)->get();
$config->course_signs_unique_total = $courseType->sum('history_course_signs_total') + CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $coursesAll->pluck('id'), false, false);
}
return $this->success(compact('list', 'suzhou', 'country', 'monthCourses', 'time_axis', 'article', 'yearConfigs'));

Loading…
Cancel
Save