89 lines
2.5 KiB
PHP
89 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Admin\Log;
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
final class MemberLoginLogRepository
|
|
{
|
|
public function paginateByYear(int $year, array $filters, int $perPage = 30): LengthAwarePaginator
|
|
{
|
|
$table = 'mem_login_' . $year;
|
|
|
|
$q = DB::table($table . ' as l')
|
|
->select([
|
|
'l.seq',
|
|
'l.mem_no',
|
|
'l.sf',
|
|
'l.conn',
|
|
'l.ip4',
|
|
'l.ip4_c',
|
|
'l.error_code',
|
|
'l.dt_reg',
|
|
'l.platform',
|
|
'l.browser',
|
|
]);
|
|
|
|
// 기간(dt_reg)
|
|
if (!empty($filters['date_from'])) {
|
|
$q->where('l.dt_reg', '>=', $filters['date_from'] . ' 00:00:00');
|
|
}
|
|
if (!empty($filters['date_to'])) {
|
|
$q->where('l.dt_reg', '<=', $filters['date_to'] . ' 23:59:59.999999');
|
|
}
|
|
|
|
// mem_no
|
|
if (($filters['mem_no'] ?? null) !== null) {
|
|
$q->where('l.mem_no', (int)$filters['mem_no']);
|
|
}
|
|
|
|
// 성공/실패
|
|
if (!empty($filters['sf'])) {
|
|
$q->where('l.sf', $filters['sf']);
|
|
}
|
|
|
|
// 접속경로 1/2
|
|
if (!empty($filters['conn'])) {
|
|
$q->where('l.conn', $filters['conn']);
|
|
}
|
|
|
|
// ip prefix
|
|
$ip4 = trim((string)($filters['ip4'] ?? ''));
|
|
if ($ip4 !== '') {
|
|
$q->where('l.ip4', 'like', $this->escapeLike($ip4) . '%');
|
|
}
|
|
|
|
$ip4c = trim((string)($filters['ip4_c'] ?? ''));
|
|
if ($ip4c !== '') {
|
|
$q->where('l.ip4_c', 'like', $this->escapeLike($ip4c) . '%');
|
|
}
|
|
|
|
// error_code
|
|
$err = trim((string)($filters['error_code'] ?? ''));
|
|
if ($err !== '') {
|
|
$q->where('l.error_code', $err);
|
|
}
|
|
|
|
// platform/browser (contains)
|
|
$platform = trim((string)($filters['platform'] ?? ''));
|
|
if ($platform !== '') {
|
|
$q->where('l.platform', 'like', '%' . $this->escapeLike($platform) . '%');
|
|
}
|
|
|
|
$browser = trim((string)($filters['browser'] ?? ''));
|
|
if ($browser !== '') {
|
|
$q->where('l.browser', 'like', '%' . $this->escapeLike($browser) . '%');
|
|
}
|
|
|
|
$q->orderByDesc('l.dt_reg')->orderByDesc('l.seq');
|
|
|
|
return $q->paginate($perPage)->withQueryString();
|
|
}
|
|
|
|
private function escapeLike(string $s): string
|
|
{
|
|
return str_replace(['\\', '%', '_'], ['\\\\', '\%', '\_'], $s);
|
|
}
|
|
}
|