You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.9 KiB

<?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::whereHas('typeDetail', function ($query) {
$query->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)->whereNotNull('company_id')->groupBy('company_id')->get();
foreach ($users as $user) {
$result = $YuanheRepository->pushCourses($course, $user,$out);
if ($result) {
$this->info("推送成功:{$course->name}-{$user->name}");
} else {
$this->info("推送失败:{$course->name}-{$user->name}-{$out}");
}
}
}
return $this->info('全部更新完成');
}
}