refactor: 出库时间更名为首次购买套餐时间,换货新资产不再按换货完成时间记录
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Failing after 38s

- 字段 outbound_at → first_purchase_at,记录表 tb_asset_outbound_record → tb_asset_first_purchase_record,接口 /outbound-records → /first-purchase-records,筛选参数与导出列同步更名
- 换货后的新资产不因换货写入,在当前世代真正支付套餐订单时才记录;记录来源只保留 order / backfill,去掉换货单字段
- 迁移 000266 重命名列、表、索引与约束;同步 Spec、设计、任务与前端接口变更说明

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-27 16:47:02 +09:00
parent 909f4d0ec2
commit 62ec94adec
46 changed files with 570 additions and 560 deletions

View File

@@ -39,7 +39,7 @@ type Service struct {
silenceHook *packagesilenceapp.ExchangeHook
}
// SetSilenceHook 注入沉默期与出库时间换货接缝。
// SetSilenceHook 注入沉默期与首次购买套餐时间换货接缝。
func (s *Service) SetSilenceHook(hook *packagesilenceapp.ExchangeHook) {
s.silenceHook = hook
}
@@ -402,7 +402,7 @@ func (s *Service) Renew(ctx context.Context, id uint) error {
}).Error; updateErr != nil {
return errors.Wrap(errors.CodeDatabaseError, updateErr, "重置旧卡转新状态失败")
}
// 出库时间:旧卡回库、世代 +1,清空出库时间并结束旧世代出库记录
// 首次购买套餐时间:旧卡回库、世代 +1,清空首次购买套餐时间并结束旧世代首次购买套餐记录
if hookErr := s.silenceHook.OnOldAssetRenewedInTx(ctx, tx, constants.ExchangeAssetTypeIotCard, card.ID, card.Generation, time.Now()); hookErr != nil {
return hookErr
}
@@ -479,7 +479,7 @@ func (s *Service) Renew(ctx context.Context, id uint) error {
}).Error; err != nil {
return errors.Wrap(errors.CodeDatabaseError, err, "重置旧设备转新状态失败")
}
// 出库时间:旧设备回库、世代 +1,清空出库时间并结束旧世代出库记录
// 首次购买套餐时间:旧设备回库、世代 +1,清空首次购买套餐时间并结束旧世代首次购买套餐记录
if err = s.silenceHook.OnOldAssetRenewedInTx(ctx, tx, constants.ExchangeAssetTypeDevice, device.ID, device.Generation, time.Now()); err != nil {
return err
}
@@ -897,10 +897,6 @@ func (s *Service) completeExchangeWithTx(ctx context.Context, tx *gorm.DB, order
if result.RowsAffected == 0 {
return errors.New(errors.CodeExchangeStatusInvalid)
}
// 出库时间:换货后的新资产取换货完成时间(当前世代已有出库时间的不覆盖)
if err = s.silenceHook.OnNewAssetInTx(ctx, tx, order.NewAssetType, *order.NewAssetID, order, now); err != nil {
return err
}
orderBefore := map[string]any{"status": fromStatus, "migration_completed": order.MigrationCompleted, "migration_balance": order.MigrationBalance, "migration_status": beforeMigrationStatus}
order.Status = constants.ExchangeStatusCompleted
order.CompletedAt = &now