添加 封禁逻辑

This commit is contained in:
iVampireSP.com 2022-09-13 19:32:58 +08:00
parent 2c87d4a701
commit 6c82b8afb5
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
3 changed files with 128 additions and 0 deletions

View File

@ -0,0 +1,72 @@
<?php
namespace App\Console\Commands;
use App\Models\Host;
use App\Models\User;
use App\Models\AccessToken;
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()
]);
$this->info('正在清除 Token.');
AccessToken::where('user_id', $user_id)->delete();
$this->info('封禁用户成功。');
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace App\Console\Commands;
use App\Models\Host;
use Illuminate\Console\Command;
class SuspendUserAllHosts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:suspended {user_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '暂停用户的所有 Host';
/**
* 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');
Host::where('user_id', $user_id)->update([
'status' => 'suspended',
'suspended_at' => now()
]);
$this->info('暂停用户的所有 Host 成功。');
}
}

View File

@ -2,6 +2,8 @@
namespace App\Console; namespace App\Console;
use App\Console\Commands\BanUser;
use App\Console\Commands\SuspendUserAllHosts;
use App\Jobs\HostCost; use App\Jobs\HostCost;
use App\Jobs\ClearTasks; use App\Jobs\ClearTasks;
use App\Jobs\DeleteHost; use App\Jobs\DeleteHost;
@ -18,6 +20,8 @@ class Kernel extends ConsoleKernel
*/ */
protected $commands = [ protected $commands = [
// //
BanUser::class,
SuspendUserAllHosts::class
]; ];
/** /**