-- 添加订单操作者和角色字段
ALTER TABLE tb_order ADD COLUMN operator_id INT;
ALTER TABLE tb_order ADD COLUMN operator_type VARCHAR(20);
ALTER TABLE tb_order ADD COLUMN actual_paid_amount BIGINT;
ALTER TABLE tb_order ADD COLUMN purchase_role VARCHAR(50);

-- 添加字段注释
COMMENT ON COLUMN tb_order.operator_id IS '操作者ID（谁下的单）';
COMMENT ON COLUMN tb_order.operator_type IS '操作者类型（platform/agent）';
COMMENT ON COLUMN tb_order.actual_paid_amount IS '实际支付金额（分）';
COMMENT ON COLUMN tb_order.purchase_role IS '订单角色（self_purchase/purchased_by_parent/purchased_by_platform/purchase_for_subordinate）';

-- 添加索引
-- 注意：生产环境建议手动执行 CREATE INDEX CONCURRENTLY 避免锁表
CREATE INDEX IF NOT EXISTS idx_orders_operator_id ON tb_order(operator_id);
CREATE INDEX IF NOT EXISTS idx_orders_purchase_role ON tb_order(purchase_role);
