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.

34 lines
1.1 KiB

<?php
namespace App\Console\Commands;
use App\Services\SchoolmateEnrollmentService;
use Illuminate\Console\Command;
class AutoSchoolmate extends Command
{
protected $signature = 'auto_schoolmate';
protected $description = '自动核验校友资格,补齐符合条件的学员并取消失去资格的校友';
public function handle(SchoolmateEnrollmentService $service)
{
$courses = $service->automaticCourses();
$added = 0;
$removed = 0;
$reconcile = function ($users) use ($service, $courses, &$added, &$removed) {
foreach ($users as $user) {
$change = $service->reconcile($user->id, $courses);
$added += (int) ($change === 1);
$removed += (int) ($change === -1);
}
};
$service->pendingUsers($courses)->chunkById(200, $reconcile, 'users.id', 'id');
$service->ineligibleSchoolmates($courses)->chunkById(200, $reconcile, 'users.id', 'id');
$this->info("校友资格核验完成,新增 {$added} 人,取消 {$removed} 人。");
return 0;
}
}