You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.3 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace App\Console\Commands;
use App\Models\Course;
use App\Models\CourseSign;
use App\Models\CourseType;
use App\Models\User;
use Illuminate\Console\Command;
/**
* 对比 study 接口(苏州+人才)的 list.total 与 courses-home 的 cover_rencai_total
* 在相同 start_date、end_date、is_chart、address=苏州、is_rencai=1 下应一致。
*/
class DiffStudyCoverRencai extends Command
{
protected $signature = 'diff:study-cover-rencai
{--start=2025-01-01 : 开始日期}
{--end=2025-12-31 : 结束日期}';
protected $description = '对比 study(苏州+人才) 的 list.total 与 courses-home 的 cover_rencai_total';
public function handle()
{
$start = $this->option('start');
$end = $this->option('end');
$course_type_id = CourseType::pluck('id')->toArray();
$courses = Course::whereIn('type', $course_type_id)->get();
$course_ids = $courses->pluck('id');
$rencaiCount = CourseSign::rencai($start, $end, $course_ids);
// 复现 study 的 User 数量address=苏州, is_rencai=1, courses_start/end, is_chart=1, status=1
// is_rencai 的「人才培训」已与 rencai 一致:仅在 2025、is_chart=1 的报名中认定
$studyCount = User::query()
->whereHas('courseSigns', function ($query) use ($start, $end) {
$query->where('status', 1)->whereHas('course', function ($q) use ($start, $end) {
$q->where('is_chart', 1)->where(function ($q2) use ($start, $end) {
$q2->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end]);
});
});
})
->whereHas('company', function ($c) {
$c->where('company_address', 'like', '%苏州%')
->orWhere('company_city', 'like', '%苏州%');
})
->where(function ($q) use ($start, $end) {
$q->whereHas('courseSigns', function ($cs) use ($start, $end) {
$cs->where('status', 1)->whereHas('course', function ($c) use ($start, $end) {
$c->where('is_chart', 1)
->where(function ($q2) use ($start, $end) {
$q2->whereBetween('start_date', [$start, $end])
->orWhereBetween('end_date', [$start, $end]);
})
->whereHas('typeDetail', function ($t) {
$t->where('name', '人才培训');
});
});
})->orWhere('type', 'like', '%人才%')->orWhere('talent_tags', 'like', '%人才%');
})
->count();
$diff = $studyCount - $rencaiCount;
$this->table(
['指标', 'study (User 数)', 'cover_rencai_total (rencai)', '差异 study - rencai'],
[['苏州人才', $studyCount, $rencaiCount, $diff]]
);
if ($diff !== 0) {
$this->warn("两者相差 {$diff},请检查 study 的 is_rencai 与 CourseSign::rencai 的细微口径。");
return 1;
}
$this->info('study 与 cover_rencai_total 一致。');
return 0;
}
}