修复 code review 问题:提取重复函数、补全缺失测试用例

- 提取 ResolveTermsFromTx 到 service/package,消除 order 和 auto_purchase 中的重复实现
- 补全 domain 测试:新增 from_activation 覆盖用例,现覆盖两种覆盖值
- 补全激活集成测试:新增 from_purchase 立即激活场景、历史记录兼容回退计数器验证
- 补全自动购包集成测试:新增购买后修改套餐配置不影响已有快照的验证

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-07-23 11:18:38 +09:00
parent 147f3eb775
commit 8dde55ea6d
6 changed files with 122 additions and 35 deletions

View File

@@ -2446,21 +2446,8 @@ func (s *Service) activateAddonPackage(ctx context.Context, tx *gorm.DB, order *
return nil
}
// resolvePackageTerms 在给定事务内查询分配覆盖并解析计时条款快照。
// 必须在事务内调用,确保分配读取与 PackageUsage 写入在同一连接,避免快照与提交值不一致。
func (s *Service) resolvePackageTerms(ctx context.Context, tx *gorm.DB, pkg *model.Package, sellerShopID *uint) (packagedomain.TermsSnapshot, error) {
var allocation *model.ShopPackageAllocation
if sellerShopID != nil && *sellerShopID > 0 {
store := postgres.NewShopPackageAllocationStore(tx)
found, err := store.GetByShopAndPackageForSystem(ctx, *sellerShopID, pkg.ID)
if err != nil && err != gorm.ErrRecordNotFound {
return packagedomain.TermsSnapshot{}, errors.Wrap(errors.CodeDatabaseError, err, "查询套餐分配失败")
}
if err == nil {
allocation = found
}
}
return packagedomain.ResolveTermsSnapshot(pkg, allocation)
return packagepkg.ResolveTermsFromTx(ctx, tx, pkg, sellerShopID)
}
func (s *Service) enqueueCommissionCalculation(ctx context.Context, orderID uint) {