--
-- Host: 127.0.0.1    Database: moree
-- ------------------------------------------------------


--
-- Table structure for table `companies`
--

CREATE TABLE `companies` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `user_id` varchar(16) NOT NULL COMMENT '로그인 아이디 (4~16자 영숫자, 소문자)',
  `password_hash` varchar(255) NOT NULL COMMENT 'Argon2id 해시',
  `company_name` varchar(160) NOT NULL COMMENT '법인단체 명',
  `representative_name` varchar(60) DEFAULT NULL,
  `site_domain` varchar(80) DEFAULT NULL COMMENT 'ERP 테넌트 서브도메인(erp_module/site_config.site_domain과 매칭)',
  `site_domain_suffix` varchar(40) NOT NULL DEFAULT '.acux.store' COMMENT '사이트 도메인 접미사 — 기존은 .acux.store, 신규는 .mo-ree.com',
  `acux_company_id` int(11) DEFAULT NULL COMMENT 'agent.companies.id 매핑 (acuxmsg)',
  `business_no` varchar(10) NOT NULL COMMENT '사업자등록번호 10자리 (하이픈 제외)',
  `email` varchar(160) NOT NULL,
  `phone_mobile` varchar(20) NOT NULL COMMENT '휴대폰',
  `phone_office` varchar(20) DEFAULT NULL COMMENT '일반전화 (선택)',
  `address` varchar(300) NOT NULL COMMENT '사업장 소재지',
  `address_detail` varchar(200) DEFAULT NULL,
  `agree_service` tinyint(1) NOT NULL DEFAULT 0,
  `agree_privacy` tinyint(1) NOT NULL DEFAULT 0,
  `agree_marketing` tinyint(1) NOT NULL DEFAULT 0,
  `agree_marketing_at` datetime DEFAULT NULL,
  `status` varchar(30) NOT NULL DEFAULT 'active' COMMENT 'active|paused|suspended|terminated',
  `last_login_at` datetime DEFAULT NULL,
  `first_erp_visit_at` datetime DEFAULT NULL COMMENT 'mypage index에서 ERP 첫 진입 시각',
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  `updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `deleted_at` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_user_id` (`user_id`),
  UNIQUE KEY `uk_business_no` (`business_no`),
  UNIQUE KEY `uk_email` (`email`),
  UNIQUE KEY `site_domain` (`site_domain`),
  KEY `idx_status` (`status`),
  KEY `idx_companies_acux` (`acux_company_id`),
  KEY `idx_companies_deleted_created` (`deleted_at`,`created_at`)
) ENGINE=InnoDB AUTO_INCREMENT=1021 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `companies`
--
-- WHERE:  id=1019

INSERT INTO `companies` VALUES (1019,'test','$argon2id$v=19$m=65536,t=4,p=1$eFdPLmxoa01DdHhyZkYxbw$RVUwbPk3DddY84p5ULJYq6z0LUcafWfno70PW41+VN8','test','한상빈',NULL,'',NULL,'1112244444','gswx31@gmail.com','010-9635-8823',NULL,'경기 화성시 만세구 우정읍 3.1만세로 1','22',1,1,1,'2026-06-09 17:42:10','active','2026-06-12 13:10:59',NULL,'2026-06-09 17:42:10','2026-06-12 13:10:59',NULL);


--
-- Host: 127.0.0.1    Database: moree
-- ------------------------------------------------------


--
-- Table structure for table `company_login_logs`
--

CREATE TABLE `company_login_logs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `company_id` bigint(20) unsigned NOT NULL,
  `ip_address` varchar(45) DEFAULT NULL,
  `browser` varchar(120) DEFAULT NULL,
  `os` varchar(120) DEFAULT NULL,
  `result` varchar(20) NOT NULL COMMENT 'success|failed',
  `logged_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `idx_cll_company` (`company_id`,`logged_at`),
  CONSTRAINT `fk_cll_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=244 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `company_login_logs`
--
-- WHERE:  company_id=1019

INSERT INTO `company_login_logs` VALUES (214,1019,'211.197.16.113','Chrome/149.0.0.0','Windows NT 10.0; Win64; x64','success','2026-06-11 09:18:34'),(220,1019,'211.197.16.113','Chrome/149.0.0.0','Windows NT 10.0; Win64; x64','success','2026-06-11 12:54:18'),(234,1019,'211.197.16.113','Chrome/149.0.0.0','Windows NT 10.0; Win64; x64','success','2026-06-11 17:06:55'),(239,1019,'211.197.16.113','Chrome/149.0.0.0','Windows NT 10.0; Win64; x64','success','2026-06-12 13:10:59');


--
-- Host: 127.0.0.1    Database: moree
-- ------------------------------------------------------


--
-- Table structure for table `auth_verifications`
--

CREATE TABLE `auth_verifications` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `purpose` varchar(20) NOT NULL COMMENT 'register|find_id|find_pw',
  `company_id` bigint(20) unsigned DEFAULT NULL,
  `email` varchar(160) NOT NULL,
  `code` char(6) NOT NULL,
  `attempt_count` tinyint(3) unsigned NOT NULL DEFAULT 0,
  `expires_at` datetime NOT NULL,
  `verified_at` datetime DEFAULT NULL,
  `verification_token` char(64) DEFAULT NULL,
  `token_expires_at` datetime DEFAULT NULL,
  `consumed_at` datetime DEFAULT NULL,
  `request_ip` varchar(45) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `ix_email_purpose` (`email`,`purpose`),
  KEY `ix_token` (`verification_token`),
  KEY `ix_company` (`company_id`)
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `auth_verifications`
--
-- WHERE:  company_id=1019

INSERT INTO `auth_verifications` VALUES (27,'register',1019,'gswx31@gmail.com','567601',0,'2026-06-09 17:46:01','2026-06-09 17:41:11','34944034b617a2e9028db241defb0112b72e59ba82a64116cf834361e155adda','2026-06-09 17:51:11','2026-06-09 17:42:10','211.197.16.113','2026-06-09 17:41:01');


--
-- Host: 127.0.0.1    Database: moree
-- ------------------------------------------------------


--
-- Table structure for table `coupon_usages`
--

CREATE TABLE `coupon_usages` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `coupon_id` bigint(20) unsigned NOT NULL,
  `company_id` bigint(20) unsigned NOT NULL,
  `payment_id` bigint(20) unsigned DEFAULT NULL,
  `status` varchar(20) NOT NULL DEFAULT 'available' COMMENT 'available|used|expired',
  `discount_amount` decimal(12,2) NOT NULL DEFAULT 0.00,
  `registered_at` datetime NOT NULL DEFAULT current_timestamp() COMMENT '사용자 등록 시각',
  `used_at` datetime DEFAULT NULL COMMENT '결제 적용 시각',
  `expired_at` datetime DEFAULT NULL COMMENT '기간만료 처리 시각',
  PRIMARY KEY (`id`),
  KEY `idx_cu_coupon` (`coupon_id`,`registered_at`),
  KEY `idx_cu_company` (`company_id`,`registered_at`),
  KEY `fk_cu_payment` (`payment_id`),
  KEY `idx_cu_company_status` (`company_id`,`status`),
  CONSTRAINT `fk_cu_company` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_cu_coupon` FOREIGN KEY (`coupon_id`) REFERENCES `coupons` (`id`),
  CONSTRAINT `fk_cu_payment` FOREIGN KEY (`payment_id`) REFERENCES `payments` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `coupon_usages`
--
-- WHERE:  company_id=1019

INSERT INTO `coupon_usages` VALUES (26,8,1019,NULL,'available',0.00,'2026-06-11 20:12:35',NULL,'2026-06-30 23:59:59');


