-- 기존 테이블 활용 최소 변경 SQL -- 기존 temp_, extra_ 컬럼을 활용하여 새 기능 구현 -- 1. 시스템 설정을 위한 간단한 테이블 (기존 테이블 없을 경우만 생성) CREATE TABLE IF NOT EXISTS `order_config` ( `id` int(11) NOT NULL AUTO_INCREMENT, `config_key` varchar(100) NOT NULL, `config_value` text NOT NULL, `config_desc` varchar(255) DEFAULT NULL, `config_type` varchar(20) DEFAULT 'text', `created_at` datetime DEFAULT CURRENT_TIMESTAMP, `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `config_key` (`config_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 기본 설정값 삽입 (중복 시 무시) INSERT IGNORE INTO `order_config` (`config_key`, `config_value`, `config_desc`, `config_type`) VALUES ('timer_enabled', '1', '24시간 타이머 활성화 여부', 'boolean'), ('timer_message_active', '견적 제안 마감까지 {time} 남았습니다.', '타이머 활성화 시 메시지', 'text'), ('timer_message_inactive', '고객 작성이 완료되었습니다. 24시간 후에 확인 바랍니다.', '타이머 비활성화 시 메시지', 'text'), ('contract_deposit_rate', '10', '계약금 비율 (%)', 'number'), ('middle_payment_rate', '40', '중도금 비율 (%)', 'number'), ('expert_visit_fee', '50000', '전문가 방문 비용', 'number'), ('expert_account_info', '국민은행 123-456-789 (주)창호전문가', '전문가 방문 계좌 정보', 'text'); -- 2. 메일 템플릿 테이블 (기존 테이블 없을 경우만 생성) CREATE TABLE IF NOT EXISTS `order_mail_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `template_key` varchar(100) NOT NULL, `template_name` varchar(255) NOT NULL, `subject` varchar(255) NOT NULL, `content` text NOT NULL, `variables` text DEFAULT NULL COMMENT '사용 가능한 변수들 (JSON)', `created_at` datetime DEFAULT CURRENT_TIMESTAMP, `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `template_key` (`template_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 3. SMS 템플릿 테이블 (기존 테이블 없을 경우만 생성) CREATE TABLE IF NOT EXISTS `order_sms_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `template_key` varchar(100) NOT NULL, `template_name` varchar(255) NOT NULL, `content` text NOT NULL, `variables` text DEFAULT NULL COMMENT '사용 가능한 변수들 (JSON)', `created_at` datetime DEFAULT CURRENT_TIMESTAMP, `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `template_key` (`template_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- 4. 기존 estimate 테이블의 temp_ 컬럼 활용 정의 -- temp_1: 전문가 방문 요청 여부 ('Y'/'N') -- temp_2: 전문가 방문 상태 ('requested'/'scheduled'/'completed'/'cancelled') -- temp_3: 전문가 방문 비용 -- temp_4: 전문가 방문 일정 (YYYY-MM-DD HH:MM) -- temp_5: 전문가 방문 메모 -- 5. 기본 메일 템플릿 삽입 (중복 시 무시) INSERT IGNORE INTO `order_mail_templates` (`template_key`, `template_name`, `subject`, `content`, `variables`) VALUES ('customer_request_complete', '고객 - 견적 요청 완료', '견적 요청이 완료되었습니다', '안녕하세요 {customer_name}님,

견적 요청이 성공적으로 완료되었습니다.
24시간 후에 견적서를 확인해주시기 바랍니다.

감사합니다.', '["customer_name", "request_title", "request_date"]'), ('agent_new_request', '대리점 - 새 견적 요청', '새로운 견적 요청이 등록되었습니다', '안녕하세요 {agent_name}님,

{customer_name}님이 견적을 요청했습니다.

제목: {request_title}
요청일: {request_date}

견적 작성 URL: {write_url}

24시간 내에 견적을 제안해주시기 바랍니다.', '["agent_name", "customer_name", "request_title", "request_date", "write_url"]'), ('customer_quote_selected', '고객 - 견적 선택 완료', '견적이 선택되었습니다', '안녕하세요 {customer_name}님,

{agent_name} 대리점의 견적이 선택되었습니다.

계약금({deposit_amount}원)을 입금해주시기 바랍니다.

계좌정보: {account_info}', '["customer_name", "agent_name", "deposit_amount", "account_info"]'), ('agent_quote_selected', '대리점 - 견적 선택됨', '견적이 선택되었습니다', '안녕하세요 {agent_name}님,

{customer_name}님이 귀하의 견적을 선택하셨습니다.

시공 일정을 관리자에게 알려주시기 바랍니다.

감사합니다.', '["agent_name", "customer_name", "request_title"]'), ('expert_visit_request', '전문가 방문 요청', '전문가 방문이 요청되었습니다', '안녕하세요 {customer_name}님,

전문가 방문이 요청되었습니다.

방문 비용: {visit_fee}원
계좌정보: {account_info}

입금 확인 후 방문 일정을 조율하겠습니다.', '["customer_name", "visit_fee", "account_info"]'); -- 6. 기본 SMS 템플릿 삽입 (중복 시 무시) INSERT IGNORE INTO `order_sms_templates` (`template_key`, `template_name`, `content`, `variables`) VALUES ('customer_request_complete', '고객 - 견적 요청 완료', '{customer_name}님, 견적 요청이 완료되었습니다. 24시간 후에 확인해주세요.', '["customer_name"]'), ('agent_new_request', '대리점 - 새 견적 요청', '{agent_name}님, {customer_name}님이 견적을 요청했습니다. 24시간 내에 제안해주세요. {write_url}', '["agent_name", "customer_name", "write_url"]'), ('customer_quote_selected', '고객 - 견적 선택 완료', '{customer_name}님, 견적이 선택되었습니다. 계약금 {deposit_amount}원을 입금해주세요.', '["customer_name", "deposit_amount"]'), ('agent_quote_selected', '대리점 - 견적 선택됨', '{agent_name}님, {customer_name}님이 귀하의 견적을 선택하셨습니다. 시공 일정을 알려주세요.', '["agent_name", "customer_name"]'), ('expert_visit_request', '전문가 방문 요청', '{customer_name}님, 전문가 방문이 요청되었습니다. 방문비 {visit_fee}원 입금 후 일정 조율하겠습니다.', '["customer_name", "visit_fee"]'); -- 7. 기존 테이블 컬럼 활용 방법 주석 /* 기존 estimate 테이블의 temp_ 컬럼 활용: - temp_1: 전문가 방문 요청 여부 ('Y'/'N') - temp_2: 전문가 방문 상태 ('requested'/'scheduled'/'completed'/'cancelled') - temp_3: 전문가 방문 비용 (숫자) - temp_4: 전문가 방문 일정 (YYYY-MM-DD HH:MM 형식) - temp_5: 전문가 방문 메모/특이사항 기존 estimate 테이블의 extra_ 컬럼 활용: - extra_1: 고객 연락처 (전문가 방문용) - extra_2: 결제 상태 ('pending'/'paid'/'cancelled') - extra_3: 추가 요청사항 - extra_4: 관리자 메모 - extra_5: 예비 필드 */