feat: 예치금 시스템 추가 (은행 SMS 자동 매칭)

- manage_deposit Function Calling 추가 (잔액조회, 입금신고, 거래내역, 취소)
- Email Worker로 은행 SMS 파싱 (하나/KB/신한 지원)
- 양방향 자동 매칭: 사용자 신고 ↔ 은행 알림
- D1 테이블: user_deposits, deposit_transactions, bank_notifications
- 관리자 전용: 대기목록 조회, 입금 확인/거절

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
kappa
2026-01-16 12:29:57 +09:00
parent 8b2ccf05b5
commit e98bfd3a68
7 changed files with 702 additions and 11 deletions

View File

@@ -45,9 +45,51 @@ CREATE TABLE IF NOT EXISTS user_domains (
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- 예치금 계정 테이블
CREATE TABLE IF NOT EXISTS user_deposits (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL UNIQUE,
balance INTEGER NOT NULL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- 은행 입금 알림 테이블 (SMS → 메일 → 파싱)
CREATE TABLE IF NOT EXISTS bank_notifications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bank_name TEXT,
depositor_name TEXT NOT NULL,
amount INTEGER NOT NULL,
balance_after INTEGER,
transaction_time DATETIME,
raw_message TEXT,
matched_transaction_id INTEGER,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (matched_transaction_id) REFERENCES deposit_transactions(id)
);
-- 예치금 거래 내역 테이블
CREATE TABLE IF NOT EXISTS deposit_transactions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
type TEXT NOT NULL CHECK(type IN ('deposit', 'withdrawal', 'refund')),
amount INTEGER NOT NULL,
status TEXT NOT NULL DEFAULT 'pending' CHECK(status IN ('pending', 'confirmed', 'rejected', 'cancelled')),
depositor_name TEXT,
description TEXT,
confirmed_at DATETIME,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- 인덱스
CREATE INDEX IF NOT EXISTS idx_user_domains_user ON user_domains(user_id);
CREATE INDEX IF NOT EXISTS idx_user_domains_domain ON user_domains(domain);
CREATE INDEX IF NOT EXISTS idx_deposits_user ON user_deposits(user_id);
CREATE INDEX IF NOT EXISTS idx_transactions_user ON deposit_transactions(user_id);
CREATE INDEX IF NOT EXISTS idx_transactions_status ON deposit_transactions(status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_bank_notifications_match ON bank_notifications(depositor_name, amount, matched_transaction_id);
CREATE INDEX IF NOT EXISTS idx_buffer_user ON message_buffer(user_id);
CREATE INDEX IF NOT EXISTS idx_buffer_chat ON message_buffer(user_id, chat_id);
CREATE INDEX IF NOT EXISTS idx_summary_user ON summaries(user_id, chat_id);