mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-20 00:30:50 +08:00
add disable user method
This commit is contained in:
@@ -6,7 +6,9 @@ use App\Http\Resources\UserResource;
|
||||
use App\Models\ExamUser;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Models\UserBanLog;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserRepository extends BaseRepository
|
||||
{
|
||||
@@ -96,4 +98,21 @@ class UserRepository extends BaseRepository
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function disableUser(User $operator, $uid, $reason)
|
||||
{
|
||||
$targetUser = User::query()->findOrFail(['id', 'username']);
|
||||
$banLog = [
|
||||
'uid' => $uid,
|
||||
'username' => $targetUser->username,
|
||||
'reason' => $reason,
|
||||
'operator' => $operator->id,
|
||||
];
|
||||
$modCommentText = sprintf("Disable by %s, reason: %s.", $operator->username, $reason);
|
||||
DB::transaction(function () use ($targetUser, $banLog, $modCommentText) {
|
||||
$targetUser->updateWithModComment(['enable' => User::ENABLED_NO], $modCommentText);
|
||||
UserBanLog::query()->insert($banLog);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user