优化 封禁逻辑

This commit is contained in:
iVampireSP.com 2022-11-18 16:29:57 +08:00
parent 82b2a3a954
commit dc9ad81cb6
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 12 additions and 11 deletions

View File

@ -49,23 +49,14 @@ public function handle()
$this->info('封禁: ' . $user->name);
$this->confirm('确定要继续吗?如果继续,将会暂停所有的 Host。');
$this->confirm('确定要继续吗?如果继续,将会暂停所有的 Host,并且吊销所有 Token。');
$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...');
$user->tokens()->delete();
$this->info('封禁用户成功。');
return 0;
}
}

View File

@ -52,6 +52,16 @@ protected static function boot()
// balance 四舍五入
$model->balance = round($model->balance, 2);
if ($model->banned_at) {
Host::where('user_id', $model->id)->update([
'status' => 'suspended',
'suspended_at' => now()
]);
$model->tokens()->delete();
}
});
}