-- 检查并添加钱包流水表字段（如果不存在）
DO $$
BEGIN
    -- 检查并添加 transaction_subtype 字段
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name='tb_agent_wallet_transaction'
        AND column_name='transaction_subtype'
    ) THEN
        ALTER TABLE tb_agent_wallet_transaction ADD COLUMN transaction_subtype VARCHAR(50);
        COMMENT ON COLUMN tb_agent_wallet_transaction.transaction_subtype IS '交易子类型（细分 order_payment 场景）';
    END IF;

    -- 检查并添加 related_shop_id 字段
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns
        WHERE table_name='tb_agent_wallet_transaction'
        AND column_name='related_shop_id'
    ) THEN
        ALTER TABLE tb_agent_wallet_transaction ADD COLUMN related_shop_id INT;
        COMMENT ON COLUMN tb_agent_wallet_transaction.related_shop_id IS '关联店铺ID（代购时记录下级店铺）';
    END IF;
END
$$;
