feat: 활동 로그를 사람이 읽기 쉬운 문장으로 표시
- '내용' 컬럼: 대상명+작업(예: 업체 'OO' 수정), 변경 항목(라벨: 전→후) 인라인 표시 - 로그인(member housekeeping 수정)은 '로그인'으로 구분 표시 - 컬럼 한글 라벨(정확매칭+접미사 추정), 레코드 이름 자동 추출 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -55,11 +55,133 @@ class ActivityLog extends BaseController
|
|||||||
'delete' => '삭제',
|
'delete' => '삭제',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** 컬럼 → 한글 라벨 (없으면 접미사 추정 → 원문) */
|
||||||
|
private const FIELD_LABELS = [
|
||||||
|
'mb_id' => '아이디', 'mb_name' => '이름', 'mb_level' => '권한등급', 'mb_group' => '그룹',
|
||||||
|
'cp_type' => '구분', 'cp_biz_no' => '사업자번호', 'cp_rep_name' => '대표자',
|
||||||
|
'ds_shop_no' => '지정번호', 'ds_rep_name' => '대표자', 'ds_biz_no' => '사업자번호',
|
||||||
|
'ck_code' => '코드', 'cd_code' => '코드', 'cd_value' => '값', 'cd_sort' => '정렬순서',
|
||||||
|
'sa_kind' => '종류', 'lg_sido' => '시도', 'lg_gugun' => '구·군',
|
||||||
|
'mm_link' => '메뉴 링크', 'mm_is_view' => '노출여부', 'mm_level' => '노출등급',
|
||||||
|
'bs_bag_name' => '품목', 'bs_qty' => '수량', 'bs_amount' => '금액', 'bs_sale_date' => '판매일',
|
||||||
|
'bo_status' => '상태', 'bi2_status' => '상태',
|
||||||
|
];
|
||||||
|
|
||||||
|
/** 로그인 시 갱신되는 회원 필드(이것만 바뀌면 '로그인'으로 표시) */
|
||||||
|
private const LOGIN_FIELDS = ['mb_session_token', 'mb_latestdate', 'mb_login_fail_count', 'mb_locked_until'];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->logModel = model(ActivityLogModel::class);
|
$this->logModel = model(ActivityLogModel::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 컬럼명 → 한글 라벨 (정확 매칭 → 접미사 추정 → 원문) */
|
||||||
|
private function fieldLabel(string $col): string
|
||||||
|
{
|
||||||
|
if (isset(self::FIELD_LABELS[$col])) {
|
||||||
|
return self::FIELD_LABELS[$col];
|
||||||
|
}
|
||||||
|
$suffix = [
|
||||||
|
'_name' => '이름', '_tel' => '전화번호', '_phone' => '전화번호', '_addr' => '주소',
|
||||||
|
'_email' => '이메일', '_state' => '상태', '_regdate' => '등록일', '_date' => '일자',
|
||||||
|
'_qty' => '수량', '_amount' => '금액', '_price' => '단가', '_code' => '코드',
|
||||||
|
];
|
||||||
|
foreach ($suffix as $sfx => $lbl) {
|
||||||
|
if (str_ends_with($col, $sfx)) {
|
||||||
|
return $lbl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $col;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 레코드 표시 이름 추출 (이름 계열 필드 우선) */
|
||||||
|
private function recordName(array $data): string
|
||||||
|
{
|
||||||
|
foreach (['mb_name', 'cp_name', 'ds_name', 'lg_name', 'ck_name', 'cd_name', 'sa_name', 'fr_name', 'mn_name', 'mm_name'] as $k) {
|
||||||
|
if (! empty($data[$k])) {
|
||||||
|
return (string) $data[$k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($data as $k => $v) {
|
||||||
|
if (str_ends_with((string) $k, '_name') && (string) $v !== '') {
|
||||||
|
return (string) $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fmtVal(mixed $v): string
|
||||||
|
{
|
||||||
|
if (is_array($v)) {
|
||||||
|
$v = json_encode($v, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
$s = (string) ($v ?? '');
|
||||||
|
if ($s === '') {
|
||||||
|
return '(없음)';
|
||||||
|
}
|
||||||
|
|
||||||
|
return mb_strlen($s) > 30 ? mb_substr($s, 0, 30) . '…' : $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 로그 1행에 사람이 읽기 쉬운 요약(summaryText)·변경목록(changeList)·로그인여부(isLogin)를 붙인다 */
|
||||||
|
private function attachSummary(object $row): void
|
||||||
|
{
|
||||||
|
$table = (string) ($row->al_table ?? '');
|
||||||
|
$action = (string) ($row->al_action ?? '');
|
||||||
|
$before = $row->al_data_before ? (json_decode((string) $row->al_data_before, true) ?: []) : [];
|
||||||
|
$after = $row->al_data_after ? (json_decode((string) $row->al_data_after, true) ?: []) : [];
|
||||||
|
$tlabel = self::TABLE_LABELS[$table] ?? $table;
|
||||||
|
|
||||||
|
$changes = [];
|
||||||
|
$isLogin = false;
|
||||||
|
if ($action === 'update') {
|
||||||
|
foreach ($after as $k => $v) {
|
||||||
|
$bv = $before[$k] ?? null;
|
||||||
|
if (! array_key_exists($k, $before) || (string) $bv !== (string) $v) {
|
||||||
|
$changes[$k] = [$bv, $v];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($table === 'member' && $changes !== [] && array_diff(array_keys($changes), self::LOGIN_FIELDS) === []) {
|
||||||
|
$isLogin = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $this->recordName($action === 'delete' ? $before : $after);
|
||||||
|
if ($name === '') {
|
||||||
|
$name = $this->recordName($before);
|
||||||
|
}
|
||||||
|
$namePart = $name !== '' ? " '" . $name . "'" : ((int) ($row->al_record_id ?? 0) ? ' #' . (int) $row->al_record_id : '');
|
||||||
|
|
||||||
|
if ($isLogin) {
|
||||||
|
$text = '로그인';
|
||||||
|
} elseif ($action === 'create') {
|
||||||
|
$text = $tlabel . $namePart . ' 등록';
|
||||||
|
} elseif ($action === 'delete') {
|
||||||
|
$text = $tlabel . $namePart . ' 삭제';
|
||||||
|
} else {
|
||||||
|
$text = $tlabel . $namePart . ' 수정';
|
||||||
|
}
|
||||||
|
|
||||||
|
$skip = array_merge(self::LOGIN_FIELDS, ['mb_passwd', 'mb_totp_secret', 'mb_session_token']);
|
||||||
|
$changeList = [];
|
||||||
|
foreach ($changes as $k => $pair) {
|
||||||
|
if (in_array($k, $skip, true)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$changeList[] = [
|
||||||
|
'label' => $this->fieldLabel($k),
|
||||||
|
'from' => $this->fmtVal($pair[0]),
|
||||||
|
'to' => $this->fmtVal($pair[1]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$row->summaryText = $text;
|
||||||
|
$row->isLogin = $isLogin;
|
||||||
|
$row->changeList = $changeList;
|
||||||
|
}
|
||||||
|
|
||||||
public function index(): string
|
public function index(): string
|
||||||
{
|
{
|
||||||
helper('admin');
|
helper('admin');
|
||||||
@@ -103,6 +225,10 @@ class ActivityLog extends BaseController
|
|||||||
$list = $builder->orderBy('activity_log.al_idx', 'DESC')->paginate(20);
|
$list = $builder->orderBy('activity_log.al_idx', 'DESC')->paginate(20);
|
||||||
$pager = $this->logModel->pager;
|
$pager = $this->logModel->pager;
|
||||||
|
|
||||||
|
foreach ($list as $row) {
|
||||||
|
$this->attachSummary($row);
|
||||||
|
}
|
||||||
|
|
||||||
return view('admin/layout', [
|
return view('admin/layout', [
|
||||||
'title' => '활동 로그',
|
'title' => '활동 로그',
|
||||||
'content' => view('admin/access/activity_log', [
|
'content' => view('admin/access/activity_log', [
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ $actionBadge = static function (string $a): string {
|
|||||||
<th class="text-left">일시</th>
|
<th class="text-left">일시</th>
|
||||||
<th class="text-left">사용자</th>
|
<th class="text-left">사용자</th>
|
||||||
<th class="text-center">작업</th>
|
<th class="text-center">작업</th>
|
||||||
<th class="text-left">대상</th>
|
<th class="text-left">내용</th>
|
||||||
<th class="text-center">대상 번호</th>
|
|
||||||
<th class="text-center no-print">상세</th>
|
<th class="text-center no-print">상세</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -65,26 +64,43 @@ $actionBadge = static function (string $a): string {
|
|||||||
<?php foreach ($list as $row): ?>
|
<?php foreach ($list as $row): ?>
|
||||||
<?php
|
<?php
|
||||||
$act = (string) ($row->al_action ?? '');
|
$act = (string) ($row->al_action ?? '');
|
||||||
$tbl = (string) ($row->al_table ?? '');
|
$isLogin = ! empty($row->isLogin);
|
||||||
$who = trim((string) ($row->mb_name ?? '') . (($row->mb_id ?? '') !== '' ? ' (' . $row->mb_id . ')' : ''));
|
$who = trim((string) ($row->mb_name ?? '') . (($row->mb_id ?? '') !== '' ? ' (' . $row->mb_id . ')' : ''));
|
||||||
|
$badgeText = $isLogin ? '로그인' : ($actionLabels[$act] ?? $act);
|
||||||
|
$badgeStyle = $isLogin ? 'background:#ede9fe;color:#5b21b6;' : $actionBadge($act);
|
||||||
|
$changeList = $row->changeList ?? [];
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-left pl-2 whitespace-nowrap"><?= esc((string) ($row->al_regdate ?? '')) ?></td>
|
<td class="text-left pl-2 whitespace-nowrap"><?= esc((string) ($row->al_regdate ?? '')) ?></td>
|
||||||
<td class="text-left pl-2"><?= $who !== '' ? esc($who) : '<span class="text-gray-400">시스템</span>' ?></td>
|
<td class="text-left pl-2"><?= $who !== '' ? esc($who) : '<span class="text-gray-400">시스템</span>' ?></td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<span style="<?= $actionBadge($act) ?>display:inline-block;padding:1px 8px;border-radius:9999px;font-size:11px;font-weight:700;">
|
<span style="<?= $badgeStyle ?>display:inline-block;padding:1px 8px;border-radius:9999px;font-size:11px;font-weight:700;white-space:nowrap;">
|
||||||
<?= esc($actionLabels[$act] ?? $act) ?>
|
<?= esc($badgeText) ?>
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-left pl-2"><?= esc($tableLabels[$tbl] ?? $tbl) ?></td>
|
<td class="text-left pl-2">
|
||||||
<td class="text-center"><?= (int) ($row->al_record_id ?? 0) ?: '-' ?></td>
|
<span class="font-semibold text-gray-800"><?= esc((string) ($row->summaryText ?? '')) ?></span>
|
||||||
|
<?php if ($changeList !== []): ?>
|
||||||
|
<div class="text-xs text-gray-500 mt-0.5">
|
||||||
|
<?php foreach (array_slice($changeList, 0, 4) as $c): ?>
|
||||||
|
<span class="inline-block mr-2">
|
||||||
|
<span class="text-gray-600"><?= esc($c['label']) ?>:</span>
|
||||||
|
<span class="text-gray-400"><?= esc($c['from']) ?></span>
|
||||||
|
→
|
||||||
|
<span class="text-gray-700"><?= esc($c['to']) ?></span>
|
||||||
|
</span>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php if (count($changeList) > 4): ?><span class="text-gray-400">외 <?= count($changeList) - 4 ?>건</span><?php endif; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</td>
|
||||||
<td class="text-center no-print">
|
<td class="text-center no-print">
|
||||||
<a href="<?= base_url('admin/access/activity-logs/' . (int) $row->al_idx) ?>" class="text-blue-700 hover:underline">보기</a>
|
<a href="<?= base_url('admin/access/activity-logs/' . (int) $row->al_idx) ?>" class="text-blue-700 hover:underline">보기</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($list === []): ?>
|
<?php if ($list === []): ?>
|
||||||
<tr><td colspan="6" class="text-center text-gray-400 py-6">조회된 로그가 없습니다.</td></tr>
|
<tr><td colspan="5" class="text-center text-gray-400 py-6">조회된 로그가 없습니다.</td></tr>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user