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
|
|
|
|
2026-03-29 21:42:43 +07:00
|
|
|
public $timestamps = true;
|
|
|
|
|
|
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
|
|
|
}
|