-- 插入支付数据
INSERT INTO payments (order_id, user_id, amount, currency, payment_method, status, external_transaction_id, paid_at, created_at) 
SELECT 
    o.id as order_id,
    o.user_id,
    o.total_amount as amount,
    o.currency,
    CASE 
        WHEN RAND() < 0.6 THEN 'ALIPAY'
        WHEN RAND() < 0.8 THEN 'WECHAT'
        ELSE 'PAYPAL'
    END as payment_method,
    CASE 
        WHEN o.status = 'COMPLETED' THEN 'COMPLETED'
        WHEN o.status = 'CANCELLED' THEN 'CANCELLED'
        ELSE 'PENDING'
    END as status,
    CONCAT('TXN_', UNIX_TIMESTAMP(o.created_at), '_', o.id) as external_transaction_id,
    CASE 
        WHEN o.status = 'COMPLETED' THEN DATE_ADD(o.created_at, INTERVAL FLOOR(RAND() * 30) MINUTE)
        ELSE NULL
    END as paid_at,
    o.created_at
FROM orders o;
