Files
junhong_cmp_fiber/internal/service/package/terms.go
break 4aaae07cee 修复错误消息含英文字段名:生效条件覆盖校验改为纯中文描述
AGENTS.md 要求用户可见的错误消息必须使用中文

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-23 11:23:13 +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, "生效条件覆盖字段未提交须显式传值null 或合法枚举)")
}
if value == nil {
return nil, nil
}
if *value != constants.PackageExpiryBaseFromActivation && *value != constants.PackageExpiryBaseFromPurchase {
return nil, errors.New(errors.CodeInvalidParam, "生效条件覆盖值非法,合法值为:购买即生效、实名激活时生效")
}
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)
}