parent
f153a87e99
commit
64675e5319
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\Course;
|
||||
use App\Models\User;
|
||||
use App\Repositories\MeetRepository;
|
||||
use App\Repositories\YuanheRepository;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
||||
class PushCourses extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'push_courses {--course_id=}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '推送课程数据';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$course_id = $this->option('course_id');
|
||||
$courses = Course::where(function ($query) use ($course_id) {
|
||||
if ($course_id) {
|
||||
$query->where('id', $course_id);
|
||||
}
|
||||
})->whereHas('typeDetail', function ($query) {
|
||||
$query->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)->whereNotNull('company_id')->get();
|
||||
foreach ($users as $user) {
|
||||
$result = $YuanheRepository->pushCourses($course, $user);
|
||||
if ($result) {
|
||||
$this->info("推送成功:{$course->name}-{$user->name}");
|
||||
} else {
|
||||
$this->info("推送失败:{$course->name}-{$user->name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->info('全部更新完成');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue