Files
nexusphp/app/Models/UserBanLog.php
2026-03-29 21:42:43 +07:00

32 lines
866 B
PHP

<?php
namespace App\Models;
class UserBanLog extends NexusModel
{
protected $table = 'user_ban_logs';
protected $fillable = ['uid', 'username', 'operator', 'reason'];
public $timestamps = true;
public static function clearUserBanLogDuplicate()
{
$lists = UserBanLog::query()
->selectRaw("min(id) as id, uid, count(*) as counts")
->groupBy('uid')
->having("counts", ">", 1)
->get();
if ($lists->isEmpty()) {
do_log("sql: " . last_query() . ", no data to delete");
return;
}
$idArr = $lists->pluck("id")->toArray();
$uidArr = $lists->pluck('uid')->toArray();
$result = UserBanLog::query()->whereIn("uid", $uidArr)->whereNotIn("id", $idArr)->delete();
do_log("sql: " . last_query() . ", result: $result");
}
}