master
cody 3 months ago
parent 79ee7973be
commit c7848e99b9

@ -3,231 +3,294 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Models\Course; use App\Models\Course;
use App\Models\CourseSign;
use App\Models\CourseType; use App\Models\CourseType;
use App\Models\CourseTypeDataOverviewConfig; use App\Models\CourseTypeDataOverviewConfig;
use App\Models\HistoryCourse; use App\Models\HistoryCourse;
use App\Models\CourseSign;
use Illuminate\Console\Command; use Illuminate\Console\Command;
/** /**
* 比 home-v2 的 yearConfigs 与 courses-home 的 courseTypesSum * 比 home-v2 的 yearConfigs 与 courses-home 的 courseTypesSum
* 在 2024-01-01 2027-01-01 时间段内,找出课程数量、去重培养人数差异的原因 * 在指定时间段内 期数、课程数量、去重培养人数 的差异,并输出导致差异的 Course / HistoryCourse 明细。
*/ */
class DiffHomeV2CoursesHome extends Command class DiffHomeV2CoursesHome extends Command
{ {
protected $signature = 'diff:home-v2-courses-home {--start=2024-01-01} {--end=2027-01-01}'; protected $signature = 'diff:home-v2-courses-home
protected $description = '对比 home-v2 yearConfigs 与 courses-home courseTypesSum 在指定时间段内的期数、去重培养人数差异'; {--start=2024-01-01 : 开始日期}
{--end=2027-01-01 : 结束日期}
public function handle() {--config-id= : 可选,仅用该 yearConfig 的日期;不传则用 start/end}';
{
$start = $this->option('start');
$end = $this->option('end');
$this->info("=== 对比时间段: {$start} {$end} ===\n");
// 1. 找到覆盖该时间段的 yearConfig或使用该时间段模拟
$config = CourseTypeDataOverviewConfig::where('status', true)
->where('start_date', '<=', $start)
->where(function ($q) use ($end) {
$q->where('end_date', '>=', $end)->orWhereNull('end_date');
})
->orderBy('sort')
->first();
if (!$config) {
$config = CourseTypeDataOverviewConfig::where('status', true)
->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end])
->orderBy('sort')
->first();
}
$configStart = $config ? $config->start_date : $start; protected $description = '比对 home-v2(yearConfigs) 与 courses-home(courseTypesSum) 的期数、课程数量、去重培养人数差异';
$configEnd = $config && $config->end_date ? $config->end_date : $end;
$this->info("yearConfig: " . ($config ? "id={$config->id} [{$configStart} {$configEnd}]" : "无覆盖配置,使用 {$configStart} {$configEnd}"));
// 2. 按 home-v2 逻辑统计(仅用 2024-01-012027-01-01 做筛选,与 config 自身范围不一致时以 2024-2027 为准则需单独算) protected $startDate;
// 为与 courses-home 可比,我们在这里用 startend 作为统一日期范围 protected $endDate;
$homeV2 = $this->computeHomeV2Style($start, $end);
$this->info("\n【home-v2 逻辑】期数: {$homeV2['course_periods_total']}, 去重培养人数: {$homeV2['course_signs_unique_total']}");
// 3. 按 courses-home 逻辑统计 public function handle()
$coursesHome = $this->computeCoursesHomeStyle($start, $end); {
$this->info("【courses-home 逻辑】课程数量(行数): {$coursesHome['course_count']}, 去重培养人数: {$coursesHome['course_signs_unique_total']}"); $this->startDate = $this->option('start');
$this->endDate = $this->option('end');
$configId = $this->option('config-id');
// 4. 差异 if ($configId) {
$diffCount = $coursesHome['course_count'] - $homeV2['course_periods_total']; $config = CourseTypeDataOverviewConfig::where('status', true)->find($configId);
$this->info("\n--- 差异: 课程数量 courses-home 多 " . $diffCount . " ---"); if (!$config) {
$this->error("未找到 status=1 的 config id={$configId}");
return 1;
}
$this->startDate = $config->start_date;
$this->endDate = $config->end_date ?: date('Y-m-d', strtotime('+10 year'));
$this->info("使用 config#{$configId} 的日期: {$this->startDate} ~ {$this->endDate}");
} else {
$this->info("使用参数日期: {$this->startDate} ~ {$this->endDate}");
}
// 5. 定位多出来的课程来源 // 1) home-v2 逻辑:按 yearConfigs 的统计方式(只取 is_chart=1 & is_history=0 的 CourseType + 其他)
$this->findExtraSources($start, $end, $homeV2, $coursesHome); $homeV2 = $this->computeHomeV2($this->startDate, $this->endDate);
// 2) courses-home 逻辑courseTypesSum 的课程数量、以及涉及的 Course / HistoryCourse
$coursesHome = $this->computeCoursesHome($this->startDate, $this->endDate);
$this->printComparison($homeV2, $coursesHome);
$this->printDetailDiff($homeV2, $coursesHome);
return 0; return 0;
} }
/** /**
* home-v2 风格is_chart=1 且 is_history=0 的 CourseType + 按 name like 的 HistoryCourse + 其他 * home-v2 的 yearConfigs 统计(单一段 startend
* 返回:期数、去重人数、涉及的 course_ids、history_course_ids
*/ */
protected function computeHomeV2Style(string $start, string $end): array protected function computeHomeV2(string $start, string $end): array
{ {
$allCourseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->orderBy('sort')->get(); $courseIds = [];
$coursePeriodsTotal = 0; $historyIds = [];
$courseSignsUniqueTotal = 0; $periodsTotal = 0;
$signsUniqueSum = 0;
$dateFilter = function ($q) use ($start, $end) { $allCourseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->orderBy('sort')->get();
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]);
};
$historyDateFilter = function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]);
};
foreach ($allCourseTypes as $ct) { foreach ($allCourseTypes as $ct) {
$historyCourse = HistoryCourse::whereHas('typeDetail', fn($q) => $q->where('name', 'like', '%' . $ct->name . '%')) // 历史typeDetail name like且仅 type 为 is_history=0is_history=1 的由下方与 courses-home 口径一致的块统计)
->where($historyDateFilter)->get(); $history = HistoryCourse::whereHas('typeDetail', function ($q) use ($ct) {
$courses = Course::where('type', $ct->id)->where('is_chart', 1)->where($dateFilter)->get(); $q->where('name', 'like', '%' . $ct->name . '%')->where('is_history', 0);
})->where(function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])
->orWhereBetween('end_time', [$start, $end]);
})->get();
foreach ($history as $h) {
$historyIds[] = $h->id;
}
$historyPeriods = $history->count();
// 现在Course type=$ct->id, is_chart=1
$courses = Course::where('type', $ct->id)->where('is_chart', 1)
->where(function ($q) use ($start, $end) {
$q->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end]);
})->get();
foreach ($courses as $c) {
$courseIds[] = $c->id;
}
$nowPeriods = $courses->count();
$coursePeriodsTotal += $historyCourse->count() + $courses->count(); $periodsTotal += $historyPeriods + $nowPeriods;
$courseSignsUniqueTotal += $historyCourse->sum('course_type_signs_pass_unique') $signsUniqueSum += $history->sum('course_type_signs_pass_unique')
+ (int)CourseSign::courseSignsTotalByUnique($start, $end, 1, $courses->pluck('id'), false, false); + CourseSign::courseSignsTotalByUnique($start, $end, 1, $courses->pluck('id'), false, false);
} }
$other = CourseType::getOtherStatistics($start, $end); // 其他 is_chart=0
$coursePeriodsTotal += $other->course_periods_total; $other = CourseType::getOtherStatistics($start, $end);
$courseSignsUniqueTotal += $other->course_signs_total; $oIds = CourseType::getOtherCourseIds($start, $end);
$otherH = HistoryCourse::whereIn('type', CourseType::where('is_chart', 0)->where('is_history', 0)->pluck('id'))
->where(function ($q) use ($start, $end) {
$q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]);
})->get();
foreach ($otherH as $h) {
$historyIds[] = $h->id;
}
foreach (Course::whereIn('id', $oIds)->get() as $c) {
$courseIds[] = $c->id;
}
$periodsTotal += $other->course_periods_total;
$signsUniqueSum += $other->course_signs_total;
// getOtherStatistics 内部已含 history此处仅补 course idsgetOtherCourseIds 与 getOtherStatistics 的 Course 条件一致)
return ['course_periods_total' => $coursePeriodsTotal, 'course_signs_unique_total' => $courseSignsUniqueTotal]; // 与 courses-home 口径一致:附加 is_history=1 的 HistoryCoursewhereHas calendar is_count_people=1type=体系 id
$courseTypesHistory = CourseType::where('is_history', 1)->get();
foreach ($courseTypesHistory as $hc) {
$historyList = HistoryCourse::whereHas('calendar', fn ($q) => $q->where('is_count_people', 1))
->where(fn ($q) => $q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]))
->where('type', $hc->id)
->get();
foreach ($historyList as $h) {
$historyIds[] = $h->id;
}
$periodsTotal += $historyList->count();
$signsUniqueSum += $historyList->sum('course_type_signs_pass_unique');
}
return [
'periods_total' => $periodsTotal,
'signs_unique_sum' => $signsUniqueSum,
'course_ids' => array_values(array_unique($courseIds)),
'history_ids' => array_values(array_unique($historyIds)),
];
} }
/** /**
* courses-home 风格:全部 CourseType含 is_history=1的 Course(is_chart=1) + is_history=1 的 HistoryCourse(calendar.is_count_people=1) * courses-home 的 courseTypesSum按行展开的课程数量、去重按类型聚合的那列会重复这里只算 课程数量/期数)
* 返回:课程数量(行数)、涉及的 course_ids、history_course_ids
*/ */
protected function computeCoursesHomeStyle(string $start, string $end): array protected function computeCoursesHome(string $start, string $end): array
{ {
$course_type_id = CourseType::pluck('id')->toArray(); $courseIds = [];
$courseTypesSum = []; $historyIds = [];
$allCourseIdsForUnique = []; $courseTypes = CourseType::whereIn('id', CourseType::pluck('id')->toArray())->get();
$dateFilter = function ($q) use ($start, $end) {
if ($start && $end) {
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]);
}
};
// 第一循环:所有 CourseType含 is_history=1 // 第一段:非历史 CourseType 下的 Course
$courseTypes = CourseType::whereIn('id', $course_type_id)->get();
foreach ($courseTypes as $ct) { foreach ($courseTypes as $ct) {
$courses2 = Course::where('type', $ct->id)->where($dateFilter)->where('is_chart', 1)->orderBy('start_date')->get(); $courses2 = Course::where('type', $ct->id)
->where(function ($q) use ($start, $end) {
if ($start && $end) {
$q->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end]);
}
})
->where('is_chart', 1)
->orderBy('start_date')
->get();
foreach ($courses2 as $c) { foreach ($courses2 as $c) {
$courseTypesSum[] = ['source' => 'Course', 'course_type_id' => $ct->id, 'course_type_name' => $ct->name, 'is_history' => $ct->is_history ?? 0, 'course_id' => $c->id, 'course_name' => $c->name]; $courseIds[] = $c->id;
$allCourseIdsForUnique[] = $c->id;
} }
} }
// 第二循环is_history=1 的 HistoryCourse与 home-v2 一致:仅 typeDetail.name 能匹配某个 is_chart=1 且 is_history=0 的 name // 第二段is_history=1 的 HistoryCourse与 courses-home 一致whereHas calendar is_count_people=1
$chartHistoryTypeNames = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('name')->toArray(); $courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', CourseType::pluck('id')->toArray())->get();
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
$historySignsTotal = 0;
foreach ($courseTypesHistory as $hc) { foreach ($courseTypesHistory as $hc) {
$historyQ = HistoryCourse::whereHas('calendar', fn($q) => $q->where('is_count_people', 1)) $courses3 = HistoryCourse::whereHas('calendar', function ($q) {
->where(fn($q) => $q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end])) $q->where('is_count_people', 1);
->where('type', $hc->id); })
if (!empty($chartHistoryTypeNames)) { ->where(function ($q) use ($start, $end) {
$historyQ->whereHas('typeDetail', function ($query) use ($chartHistoryTypeNames) { $q->whereBetween('start_time', [$start, $end])
$query->where(function ($q2) use ($chartHistoryTypeNames) { ->orWhereBetween('end_time', [$start, $end]);
foreach ($chartHistoryTypeNames as $n) { })
$q2->orWhere('name', 'like', '%' . $n . '%'); ->where('type', $hc->id)
} ->get();
}); foreach ($courses3 as $h) {
}); $historyIds[] = $h->id;
} else {
$historyQ->whereHas('typeDetail', fn($query) => $query->whereRaw('1=0'));
}
$courses3 = $historyQ->get();
foreach ($courses3 as $c) {
$courseTypesSum[] = ['source' => 'HistoryCourse', 'course_type_id' => $hc->id, 'course_type_name' => $hc->name, 'is_history' => 1, 'history_course_id' => $c->id, 'course_name' => $c->course_name];
$historySignsTotal += (int)($c->course_type_signs_pass_unique ?? 0);
} }
} }
$courseSignsUniqueTotal = (int)CourseSign::courseSignsTotalByUnique($start, $end, 1, $allCourseIdsForUnique ?: [], false, false) + $historySignsTotal; // 期数 = courseTypesSum 行数:每个 Course 一行,每个 HistoryCourse 一行
$periodsTotal = count($courseIds) + count($historyIds);
// 去重人数:用与 home-v2 同口径的「所有在 courseTypesSum 里的 course_id + history 对应类型」来算较复杂,
// 这里仅用 courses-home 实际用到的 Course 的 id 做 courseSignsTotalByUnique历史用 sum(course_type_signs_pass_unique)
$allCids = array_values(array_unique($courseIds));
$signsFromCourse = $allCids
? (int) CourseSign::courseSignsTotalByUnique($start, $end, 1, $allCids, false, false)
: 0;
$signsFromHistory = 0;
foreach ($courseTypesHistory as $hc) {
$list = HistoryCourse::whereHas('calendar', fn($q) => $q->where('is_count_people', 1))
->where(fn($q) => $q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]))
->where('type', $hc->id)
->get();
$signsFromHistory += $list->sum('course_type_signs_pass_unique');
}
$signsUniqueSum = $signsFromCourse + $signsFromHistory;
return [ return [
'course_count' => count($courseTypesSum), 'periods_total' => $periodsTotal,
'course_signs_unique_total' => $courseSignsUniqueTotal, 'signs_unique_sum' => $signsUniqueSum,
'rows' => $courseTypesSum, 'course_ids' => array_values(array_unique($courseIds)),
'history_ids' => array_values(array_unique($historyIds)),
]; ];
} }
/** protected function printComparison(array $homeV2, array $coursesHome): void
* 找出 courses-home 多出来的课程来源
*/
protected function findExtraSources(string $start, string $end, array $homeV2, array $coursesHome): void
{ {
$allCourseTypes = CourseType::where('is_chart', 1)->where('is_history', 0)->pluck('id')->toArray(); $this->line('');
$historyDateFilter = function ($q) use ($start, $end) { $this->line('========== 汇总对比 ==========');
$q->whereBetween('start_time', [$start, $end])->orWhereBetween('end_time', [$start, $end]); $this->table(
}; ['指标', 'home-v2 (yearConfigs)', 'courses-home (courseTypesSum)', '差异 (courses-home - home-v2)'],
$dateFilter = function ($q) use ($start, $end) { [
$q->whereBetween('start_date', [$start, $end])->orWhereBetween('end_date', [$start, $end]); [
}; '期数/课程数量',
$homeV2['periods_total'],
// home-v2 会计入的1) Course: type in is_history=0, is_chart=1, 日期 2) HistoryCourse: typeDetail.name like (is_history=0 的 name), 日期 3) 其他 $coursesHome['periods_total'],
$homeV2CourseIds = []; $coursesHome['periods_total'] - $homeV2['periods_total'],
foreach (CourseType::where('is_chart', 1)->where('is_history', 0)->get() as $ct) { ],
$ids = Course::where('type', $ct->id)->where('is_chart', 1)->where($dateFilter)->pluck('id')->toArray(); [
$homeV2CourseIds = array_merge($homeV2CourseIds, $ids); '去重培养人数',
} $homeV2['signs_unique_sum'],
$otherCourseIds = Course::whereIn('type', CourseType::where('is_chart', 0)->where('is_history', 0)->pluck('id')) $coursesHome['signs_unique_sum'],
->where('is_chart', 1)->where($dateFilter)->pluck('id')->toArray(); $coursesHome['signs_unique_sum'] - $homeV2['signs_unique_sum'],
$homeV2CourseIds = array_unique(array_merge($homeV2CourseIds, $otherCourseIds)); ],
[
$homeV2HistoryIds = []; 'Course 数',
foreach (CourseType::where('is_chart', 1)->where('is_history', 0)->get() as $ct) { count($homeV2['course_ids']),
$ids = HistoryCourse::whereHas('typeDetail', fn($q) => $q->where('name', 'like', '%' . $ct->name . '%')) count($coursesHome['course_ids']),
->where($historyDateFilter)->pluck('id')->toArray(); count($coursesHome['course_ids']) - count($homeV2['course_ids']),
$homeV2HistoryIds = array_merge($homeV2HistoryIds, $ids); ],
[
'HistoryCourse 数',
count($homeV2['history_ids']),
count($coursesHome['history_ids']),
count($coursesHome['history_ids']) - count($homeV2['history_ids']),
],
]
);
}
protected function printDetailDiff(array $homeV2, array $coursesHome): void
{
$this->line('');
$this->line('========== 明细差异(导致 courses-home 多出 期数 的条目) ==========');
$h2C = array_flip($homeV2['course_ids']);
$chC = array_flip($coursesHome['course_ids']);
$onlyInChC = array_keys(array_diff_key($chC, $h2C));
$onlyInH2C = array_keys(array_diff_key($h2C, $chC));
$h2H = array_flip($homeV2['history_ids']);
$chH = array_flip($coursesHome['history_ids']);
$onlyInChH = array_keys(array_diff_key($chH, $h2H));
$onlyInH2H = array_keys(array_diff_key($h2H, $chH));
if (!empty($onlyInChC)) {
$this->line('【仅 courses-home 有的 Course会多算期数】');
$rows = Course::whereIn('id', $onlyInChC)->get(['id', 'name', 'type', 'start_date', 'end_date', 'is_chart']);
$this->table(
['id', 'name', 'type', 'start_date', 'end_date', 'is_chart'],
$rows->map(fn($r) => [$r->id, $r->name, $r->type, $r->start_date, $r->end_date, $r->is_chart])->toArray()
);
$ctIds = $rows->pluck('type')->unique();
$cts = CourseType::whereIn('id', $ctIds)->get(['id', 'name', 'is_chart', 'is_history']);
$this->line('对应 CourseType: ' . $cts->map(fn($t) => "id={$t->id} name={$t->name} is_chart={$t->is_chart} is_history={$t->is_history}")->implode('; '));
} }
$otherHistory = HistoryCourse::whereIn('type', CourseType::where('is_chart', 0)->where('is_history', 0)->pluck('id'))
->where($historyDateFilter)->pluck('id')->toArray(); if (!empty($onlyInChH)) {
$homeV2HistoryIds = array_unique(array_merge($homeV2HistoryIds, $otherHistory)); $this->line('【仅 courses-home 有的 HistoryCourse会多算期数】');
$rows = HistoryCourse::whereIn('id', $onlyInChH)->get(['id', 'course_name', 'type', 'start_time', 'end_time', 'calendar_id']);
// courses-home 多出的:在 rows 里但不在 home-v2 的 $this->table(
$extras = []; ['id', 'course_name', 'type', 'start_time', 'end_time', 'calendar_id'],
foreach ($coursesHome['rows'] as $r) { $rows->map(fn($r) => [$r->id, $r->course_name, $r->type, $r->start_time, $r->end_time, $r->calendar_id])->toArray()
if ($r['source'] === 'Course') { );
if (!in_array($r['course_id'], $homeV2CourseIds)) { $ctIds = $rows->pluck('type')->unique();
$extras[] = $r; $cts = CourseType::whereIn('id', $ctIds)->get(['id', 'name', 'is_chart', 'is_history']);
} $this->line('对应 CourseType: ' . $cts->map(fn($t) => "id={$t->id} name={$t->name} is_chart={$t->is_chart} is_history={$t->is_history}")->implode('; '));
} else {
if (!in_array($r['history_course_id'], $homeV2HistoryIds)) {
$extras[] = $r;
}
}
} }
$this->info("\n【多出的课程/期courses-home 有、home-v2 无)】共 " . count($extras) . " 条:"); if (!empty($onlyInH2C)) {
foreach ($extras as $e) { $this->line('【仅 home-v2 有的 Course】');
$this->line(sprintf( $this->line(implode(', ', $onlyInH2C));
" - %s | type_id=%s is_history=%s | %s | %s", }
$e['source'], if (!empty($onlyInH2H)) {
$e['course_type_id'], $this->line('【仅 home-v2 有的 HistoryCourse】');
$e['is_history'], $this->line(implode(', ', $onlyInH2H));
$e['course_name'] ?? '-',
isset($e['course_id']) ? "course_id={$e['course_id']}" : "history_id={$e['history_course_id']}"
));
} }
// 单独列出type 属于 is_history=1 的 Coursehome-v2 不统计此类) if (empty($onlyInChC) && empty($onlyInChH) && empty($onlyInH2C) && empty($onlyInH2H)) {
$isHistory1TypeIds = CourseType::where('is_history', 1)->pluck('id')->toArray(); $this->line('(无 ID 集合差异;若期数仍不一致,可能是同一条目在两个口径下 算/不算 的规则不同,例如 is_chart、is_count_people、日期区间、type 与 name 匹配等)');
$courseFromHistory1Type = Course::whereIn('type', $isHistory1TypeIds)
->where('is_chart', 1)
->where($dateFilter)
->get();
if ($courseFromHistory1Type->isNotEmpty()) {
$this->info("\n【属于 is_history=1 课程类型的 Coursehome-v2 不统计)】共 " . $courseFromHistory1Type->count() . " 条:");
foreach ($courseFromHistory1Type as $c) {
$ct = CourseType::find($c->type);
$this->line(" - course_id={$c->id} type={$c->type} ({$ct->name}) | {$c->name} | {$c->start_date}{$c->end_date}");
}
} }
} }
} }

@ -224,9 +224,9 @@ class OtherController extends CommonController
// 对每个 CourseType 进行统计 // 对每个 CourseType 进行统计
foreach ($courseTypes as $courseType) { foreach ($courseTypes as $courseType) {
// 历史课程数据(添加时间范围限制) // 历史课程数据(添加时间范围限制;仅统计 type 为 is_history=0 的is_history=1 的由下方「与 courses-home 口径一致」块统计,避免重复
$historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) { $historyCourse = HistoryCourse::whereHas('typeDetail', function ($query) use ($courseType) {
$query->where('name', 'like', '%' . $courseType->name . '%'); $query->where('name', 'like', '%' . $courseType->name . '%')->where('is_history', 0);
})->where(function ($query) use ($configStartDate, $configEndDate) { })->where(function ($query) use ($configStartDate, $configEndDate) {
$query->whereBetween('start_time', [$configStartDate, $configEndDate]) $query->whereBetween('start_time', [$configStartDate, $configEndDate])
->orWhereBetween('end_time', [$configStartDate, $configEndDate]); ->orWhereBetween('end_time', [$configStartDate, $configEndDate]);
@ -253,6 +253,24 @@ class OtherController extends CommonController
$courseType->course_signs_total = $courseType->history_course_signs_total + $courseType->now_course_signs_total; $courseType->course_signs_total = $courseType->history_course_signs_total + $courseType->now_course_signs_total;
} }
// 与 courses-home 口径一致:附加 is_history=1 的 HistoryCoursewhereHas calendar is_count_people=1type=体系 id日期在配置范围内
$courseTypesHistory = CourseType::where('is_history', 1)->get();
foreach ($courseTypesHistory as $hc) {
$historyList = HistoryCourse::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]);
})->where('type', $hc->id)->get();
$hc->history_course_periods_total = $historyList->count();
$hc->now_course_periods_total = 0;
$hc->history_course_signs_total = $historyList->sum('course_type_signs_pass_unique');
$hc->now_course_signs_total = 0;
$hc->course_periods_total = $hc->history_course_periods_total;
$hc->course_signs_total = $hc->history_course_signs_total;
$courseTypes->push(clone $hc);
}
// 统计 is_chart=0 的课程类型数据,组成"其他"统计项 // 统计 is_chart=0 的课程类型数据,组成"其他"统计项
$otherCourseType = CourseType::getOtherStatistics($configStartDate, $configEndDate); $otherCourseType = CourseType::getOtherStatistics($configStartDate, $configEndDate);
@ -377,7 +395,7 @@ class OtherController extends CommonController
]; ];
} }
} }
// 附加历史课程数据(与 course_signs_pass 口径一致:与 needHistory 的 HistoryCourse 条件一致calendar+日期+type in course_type_id // 附加历史课程数据(与 courses-home 口径一致:统计所有 is_history=1 的 HistoryCourse
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get(); $courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
foreach ($courseTypesHistory as $historyCourse) { foreach ($courseTypesHistory as $historyCourse) {
$courses3 = HistoryCourse::whereHas('calendar', function ($query) { $courses3 = HistoryCourse::whereHas('calendar', function ($query) {
@ -863,7 +881,7 @@ class OtherController extends CommonController
]; ];
} }
} }
// 附加历史课程数据(与 course_signs_pass 口径一致:与 needHistory 的 HistoryCourse 条件一致calendar+日期+type in course_type_id // 附加历史课程数据
$courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get(); $courseTypesHistory = CourseType::where('is_history', 1)->whereIn('id', $course_type_id)->get();
foreach ($courseTypesHistory as $historyCourse) { foreach ($courseTypesHistory as $historyCourse) {
$courses3 = HistoryCourse::whereHas('calendar', function ($query) { $courses3 = HistoryCourse::whereHas('calendar', function ($query) {
@ -2032,7 +2050,6 @@ class OtherController extends CommonController
'company_position' => $user->company_position ?? '', 'company_position' => $user->company_position ?? '',
'education' => $user->education ?? '', 'education' => $user->education ?? '',
'geren_rongyu' => $user->type ?? '', 'geren_rongyu' => $user->type ?? '',
'talent_tags' => $user->talent_tags ?? '',
'course_names' => $courseNamesStr, 'course_names' => $courseNamesStr,
'course_types' => $courseTypesStr, 'course_types' => $courseTypesStr,
'course_count' => $totalCourseCount, 'course_count' => $totalCourseCount,
@ -2047,7 +2064,6 @@ class OtherController extends CommonController
'company_position' => '职位', 'company_position' => '职位',
'education' => '学历', 'education' => '学历',
'geren_rongyu' => '个人荣誉', 'geren_rongyu' => '个人荣誉',
'talent_tags' => '人才标签',
'course_names' => '课程名称', 'course_names' => '课程名称',
'course_types' => '课程体系', 'course_types' => '课程体系',
'course_count' => '报名课程数', 'course_count' => '报名课程数',

Loading…
Cancel
Save