diff --git a/app/Controllers/Admin/ActivityLog.php b/app/Controllers/Admin/ActivityLog.php index de1f49d..92604c8 100644 --- a/app/Controllers/Admin/ActivityLog.php +++ b/app/Controllers/Admin/ActivityLog.php @@ -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', [ diff --git a/app/Views/admin/access/activity_log.php b/app/Views/admin/access/activity_log.php index 2eba272..d86902e 100644 --- a/app/Views/admin/access/activity_log.php +++ b/app/Views/admin/access/activity_log.php @@ -56,8 +56,7 @@ $actionBadge = static function (string $a): string { 일시 사용자 작업 - 대상 - 대상 번호 + 내용 상세 @@ -65,26 +64,43 @@ $actionBadge = static function (string $a): string { al_action ?? ''); - $tbl = (string) ($row->al_table ?? ''); + $isLogin = ! empty($row->isLogin); $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 ?? []; ?> al_regdate ?? '')) ?> 시스템' ?> - - + + - - al_record_id ?? 0) ?: '-' ?> + + summaryText ?? '')) ?> + +
+ + + : + + → + + + + 4): ?> +
+ + 보기 - 조회된 로그가 없습니다. + 조회된 로그가 없습니다.