where('is_push', 1); }) ->where('sign_end_date', $today) ->where('is_push', 1) ->get(); if ($courses->isEmpty()) { $this->info('没有可推送的课程'); return; } $YuanheRepository = new YuanheRepository(); foreach ($courses as $course) { // 所有报名审核成功的用户id $userIds = $course->courseSigns()->where('status', 1)->pluck('user_id'); $users = User::whereIn('id', $userIds)->has('company')->with('company')->groupBy('company_id')->get(); foreach ($users as $user) { $company = $user->company; if (trim((string) $company->credit_code) === '') { $reason = '统一社会信用代码为空'; $this->warn("推送跳过:{$course->name}-{$company->company_name}-{$reason}"); Log::warning('元禾课程推送跳过', [ 'course_id' => $course->id, 'course_name' => $course->name, 'company_id' => $company->id, 'company_name' => $company->company_name, 'reason' => $reason, ]); continue; } $result = $YuanheRepository->pushCourses($course, $user, $out); if ($result) { $user->is_push = 1; $user->save(); $this->info("推送成功:{$course->name}-{$user->name}"); } else { $this->info("推送失败:{$course->name}-{$user->name}-{$out}"); } } } return $this->info('全部更新完成'); } }