Files
junhong_cmp_fiber/migrations/backfill_order_purchase_role.sql
huang 8ed3d9da93
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m0s
feat: 实现代理钱包订单创建和订单角色追踪功能
新增功能:
- 代理在后台使用 wallet 支付时,订单直接完成(扣款 + 激活套餐)
- 支持代理自购和代理代购场景
- 新增订单角色追踪字段(operator_id、operator_type、actual_paid_amount、purchase_role)
- 订单查询支持 OR 逻辑(buyer_id 或 operator_id)
- 钱包流水记录交易子类型和关联店铺
- 佣金逻辑调整:代理代购不产生佣金

数据库变更:
- 订单表新增 4 个字段和 2 个索引
- 钱包流水表新增 2 个字段
- 包含迁移脚本和回滚脚本

文档:
- 功能总结文档
- 部署指南
- OpenAPI 文档更新
- Specs 同步(新增 agent-order-role-tracking capability)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 14:11:42 +08:00

44 lines
1.1 KiB
PL/PgSQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 数据回填脚本:为历史订单填充 purchase_role 和 operator_type
-- 用途:将现有平台代购订单标记为 purchased_by_platform
-- 执行时间:预计 < 1 秒(取决于历史订单数量)
-- 回滚方法:将 purchase_role 和 operator_type 设为 NULL
BEGIN;
-- 1. 回填平台代购订单offline + is_purchase_on_behalf = true
UPDATE tb_order
SET
purchase_role = 'purchased_by_platform',
operator_type = 'platform'
WHERE
payment_method = 'offline'
AND is_purchase_on_behalf = true
AND purchase_role IS NULL;
-- 2. 显示回填统计信息
DO $$
DECLARE
updated_count INTEGER;
BEGIN
SELECT COUNT(*) INTO updated_count
FROM tb_order
WHERE purchase_role = 'purchased_by_platform'
AND operator_type = 'platform';
RAISE NOTICE '已回填 % 条平台代购订单', updated_count;
END $$;
COMMIT;
-- 验证回填结果
SELECT
purchase_role,
operator_type,
payment_method,
is_purchase_on_behalf,
COUNT(*) as count
FROM tb_order
WHERE purchase_role IS NOT NULL
GROUP BY purchase_role, operator_type, payment_method, is_purchase_on_behalf
ORDER BY count DESC;