-- ========================================
-- 诊断提现功能问题
-- ========================================

-- 1. 检查withdraw表是否存在
SELECT 
    TABLE_NAME,
    ENGINE,
    TABLE_COLLATION
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'peidu' 
  AND TABLE_NAME = 'withdraw';

-- 2. 检查withdraw表的所有字段
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    IS_NULLABLE,
    COLUMN_DEFAULT,
    COLUMN_KEY,
    EXTRA,
    COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'peidu' 
  AND TABLE_NAME = 'withdraw'
ORDER BY ORDINAL_POSITION;

-- 3. 检查是否有NOT NULL约束的字段没有默认值
SELECT 
    COLUMN_NAME,
    DATA_TYPE,
    IS_NULLABLE,
    COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'peidu' 
  AND TABLE_NAME = 'withdraw'
  AND IS_NULLABLE = 'NO'
  AND COLUMN_DEFAULT IS NULL
  AND COLUMN_KEY != 'PRI'
  AND EXTRA NOT LIKE '%auto_increment%';

-- 4. 查看最近的提现记录（如果有）
SELECT * FROM withdraw 
ORDER BY id DESC 
LIMIT 5;

-- 5. 测试插入一条提现记录
-- INSERT INTO withdraw (
--     tenant_id, teacher_id, withdraw_no, amount, fee, actual_amount,
--     account_type, account_no, account_name, status, apply_time, create_time
-- ) VALUES (
--     1, 1, 'TEST001', 100.00, 0.00, 100.00,
--     'wechat', '', '微信', 'pending', NOW(), NOW()
-- );
