-- 支付操作审计日志表
CREATE TABLE IF NOT EXISTS payment_audit_log (
    id SERIAL PRIMARY KEY,
    order_no VARCHAR(64) NOT NULL REFERENCES payment_orders(order_no),
    user_id INTEGER NOT NULL REFERENCES users(id),
    action VARCHAR(32) NOT NULL,  -- paid, refunded, cancelled, admin_confirm, admin_revoke, expired
    operator_id INTEGER REFERENCES users(id),  -- NULL 表示系统操作
    detail TEXT,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_payment_audit_log_order_no ON payment_audit_log(order_no);
CREATE INDEX IF NOT EXISTS idx_payment_audit_log_user_id ON payment_audit_log(user_id);
CREATE INDEX IF NOT EXISTS idx_payment_audit_log_created_at ON payment_audit_log(created_at);
