CREATE DATABASE IF NOT EXISTS `xk_of` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT '萧康云医官网与SaaS后台数据库';

USE `xk_of`;

CREATE TABLE IF NOT EXISTS `nl_admin` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '用户ID',
  `open_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'OpenID，后期整合萧康服务中心会用到',
  `wx_open_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '微信小程序OpenID',
  `avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '头像',
  `nick_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '昵称',
  `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '密码',
  `phone` char(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户手机',
  `email` char(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户邮箱',
  `code` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '业务员推广码',
  `role_id` int NOT NULL DEFAULT '0' COMMENT '角色',
  `province_id` int NOT NULL DEFAULT '0' COMMENT '省',
  `city_id` int NOT NULL DEFAULT '0' COMMENT '市',
  `reg_ip` bigint NOT NULL DEFAULT '0' COMMENT '注册IP',
  `last_login_time` int NOT NULL DEFAULT '0' COMMENT '最后登录时间',
  `ip` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0' COMMENT '最后登录IP',
  `ip_table` json NOT NULL COMMENT '常用登录IP地址列表',
  `operation_password` varchar(60) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '操作密码',
  `desc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '备注',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '用户状态 0正常 1禁用',
  `last_reset_password_at` datetime DEFAULT NULL COMMENT '最后一次更新密码时间',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_phone` (`phone`) USING BTREE,
  KEY `idx_role_id` (`role_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='管理员表';

CREATE TABLE IF NOT EXISTS `nl_role` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '角色ID',
  `name` varchar(32) NOT NULL DEFAULT '' COMMENT '角色名称',
  `code` varchar(64) NOT NULL DEFAULT '' COMMENT '角色编码',
  `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '角色说明',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_code` (`code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色表';

CREATE TABLE IF NOT EXISTS `nl_admin_role` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '关联ID',
  `admin_id` int unsigned NOT NULL DEFAULT '0' COMMENT '管理员ID',
  `role_id` int unsigned NOT NULL DEFAULT '0' COMMENT '角色ID',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_admin_role` (`admin_id`,`role_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='管理员角色关联表';

CREATE TABLE IF NOT EXISTS `nl_menu` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '菜单ID',
  `parent_id` int unsigned NOT NULL DEFAULT '0' COMMENT '父级菜单ID',
  `title` varchar(64) NOT NULL DEFAULT '' COMMENT '菜单标题',
  `name` varchar(64) NOT NULL DEFAULT '' COMMENT '路由名称',
  `path` varchar(255) NOT NULL DEFAULT '' COMMENT '路由路径',
  `component` varchar(255) NOT NULL DEFAULT '' COMMENT '前端组件路径',
  `redirect` varchar(255) NOT NULL DEFAULT '' COMMENT '重定向地址',
  `icon` varchar(64) NOT NULL DEFAULT '' COMMENT '菜单图标',
  `type` tinyint NOT NULL DEFAULT '1' COMMENT '菜单类型 1目录 2菜单 3按钮',
  `permission` varchar(128) NOT NULL DEFAULT '' COMMENT '权限标识',
  `visible` tinyint NOT NULL DEFAULT '1' COMMENT '是否显示 0隐藏 1显示',
  `keep_alive` tinyint NOT NULL DEFAULT '0' COMMENT '是否缓存页面 0否 1是',
  `menu_area` tinyint NOT NULL DEFAULT '1' COMMENT '双列菜单区域 1主列 2次列',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_parent_id` (`parent_id`) USING BTREE,
  KEY `idx_permission` (`permission`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='后台多级菜单表';

CREATE TABLE IF NOT EXISTS `nl_role_menu` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '授权ID',
  `role_id` int unsigned NOT NULL DEFAULT '0' COMMENT '角色ID',
  `menu_id` int unsigned NOT NULL DEFAULT '0' COMMENT '菜单ID',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_role_menu` (`role_id`,`menu_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='角色菜单授权表';

CREATE TABLE IF NOT EXISTS `nl_system_config` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '配置ID',
  `config_key` varchar(128) NOT NULL DEFAULT '' COMMENT '配置键',
  `config_value` text NOT NULL COMMENT '配置值',
  `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '配置说明',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_config_key` (`config_key`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='系统配置表';

CREATE TABLE IF NOT EXISTS `nl_admin_preference` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '偏好ID',
  `admin_id` int unsigned NOT NULL DEFAULT '0' COMMENT '管理员ID',
  `menu_layout` varchar(16) NOT NULL DEFAULT '' COMMENT '菜单布局 single单列 double双列 空则使用全局配置',
  `theme` varchar(16) NOT NULL DEFAULT '' COMMENT '后台主题 light明亮 dark暗色 空则跟随系统',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_admin_id` (`admin_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='管理员个人偏好表';

CREATE TABLE IF NOT EXISTS `nl_site_page` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '页面ID',
  `code` varchar(64) NOT NULL DEFAULT '' COMMENT '页面编码',
  `title` varchar(128) NOT NULL DEFAULT '' COMMENT '页面标题',
  `seo_title` varchar(255) NOT NULL DEFAULT '' COMMENT 'SEO标题',
  `seo_keywords` varchar(255) NOT NULL DEFAULT '' COMMENT 'SEO关键词',
  `seo_description` varchar(500) NOT NULL DEFAULT '' COMMENT 'SEO描述',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_code` (`code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='官网页面表';

CREATE TABLE IF NOT EXISTS `nl_site_section` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '模块ID',
  `page_id` int unsigned NOT NULL DEFAULT '0' COMMENT '页面ID',
  `section_key` varchar(64) NOT NULL DEFAULT '' COMMENT '模块标识',
  `title` varchar(128) NOT NULL DEFAULT '' COMMENT '模块标题',
  `subtitle` varchar(255) NOT NULL DEFAULT '' COMMENT '模块副标题',
  `content` json NOT NULL COMMENT '模块内容JSON',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_page_id` (`page_id`) USING BTREE,
  KEY `idx_section_key` (`section_key`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='官网页面模块表';

CREATE TABLE IF NOT EXISTS `nl_site_lead` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '线索ID',
  `name` varchar(32) NOT NULL DEFAULT '' COMMENT '联系人姓名',
  `phone` char(11) NOT NULL DEFAULT '' COMMENT '联系电话',
  `clinic_name` varchar(128) NOT NULL DEFAULT '' COMMENT '诊所名称',
  `city` varchar(64) NOT NULL DEFAULT '' COMMENT '所在城市',
  `plan_code` varchar(64) NOT NULL DEFAULT '' COMMENT '意向套餐编码',
  `source_page` varchar(64) NOT NULL DEFAULT '' COMMENT '来源页面',
  `remark` varchar(500) NOT NULL DEFAULT '' COMMENT '备注',
  `follow_status` tinyint NOT NULL DEFAULT '0' COMMENT '跟进状态 0待跟进 1跟进中 2已成交 3无效',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_phone` (`phone`) USING BTREE,
  KEY `idx_plan_code` (`plan_code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='官网咨询线索表';

CREATE TABLE IF NOT EXISTS `nl_saas_plan` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '套餐ID',
  `code` varchar(64) NOT NULL DEFAULT '' COMMENT '套餐编码',
  `name` varchar(64) NOT NULL DEFAULT '' COMMENT '套餐名称',
  `description` varchar(500) NOT NULL DEFAULT '' COMMENT '套餐说明',
  `monthly_fee` int unsigned NOT NULL DEFAULT '0' COMMENT '月付金额，单位分',
  `yearly_fee` int unsigned NOT NULL DEFAULT '0' COMMENT '年付金额，单位分',
  `recommended` tinyint NOT NULL DEFAULT '0' COMMENT '是否推荐 0否 1是',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_code` (`code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS套餐表';

CREATE TABLE IF NOT EXISTS `nl_saas_plan_feature` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '权益ID',
  `plan_id` int unsigned NOT NULL DEFAULT '0' COMMENT '套餐ID',
  `name` varchar(64) NOT NULL DEFAULT '' COMMENT '权益名称',
  `value` varchar(255) NOT NULL DEFAULT '' COMMENT '权益值',
  `highlight` tinyint NOT NULL DEFAULT '0' COMMENT '是否重点展示 0否 1是',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_plan_id` (`plan_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS套餐权益表';

CREATE TABLE IF NOT EXISTS `nl_tenant` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '租户ID',
  `tenant_name` varchar(128) NOT NULL DEFAULT '' COMMENT '租户名称或诊所名称',
  `contact_name` varchar(32) NOT NULL DEFAULT '' COMMENT '联系人姓名',
  `phone` char(11) NOT NULL DEFAULT '' COMMENT '联系电话',
  `city` varchar(64) NOT NULL DEFAULT '' COMMENT '所在城市',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_phone` (`phone`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS订购主体表';

CREATE TABLE IF NOT EXISTS `nl_subscription` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '订阅ID',
  `tenant_id` int unsigned NOT NULL DEFAULT '0' COMMENT '租户ID',
  `plan_id` int unsigned NOT NULL DEFAULT '0' COMMENT '套餐ID',
  `start_at` int NOT NULL DEFAULT '0' COMMENT '订阅开始时间',
  `end_at` int NOT NULL DEFAULT '0' COMMENT '订阅结束时间',
  `auto_renew` tinyint NOT NULL DEFAULT '0' COMMENT '是否自动续费 0否 1是',
  `subscription_status` tinyint NOT NULL DEFAULT '0' COMMENT '订阅状态 0待生效 1生效中 2已过期 3已取消',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
  KEY `idx_plan_id` (`plan_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS订阅关系表';

CREATE TABLE IF NOT EXISTS `nl_order` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '订单ID',
  `order_no` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  `tenant_id` int unsigned NOT NULL DEFAULT '0' COMMENT '租户ID',
  `plan_id` int unsigned NOT NULL DEFAULT '0' COMMENT '套餐ID',
  `billing_cycle` varchar(16) NOT NULL DEFAULT 'month' COMMENT '订购周期 month月付 year年付',
  `amount` int unsigned NOT NULL DEFAULT '0' COMMENT '订单金额，单位分',
  `pay_status` tinyint NOT NULL DEFAULT '0' COMMENT '支付状态 0待支付 1已支付 2已退款 3已关闭',
  `order_status` tinyint NOT NULL DEFAULT '0' COMMENT '订单状态 0待支付 1已完成 2已取消 3已关闭',
  `expired_at` int NOT NULL DEFAULT '0' COMMENT '订单过期时间',
  `paid_at` int NOT NULL DEFAULT '0' COMMENT '支付完成时间',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_order_no` (`order_no`) USING BTREE,
  KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
  KEY `idx_plan_id` (`plan_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS套餐订购订单表';

CREATE TABLE IF NOT EXISTS `nl_payment` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '支付ID',
  `order_no` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  `channel` varchar(32) NOT NULL DEFAULT '' COMMENT '支付渠道 wxpay微信 alipay支付宝 manual线下',
  `channel_trade_no` varchar(128) NOT NULL DEFAULT '' COMMENT '渠道交易号',
  `amount` int unsigned NOT NULL DEFAULT '0' COMMENT '支付金额，单位分',
  `pay_status` tinyint NOT NULL DEFAULT '0' COMMENT '支付状态 0待支付 1成功 2失败 3退款',
  `notify_payload` json NOT NULL COMMENT '支付回调原始数据',
  `paid_at` int NOT NULL DEFAULT '0' COMMENT '支付完成时间',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_order_no` (`order_no`) USING BTREE,
  KEY `idx_channel_trade_no` (`channel_trade_no`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='SaaS支付流水表';

INSERT INTO `nl_system_config` (`config_key`, `config_value`, `desc`, `status`, `created_at`, `updated_at`)
VALUES ('admin_menu_layout', 'double', '后台默认菜单布局 single单列 double双列', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `config_value` = VALUES(`config_value`), `updated_at` = UNIX_TIMESTAMP();

INSERT INTO `nl_role` (`id`, `name`, `code`, `desc`, `status`, `sort`, `created_at`, `updated_at`)
VALUES
  (1, '超级管理员', 'super_admin', '拥有后台全部权限', 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (2, '运营人员', 'operator', '管理官网内容、线索、套餐和订单', 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), `updated_at` = UNIX_TIMESTAMP();

INSERT INTO `nl_menu` (`id`, `parent_id`, `title`, `name`, `path`, `component`, `icon`, `type`, `permission`, `visible`, `menu_area`, `status`, `sort`, `created_at`, `updated_at`)
VALUES
  (1, 0, '控制台', 'Dashboard', '/dashboard', 'Dashboard', 'dashboard', 2, 'dashboard:view', 1, 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (2, 0, '官网运营', 'Site', '/site', 'Layout', 'global', 1, 'site:view', 1, 1, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (21, 2, '页面模块', 'SiteSections', '/site/sections', 'SiteSections', 'blocks', 2, 'site:section:view', 1, 2, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (22, 2, '咨询线索', 'SiteLeads', '/site/leads', 'SiteLeads', 'message', 2, 'site:lead:view', 1, 2, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (3, 0, '商业化', 'Commerce', '/commerce', 'Layout', 'wallet', 1, 'commerce:view', 1, 1, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (31, 3, '套餐管理', 'PlanList', '/commerce/plans', 'PlanList', 'package', 2, 'plan:view', 1, 2, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (32, 3, '订单管理', 'OrderList', '/commerce/orders', 'OrderList', 'orders', 2, 'order:view', 1, 2, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (4, 0, '系统管理', 'System', '/system', 'Layout', 'setting', 1, 'system:view', 1, 1, 1, 4, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (41, 4, '管理员', 'AdminList', '/system/admins', 'AdminList', 'user', 2, 'admin:view', 1, 2, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (42, 4, '角色权限', 'RoleList', '/system/roles', 'RoleList', 'safety', 2, 'role:view', 1, 2, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (43, 4, '菜单管理', 'MenuList', '/system/menus', 'MenuList', 'menu', 2, 'menu:view', 1, 2, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `title` = VALUES(`title`), `updated_at` = UNIX_TIMESTAMP();

INSERT INTO `nl_saas_plan` (`id`, `code`, `name`, `description`, `monthly_fee`, `yearly_fee`, `recommended`, `status`, `sort`, `created_at`, `updated_at`)
VALUES
  (1, 'starter', '基础版', '适合单店诊所快速上线线上预约和基础经营管理', 19900, 199000, 0, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (2, 'growth', '增长版', '适合需要推广员获客、医生协同和经营分析的成长型诊所', 39900, 399000, 1, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (3, 'enterprise', '连锁版', '适合连锁门店和需要深度配置的诊所集团', 89900, 899000, 0, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`), `updated_at` = UNIX_TIMESTAMP();

INSERT INTO `nl_saas_plan_feature` (`id`, `plan_id`, `name`, `value`, `highlight`, `status`, `sort`, `created_at`, `updated_at`)
VALUES
  (1, 1, '患者端小程序', '基础预约与提醒', 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (2, 1, 'PC后台', '线索与订单管理', 1, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (3, 1, '账号数量', '5个员工账号', 0, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (4, 2, '四端小程序', '患者端、医生端、老板端、推广员端', 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (5, 2, '经营看板', '收入、转化、复购分析', 1, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (6, 2, '账号数量', '20个员工账号', 0, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (7, 3, '多门店能力', '预留连锁门店扩展', 1, 1, 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (8, 3, '专属服务', '部署辅导和运营顾问', 1, 1, 2, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (9, 3, '账号数量', '不限账号数量', 0, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`), `updated_at` = UNIX_TIMESTAMP();

-- 官网 CMS 扩展：页面 GSO/GEO、素材、招聘、站点配置
ALTER TABLE `nl_site_page` ADD COLUMN `gso_content` json DEFAULT NULL COMMENT 'GSO/GEO生成式搜索优化内容JSON' AFTER `seo_description`;

CREATE TABLE IF NOT EXISTS `nl_site_media` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '素材ID',
  `media_type` varchar(32) NOT NULL DEFAULT '' COMMENT '素材类型 logo标志 favicon站点图标 page_image页面图片 share_image分享图 job_image招聘图',
  `group_code` varchar(64) NOT NULL DEFAULT '' COMMENT '素材分组编码',
  `title` varchar(128) NOT NULL DEFAULT '' COMMENT '素材标题',
  `url` varchar(500) NOT NULL DEFAULT '' COMMENT '素材地址',
  `alt` varchar(255) NOT NULL DEFAULT '' COMMENT '图片替代文本',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0禁用 1启用',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_media_type` (`media_type`) USING BTREE,
  KEY `idx_group_code` (`group_code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='官网素材表';

CREATE TABLE IF NOT EXISTS `nl_recruit_job` (
  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT '职位ID',
  `title` varchar(128) NOT NULL DEFAULT '' COMMENT '职位名称',
  `department` varchar(64) NOT NULL DEFAULT '' COMMENT '所属部门',
  `job_type` varchar(32) NOT NULL DEFAULT '' COMMENT '职位类型',
  `city` varchar(64) NOT NULL DEFAULT '' COMMENT '工作城市',
  `salary` varchar(64) NOT NULL DEFAULT '' COMMENT '薪资范围',
  `experience` varchar(64) NOT NULL DEFAULT '' COMMENT '经验要求',
  `description` varchar(1000) NOT NULL DEFAULT '' COMMENT '职位描述',
  `requirements` json NOT NULL COMMENT '岗位要求JSON',
  `manager` varchar(32) NOT NULL DEFAULT '' COMMENT '招聘负责人',
  `manager_title` varchar(64) NOT NULL DEFAULT '' COMMENT '负责人职位',
  `email` varchar(128) NOT NULL DEFAULT '' COMMENT '投递邮箱',
  `phone` varchar(32) NOT NULL DEFAULT '' COMMENT '联系电话',
  `featured` tinyint NOT NULL DEFAULT '0' COMMENT '是否重点招聘 0否 1是',
  `status` tinyint NOT NULL DEFAULT '1' COMMENT '状态 0下架 1上架',
  `sort` int NOT NULL DEFAULT '0' COMMENT '排序',
  `created_at` int NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int NOT NULL DEFAULT '0' COMMENT '更新时间',
  `deleted_at` int NOT NULL DEFAULT '0' COMMENT '删除时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_department` (`department`) USING BTREE,
  KEY `idx_status_sort` (`status`,`sort`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='招聘职位表';

INSERT INTO `nl_system_config` (`config_key`, `config_value`, `desc`, `status`, `created_at`, `updated_at`)
VALUES
  ('site_title', '萧康云医官网', '站点标题', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('site_logo', '/src/assets/images/logo.png', '站点LOGO', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('site_favicon', '/favicon.ico', '站点favicon图标', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('site_seo', '{"title":"萧康云医官网","keywords":"诊所SaaS,云医,诊所管理","description":"萧康云医为诊所提供全链路经营赋能。"}', '默认SEO配置JSON', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('site_gso', '{"brand":"萧康云医","summary":"诊所赋能SaaS平台","services":["患者端","医生端","老板端","推广员端","PC后台"]}', '默认GSO/GEO配置JSON', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('amap_key', '', '高德地图Key', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  ('amap_security_code', '', '高德地图安全密钥', 1, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `config_value` = VALUES(`config_value`), `updated_at` = UNIX_TIMESTAMP();

INSERT INTO `nl_menu` (`id`, `parent_id`, `title`, `name`, `path`, `component`, `icon`, `type`, `permission`, `visible`, `menu_area`, `status`, `sort`, `created_at`, `updated_at`)
VALUES
  (23, 2, '图片管理', 'SiteMedia', '/site/media', 'SiteMedia', 'image', 2, 'site:media:view', 1, 2, 1, 3, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (24, 2, '招聘管理', 'RecruitJobs', '/site/jobs', 'RecruitJobs', 'briefcase', 2, 'site:job:view', 1, 2, 1, 4, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()),
  (25, 2, '站点设置', 'SiteSettings', '/site/settings', 'SiteSettings', 'setting', 2, 'site:settings:view', 1, 2, 1, 5, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())
ON DUPLICATE KEY UPDATE `title` = VALUES(`title`), `updated_at` = UNIX_TIMESTAMP();
