-- 演出票退款原因配置表 + 退款单归因字段

CREATE TABLE IF NOT EXISTS `kylin_order_refund_reasons` (
  `mid` int(11) NOT NULL AUTO_INCREMENT,
  `reason_id` varchar(32) NOT NULL DEFAULT '' COMMENT '业务ID',
  `name` varchar(100) NOT NULL DEFAULT '' COMMENT '退款理由名称',
  `need_detail` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否需要二级补充输入 0否 1是',
  `placeholder` varchar(200) NOT NULL DEFAULT '' COMMENT '二级输入placeholder',
  `is_applied` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否已应用 0未应用 1应用中',
  `sort` int(11) NOT NULL DEFAULT '0' COMMENT '排序，越大越靠前',
  `is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 0未删除 1已删除',
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL,
  PRIMARY KEY (`mid`),
  UNIQUE KEY `uk_reason_id` (`reason_id`),
  KEY `idx_is_applied_sort` (`is_applied`, `sort`),
  KEY `idx_is_deleted` (`is_deleted`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='演出票退款原因配置';

-- 已建表环境补逻辑删除字段（若已存在可忽略报错）
ALTER TABLE `kylin_order_refund_reasons`
  ADD COLUMN `is_deleted` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否删除 0未删除 1已删除' AFTER `sort`;
ALTER TABLE `kylin_order_refund_reasons`
  ADD KEY `idx_is_deleted` (`is_deleted`);

ALTER TABLE `kylin_order_refunds`
  ADD COLUMN `reason_id` varchar(32) DEFAULT NULL COMMENT '退款原因配置ID' AFTER `reason`,
  ADD COLUMN `reason_detail` varchar(200) DEFAULT NULL COMMENT '退款原因二级补充说明' AFTER `reason_id`;
