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' => '삭제',
|
||||
];
|
||||
|
||||
/** 컬럼 → 한글 라벨 (없으면 접미사 추정 → 원문) */
|
||||
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()
|
||||
{
|
||||
$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
|
||||
{
|
||||
helper('admin');
|
||||
@@ -103,6 +225,10 @@ class ActivityLog extends BaseController
|
||||
$list = $builder->orderBy('activity_log.al_idx', 'DESC')->paginate(20);
|
||||
$pager = $this->logModel->pager;
|
||||
|
||||
foreach ($list as $row) {
|
||||
$this->attachSummary($row);
|
||||
}
|
||||
|
||||
return view('admin/layout', [
|
||||
'title' => '활동 로그',
|
||||
'content' => view('admin/access/activity_log', [
|
||||
|
||||
Reference in New Issue
Block a user