prepare(" INSERT INTO merchant_pattern_rules (user_id, pattern_text, normalized_pattern, match_type, category_id, priority, confidence, is_active, memo) VALUES (?, ?, ?, 'contains', ?, ?, 0.90, 1, 'manual') "); $normalized = mb_strtolower($keyword,'UTF-8'); $normalized = str_replace([' ','-','(',')','.',',','㈜'],'',$normalized); $stmt->execute([$uid, $keyword, $normalized, $categoryId, $priority]); $msg = '규칙이 추가되었습니다.'; } if ($mode === 'update') { $id = (int)($_POST['id'] ?? 0); $keyword = trim($_POST['keyword'] ?? ''); $categoryId = (int)($_POST['category_id'] ?? 0); $priority = (int)($_POST['priority'] ?? 100); $isActive = isset($_POST['is_active']) ? 1 : 0; if ($id <= 0) { throw new RuntimeException('규칙 ID가 올바르지 않습니다.'); } if ($keyword === '') { throw new RuntimeException('키워드를 입력하세요.'); } if ($categoryId <= 0) { throw new RuntimeException('카테고리를 선택하세요.'); } $stmt = $pdo->prepare(" UPDATE merchant_pattern_rules SET pattern_text = ?, normalized_pattern = ?, category_id = ?, priority = ?, is_active = ? WHERE id = ? AND user_id = ? "); $normalized = mb_strtolower($keyword,'UTF-8'); $normalized = str_replace([' ','-','(',')','.',',','㈜'],'',$normalized); $stmt->execute([ $keyword, $normalized, $categoryId, $priority, $isActive, $id, $uid ]); $msg = '규칙이 수정되었습니다.'; } if ($mode === 'delete') { $id = (int)($_POST['id'] ?? 0); if ($id <= 0) { throw new RuntimeException('규칙 ID가 올바르지 않습니다.'); } $stmt = $pdo->prepare("DELETE FROM merchant_pattern_rules WHERE id = ? AND user_id = ?"); $stmt->execute([$id, $uid]); $msg = '규칙이 삭제되었습니다.'; } } catch (Throwable $e) { $error = $e->getMessage(); } } $stmt = $pdo->prepare(" SELECT id, category_type, name FROM categories WHERE user_id = ? AND is_active = 1 ORDER BY category_type, sort_order, id "); $stmt->execute([$uid]); $categories = $stmt->fetchAll(); $stmt = $pdo->prepare(" SELECT r.*, c.name AS category_name, c.category_type FROM merchant_pattern_rules r JOIN categories c ON c.id = r.category_id WHERE r.user_id = ? ORDER BY r.priority ASC, r.id ASC "); $stmt->execute([$uid]); $rules = $stmt->fetchAll(); require __DIR__ . '/../app/views/header.php'; ?>
| ID | 키워드 | 카테고리 | 우선순위 | 활성 | 관리 |
|---|---|---|---|---|---|
| = $rule['id'] ?> | = h($rule['pattern_text']) ?> | [= h($rule['category_type']) ?>] = h($rule['category_name']) ?> | = $rule['priority'] ?> | = $rule['is_active'] ? 'Y' : 'N' ?> | |
| 등록된 규칙이 없습니다. | |||||