-- ============================================================
-- agent_withdrawal 表缺失字段修复脚本
-- 解决 Error 1054: Unknown column 'withdraw_type'/'bank_card_no'/'bank_name'/'payee_name' in 'field list'
-- 执行方式：在 MySQL 客户端或 Navicat 等工具中逐条执行
-- 若某字段已存在会报 Duplicate column name，跳过该条继续执行下一条即可
-- ============================================================

-- 1. 添加提现类型
ALTER TABLE `agent_withdrawal` ADD COLUMN `withdraw_type` TINYINT NOT NULL DEFAULT 1 COMMENT '提现类型:1-支付宝,2-银行卡' AFTER `agent_id`;

-- 2. 添加银行卡号
ALTER TABLE `agent_withdrawal` ADD COLUMN `bank_card_no` VARCHAR(50) DEFAULT NULL COMMENT '银行卡号' AFTER `payeeAccount`;

-- 3. 添加开户支行
ALTER TABLE `agent_withdrawal` ADD COLUMN `bank_name` VARCHAR(100) DEFAULT NULL COMMENT '开户支行' AFTER `bank_card_no`;

-- 4. 添加收款人姓名
ALTER TABLE `agent_withdrawal` ADD COLUMN `payee_name` VARCHAR(50) DEFAULT NULL COMMENT '收款人姓名' AFTER `bank_name`;

-- 5. 添加索引（若已存在可跳过）
ALTER TABLE `agent_withdrawal` ADD INDEX `idx_withdraw_type` (`withdraw_type`);

-- 6. 更新现有记录
UPDATE `agent_withdrawal` SET `withdraw_type` = 1 WHERE `withdraw_type` IS NULL OR `withdraw_type` = 0;
