-- ============================================
-- t_refund 新增字段：是否恢复库存
-- 1=恢复（默认），0=不恢复
-- 用于区分"识别多扣退库存"和"质量问题不退库存"场景
-- ============================================
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
                   WHERE TABLE_SCHEMA = DATABASE()
                   AND TABLE_NAME = 't_refund'
                   AND COLUMN_NAME = 'restore_stock');

SET @sql = IF(@col_exists = 0,
    'ALTER TABLE `t_refund` ADD COLUMN `restore_stock` TINYINT NOT NULL DEFAULT 1 COMMENT ''退款后是否恢复库存：1=恢复，0=不恢复'' AFTER `status`',
    'SELECT ''Column restore_stock already exists, skipping'' AS message');

PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
