where('status', 1) ->whereHas('course', function ($query) use ($today) { $query->where('status', 1) ->whereNotNull('start_date') ->where('start_date', '>', $today); })->whereHas('user', function ($query) { $query->whereNotNull('plate') ->where('plate', '!=', ''); })->get(); foreach ($courseSigns as $courseSign) { // 2. 一个用户可能有多个车牌,按逗号拆开逐个处理 $plates = $this->parsePlates($courseSign->user->plate); foreach ($plates as $plate) { // 3. 如果这个车牌已经预约成功,就不用重复预约 $hasAppointment = ThirdAppointmentLog::where('course_sign_id', $courseSign->id) ->where('plate', $plate) ->where('plate_status', 1) ->exists(); if ($hasAppointment) { continue; } // 4. 没有预约成功记录,提交车牌预约任务 dispatch(new SendCourseCar($courseSign, $plate)); $total++; } } $this->info("课程车牌同步完成,共提交 {$total} 条车牌预约"); return self::SUCCESS; } /** * 解析用户车牌,兼容空格和重复车牌。 */ protected function parsePlates($plate) { return array_values(array_unique(array_filter(array_map('trim', explode(',', $plate))))); } }