---
phase: 02-perm-fin-realname-poll
plan: "02"
subsystem: realname-activation
tags: [realname, package, migration, refactor]
dependency_graph:
  requires: []
  provides: [REALNAME-01, REALNAME-02, REALNAME-03, REALNAME-04, REALNAME-05]
  affects: [package, order, client_order, activation_service]
tech_stack:
  added: []
  patterns: [three-dimensional-decision, expiry-base-enum]
key_files:
  created:
    - migrations/000089_realname_expiry_base.up.sql
    - migrations/000089_realname_expiry_base.down.sql
  modified:
    - internal/model/package.go
    - internal/model/dto/package_dto.go
    - internal/store/postgres/package_store.go
    - internal/service/order/service.go
    - internal/service/client_order/service.go
    - internal/service/package/service.go
    - internal/service/package/activation_service.go
    - internal/task/auto_purchase.go
decisions:
  - "expiry_base 枚举替代 enable_realname_activation 布尔字段，清晰分离等实名语义与计时起点语义"
  - "三维决策：行业卡永远直接激活，C 端购买直接激活，后台囤货按 expiry_base 决定"
  - "auto_purchase.go 被认定为 C 端路径，不适用 expiry_base 三维决策"
metrics:
  duration: "~25min"
  completed_date: "2026-03-28"
  tasks: 2
  files: 8
---

# Phase 02 Plan 02: 实名激活架构重构 Summary

将 `enable_realname_activation` 布尔字段替换为 `expiry_base` 枚举（from_activation/from_purchase），重构激活决策为三维判断（卡类型+购买路径+expiry_base），全链路原子完成。

## Tasks Completed

| Task | Description | Commits |
|------|-------------|---------|
| 1 | DB 迁移 + Model + Store 清理（REALNAME-01） | `344850f` |
| 2a | DTO 更新（REALNAME-05） | `244a274` |
| 2b | activateMainPackage 三维决策（REALNAME-02） | `7dd5563` |
| 2c | C 端实名检查按卡类型（REALNAME-03） | `0ebb3d7` |
| 2d | ActivateByRealname 按 ExpiryBase 选时间基准（REALNAME-04） | `60b43bb` |
| 2e | auto_purchase.go 废弃引用清除（偏差修复） | `4be473c` |

## Verification

```
migrate-version: 89, dirty=false ✓
EnableRealnameActivation/enable_realname_activation/packagesNeedRealname 零引用 ✓
ExpiryBase 引用出现在 package.go、package_dto.go、order/service.go、
          client_order/service.go、activation_service.go ✓
go build ./internal/... 零错误 ✓
```

## Deviations from Plan

### Auto-fixed Issues

**1. [Rule 1 - Bug] auto_purchase.go 含废弃 EnableRealnameActivation 引用**
- **发现于：** Task 2 完成后编译验证
- **问题：** `internal/task/auto_purchase.go:433` 引用已删除的 `pkg.EnableRealnameActivation` 字段，导致编译失败
- **修复：** 识别 auto_purchase 为 C 端充值触发路径，不适用 expiry_base 三维决策，删除该分支并添加注释说明
- **文件：** `internal/task/auto_purchase.go`
- **Commit：** `4be473c`

**2. [Rule 1 - Bug] package/service.go DTO 映射引用 EnableRealnameActivation**
- **发现于：** Task 2 DTO 替换后 LSP 报错
- **问题：** `service.go` 的 Create/Update/toResponse 函数仍映射旧字段
- **修复：** 同步更新三处映射为 `ExpiryBase`
- **文件：** `internal/service/package/service.go`
- **Commit：** 含于 `244a274`

## Known Stubs

无已知留桩。全链路变更已完整实现。

## Self-Check: PASSED

- `migrations/000089_realname_expiry_base.up.sql` — FOUND ✓
- `migrations/000089_realname_expiry_base.down.sql` — FOUND ✓
- `internal/model/package.go` ExpiryBase 字段 — FOUND ✓
- `internal/model/dto/package_dto.go` ExpiryBase 三处 — FOUND ✓
- `internal/store/postgres/package_store.go` 直接一步 Create — FOUND ✓
- Commit `344850f` (REALNAME-01) — FOUND ✓
- Commit `244a274` (REALNAME-05) — FOUND ✓
- Commit `7dd5563` (REALNAME-02) — FOUND ✓
- Commit `0ebb3d7` (REALNAME-03) — FOUND ✓
- Commit `60b43bb` (REALNAME-04) — FOUND ✓
