2022-09-13 11:32:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use App\Models\Host;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class BanUser extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'ban {user_id} {reason}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
$user_id = $this->argument('user_id');
|
|
|
|
|
|
|
|
$reason = $this->argument('reason');
|
|
|
|
|
|
|
|
$user = User::find($user_id);
|
|
|
|
|
|
|
|
$this->info('封禁: ' . $user->name);
|
|
|
|
|
|
|
|
$this->confirm('确定要继续吗?如果继续,将会暂停所有的 Host。');
|
|
|
|
|
|
|
|
$user->banned_at = now();
|
|
|
|
$user->banned_reason = $reason;
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$this->info('正在暂停所有的 Host...');
|
|
|
|
Host::where('user_id', $user_id)->update([
|
|
|
|
'status' => 'suspended',
|
|
|
|
'suspended_at' => now()
|
|
|
|
]);
|
|
|
|
|
2022-11-07 01:21:03 +00:00
|
|
|
$this->info('正在吊销所有 Token...');
|
2022-09-13 11:32:58 +00:00
|
|
|
|
2022-11-07 01:21:03 +00:00
|
|
|
$user->tokens()->delete();
|
2022-09-13 11:32:58 +00:00
|
|
|
|
|
|
|
$this->info('封禁用户成功。');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|