commit
7e54982d59
@ -0,0 +1,70 @@
|
||||
<?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';
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
$today = date('Y-m-d');
|
||||
$courses = Course::where('sign_end_date', $today)->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('全部更新完成');
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue