Files
nexusphp/app/Models/UserBanLog.php

30 lines
834 B
PHP
Raw Normal View History

2021-05-12 13:45:00 +08:00
<?php
namespace App\Models;
class UserBanLog extends NexusModel
{
protected $table = 'user_ban_logs';
2021-05-13 21:31:09 +08:00
protected $fillable = ['uid', 'username', 'operator', 'reason'];
2022-10-13 18:52:10 +08:00
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");
}
2021-05-12 13:45:00 +08:00
}