From 957319909f99e4590631cc498bb04144b2805e31 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Tue, 20 Jan 2026 18:20:04 +0800 Subject: [PATCH] update --- app/Console/Commands/DiffStudyCoverRencai.php | 78 +++++++++++++++++++ app/Http/Controllers/Admin/UserController.php | 58 +++++++++++++- 2 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 app/Console/Commands/DiffStudyCoverRencai.php diff --git a/app/Console/Commands/DiffStudyCoverRencai.php b/app/Console/Commands/DiffStudyCoverRencai.php new file mode 100644 index 0000000..b1038a7 --- /dev/null +++ b/app/Console/Commands/DiffStudyCoverRencai.php @@ -0,0 +1,78 @@ +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; + } +} diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 38fd6ab..1c6cd7e 100755 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -436,11 +436,61 @@ class UserController extends BaseController } }); } - // 是否人才(与 CourseSign::rencai 条件一致):1=是时筛选。任一条即视为人才:报名过人才培训课程 或 type/talent_tags 含「人才」 + // 是否人才(与 CourseSign::rencai 口径一致):1=是时筛选。任一条即视为人才:报名过人才培训课程 或 type/talent_tags 含「人才」。 + // 人才培训:仅在本次查询的课程与时间范围内(courses_start/end、is_chart 等)认定,与 cover_rencai_total 一致。 if (isset($all['is_rencai']) && (int) $all['is_rencai'] === 1) { - $query->where(function ($q) { - $q->whereHas('courseSigns', function ($cs) { - $cs->where('status', 1)->whereHas('course', function ($c) { + $query->where(function ($q) use ($all) { + $q->whereHas('courseSigns', function ($cs) use ($all) { + $cs->where('status', 1); + if (isset($all['course_id'])) { + $cs->where('course_id', $all['course_id']); + } + if (isset($all['sign_start_date']) && isset($all['sign_end_date'])) { + $cs->whereBetween('created_at', [$all['sign_start_date'], $all['sign_end_date']]); + } elseif (isset($all['sign_start_date'])) { + $cs->where('created_at', '>=', $all['sign_start_date']); + } elseif (isset($all['sign_end_date'])) { + $cs->where('created_at', '<=', $all['sign_end_date']); + } + $cs->whereHas('course', function ($c) use ($all) { + if (isset($all['year'])) { + $c->where('year', $all['year']); + } + if (isset($all['is_fee'])) { + $c->where('is_fee', $all['is_fee']); + } + if (isset($all['course_type'])) { + $c->where('type', $all['course_type']); + } + if (isset($all['course_name'])) { + $c->where('name', 'like', '%' . $all['course_name'] . '%'); + } + if (!empty($all['courses_start_date']) && !empty($all['courses_end_date'])) { + $c->where(function ($q2) use ($all) { + $q2->whereBetween('start_date', [$all['courses_start_date'], $all['courses_end_date']]) + ->orWhereBetween('end_date', [$all['courses_start_date'], $all['courses_end_date']]); + }); + } else { + if (!empty($all['courses_start_date'])) { + $c->where('start_date', '>=', $all['courses_start_date']); + } + if (!empty($all['courses_end_date'])) { + $c->where('end_date', '<=', $all['courses_end_date']); + } + } + if (isset($all['courses_ing']) && $all['courses_ing'] == 1) { + $c->where(function ($q2) { + $q2->where('start_date', '<=', date('Y-m-d'))->where('end_date', '>=', date('Y-m-d')); + }); + } + if (isset($all['is_chart'])) { + $c->where('is_chart', $all['is_chart']); + } + if (!empty($all['from']) && strpos((string) $all['from'], '跟班学员') !== false) { + $c->whereHas('typeDetail', function ($t) { + $t->where('is_count_genban', 1); + }); + } $c->whereHas('typeDetail', function ($t) { $t->where('name', '人才培训'); });