Files
junhong_cmp_fiber/internal/service/package/terms.go
break f7e0f07692 修复 code review 问题:DTO 内部字段、错误消息、重复代码与测试覆盖
- 删除 ExpiryBaseOverrideSet 字段的 description 标签(json:"-" 内部字段不进文档)
- ValidateExpiryBaseOverride 两处 CodeInvalidParam 补充中文错误消息
- 提取 initPackageExpiryBaseFields 消除 toResponse/toResponseWithAllocation 中的重复初始化
- 删除 order/service.go 中"行业卡永远直接激活"过时注释
- 补充 T01 系列授权 HTTP 集成测试(Create + ManagePackages 两个入口)
- 补充 T03 C 端购买和平台代购(无分配)快照集成测试
- 补充 T04 from_purchase 默认值、卡未实名仍立即激活的自动购包测试
- 新增 testutil.NewRedisClient 供激活接续测试使用

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 10:56:46 +09:00

50 lines
1.6 KiB
Go
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.
package packagepkg
import (
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
)
// ValidateExpiryBaseOverride 校验显式提交的分配生效条件覆盖。
func ValidateExpiryBaseOverride(value *string, submitted bool) (*string, error) {
if !submitted {
return nil, errors.New(errors.CodeInvalidParam, "expiry_base_override 字段未提交须显式传值null 或合法枚举)")
}
if value == nil {
return nil, nil
}
if *value != constants.PackageExpiryBaseFromActivation && *value != constants.PackageExpiryBaseFromPurchase {
return nil, errors.New(errors.CodeInvalidParam, "expiry_base_override 枚举值非法合法值from_activation, from_purchase")
}
return value, nil
}
// EffectiveExpiryBase 返回套餐分配最终采用的生效条件。
func EffectiveExpiryBase(pkg *model.Package, allocation *model.ShopPackageAllocation) string {
if allocation != nil && allocation.ExpiryBaseOverride != nil {
return *allocation.ExpiryBaseOverride
}
return pkg.ExpiryBase
}
// ExpiryBaseName 返回生效条件中文名称。
func ExpiryBaseName(value string) string {
switch value {
case constants.PackageExpiryBaseFromActivation:
return "实名激活时生效"
case constants.PackageExpiryBaseFromPurchase:
return "购买即生效"
default:
return "未知"
}
}
// ExpiryBaseOverrideName 返回覆盖值中文名称,空值表示跟随套餐默认。
func ExpiryBaseOverrideName(value *string) string {
if value == nil {
return "跟随套餐默认"
}
return ExpiryBaseName(*value)
}