master
cody 3 months ago
parent 102bec9bad
commit 6a519aa145

@ -205,9 +205,10 @@ class OtherController extends CommonController
->orderBy('sort', 'asc')
->get();
// 2. 查询对应的 CourseType(含 is_chart=1 的 is_history=0 与 is_history=1与 courses-home 口径一致)
// 2. 查询对应的 CourseType
$allCourseTypes = CourseType::where('is_chart', 1)
->orderBy('sort', 'asc')
->where('is_history', 0)
->get();
// 3. 循环所有配置,对每个配置进行统计
@ -221,34 +222,34 @@ class OtherController extends CommonController
return clone $item;
});
// 对每个 CourseType 进行统计(与 courses-home 口径一致)
// 对每个 CourseType 进行统计
foreach ($courseTypes as $courseType) {
// 实际课程数据(与 courses-home 一致)
// 历史课程数据(添加时间范围限制)
$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)
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_date', [$configStartDate, $configEndDate])
->orWhereBetween('end_date', [$configStartDate, $configEndDate]);
})->get();
// 历史课程:仅 is_history=1 类型统计,且与 courses-home 一致type=id + calendar.is_count_people=1
if (($courseType->is_history ?? 0) == 1) {
$historyCourse = HistoryCourse::where('type', $courseType->id)
->whereHas('calendar', function ($query) {
$query->where('is_count_people', 1);
})
->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_time', [$configStartDate, $configEndDate])
->orWhereBetween('end_time', [$configStartDate, $configEndDate]);
})->get();
} else {
$historyCourse = collect();
}
// 历史课程期数
$courseType->history_course_periods_total = $historyCourse->count();
// 现在课程期数(添加时间范围限制)
$courseType->now_course_periods_total = $courses->count();
// 历史课程培养人数去重
$courseType->history_course_signs_total = $historyCourse->sum('course_type_signs_pass_unique');
// 现在课程培养人数(使用配置的日期范围)
$courseType->now_course_signs_total = CourseSign::courseSignsTotalByUnique($configStartDate, $configEndDate, 1, $courses->pluck('id'), false, false);
// 已开设期数
$courseType->course_periods_total = $courseType->now_course_periods_total + $courseType->history_course_periods_total;
// 培养人数去重
$courseType->course_signs_total = $courseType->history_course_signs_total + $courseType->now_course_signs_total;
}

@ -52,11 +52,8 @@ class CourseType extends SoftDeletesModel
return $otherCourseType;
}
// 历史课程数据(所有 is_chart=0 的课程类型,与 courses-home 一致calendar.is_count_people=1
// 历史课程数据(所有 is_chart=0 的课程类型)
$otherHistoryCourse = HistoryCourse::whereIn('type', $otherCourseTypeIds)
->whereHas('calendar', function ($query) {
$query->where('is_count_people', 1);
})
->where(function ($query) use ($startDate, $endDate) {
$query->whereBetween('start_time', [$startDate, $endDate])
->orWhereBetween('end_time', [$startDate, $endDate]);

Loading…
Cancel
Save