From 65541e5b4e6d65e450a47015ad70e45f263d5ea5 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Tue, 20 Jan 2026 17:32:43 +0800 Subject: [PATCH] update --- app/Console/Commands/AutoSchoolmate.php | 16 +++------ app/Http/Controllers/Admin/UserController.php | 33 ++++++++++++++++--- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/Console/Commands/AutoSchoolmate.php b/app/Console/Commands/AutoSchoolmate.php index d648524..2015621 100755 --- a/app/Console/Commands/AutoSchoolmate.php +++ b/app/Console/Commands/AutoSchoolmate.php @@ -4,12 +4,8 @@ namespace App\Console\Commands; use App\Models\Course; use App\Models\CourseSign; -use App\Models\EmailRecord; -use App\Models\EmailRecordUser; use App\Models\User; -use App\Repositories\MeetRepository; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Mail; class AutoSchoolmate extends Command @@ -67,14 +63,10 @@ class AutoSchoolmate extends Command continue; } - // 只更新还不是校友的学员,避免重复处理 - // 注意:is_schoolmate != 1 不会匹配 NULL 值,需要显式包含 NULL - $updated = User::whereIn('id', $courseSigns->pluck('user_id')) - ->where(function ($query) { - $query->where('is_schoolmate', '!=', 1) - ->orWhereNull('is_schoolmate'); - }) - //->where('is_black',0) + // 只更新还不是校友的学员;从 非校友→校友 时顺带写入 schoolmate_time + $userIds = $courseSigns->pluck('user_id')->unique()->values(); + $updated = User::whereIn('id', $userIds) + ->whereRaw('COALESCE(is_schoolmate, 0) != 1') ->update(['is_schoolmate' => 1, 'schoolmate_time' => now()]); $totalUpdated += $updated; diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index e716f19..38fd6ab 100755 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -191,6 +191,7 @@ class UserController extends BaseController * @OA\Parameter(name="company_tag", in="query", @OA\Schema(type="string"), required=false, description="企业标签"), * @OA\Parameter(name="talent_tags", in="query", @OA\Schema(type="string"), required=false, description="人才标签,多个英文逗号分隔"), * @OA\Parameter(name="address", in="query", @OA\Schema(type="string"), required=false, description="公司地址,模糊匹配关联 company 的 company_address 或 company_city"), + * @OA\Parameter(name="is_rencai", in="query", @OA\Schema(type="string"), required=false, description="是否人才,1=是时筛选;满足任一条即为人才:报名过人才培训课程(typeDetail.name=人才培训) 或 user.type/talent_tags 含「人才」"), * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), * @OA\Response( * response="200", @@ -435,6 +436,18 @@ class UserController extends BaseController } }); } + // 是否人才(与 CourseSign::rencai 条件一致):1=是时筛选。任一条即视为人才:报名过人才培训课程 或 type/talent_tags 含「人才」 + 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) { + $c->whereHas('typeDetail', function ($t) { + $t->where('name', '人才培训'); + }); + }); + })->orWhere('type', 'like', '%人才%')->orWhere('talent_tags', 'like', '%人才%'); + }); + } })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc'); if (isset($all['is_export']) && !empty($all['is_export'])) { $list = $list->limit(5000)->get()->toArray(); @@ -755,13 +768,23 @@ class UserController extends BaseController if ($validator->fails()) { return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]); } - $idsArray = explode(',', $all['ids']); - $data = []; + $idsArray = array_filter(array_map('trim', explode(',', $all['ids']))); + if (empty($idsArray)) { + return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, '编号不能为空']); + } if (isset($all['is_schoolmate'])) { - $data['is_schoolmate'] = $all['is_schoolmate']; - $data['schoolmate_time'] = ($all['is_schoolmate'] == 1) ? now() : null; + if ($all['is_schoolmate'] == 1) { + // 仅当 非校友→校友 时写入 schoolmate_time;已是校友的不更新,避免覆盖 + $this->model->whereIn('id', $idsArray) + ->whereRaw('COALESCE(is_schoolmate, 0) != 1') + ->update(['is_schoolmate' => 1, 'schoolmate_time' => now()]); + } else { + $this->model->whereIn('id', $idsArray)->update([ + 'is_schoolmate' => $all['is_schoolmate'], + 'schoolmate_time' => null, + ]); + } } - $this->model->whereIn('id', $idsArray)->update($data); return $this->success('批量更新成功'); }