Files
hfb_sys/backend/internal/modules/listing/service.go
T
yml2213 98174c0e33 feat(quality-owner): 增加优质号主、极品专区与无忧租号保险
- 支持保证金余额支付、在线支付开通及后台手动设置审计
- 新增极品专区发布权限、赔付方案与保险结算费率快照
- 优化首页、商品卡和个人中心的优质号主身份展示
2026-11-04 15:04:35 +08:00

100 lines
3.3 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 listing
import (
"context"
"errors"
"strings"
"time"
)
var (
ErrDependencyUnavailable = errors.New("dependency unavailable")
ErrInvalidInput = errors.New("invalid listing input")
ErrListingLocked = errors.New("listing locked")
ErrListingMustOfflineToEdit = errors.New("listing must be offline to edit")
ErrPublishCooldown = errors.New("listing publish cooldown")
ErrMissingTitle = errors.New("missing listing title")
ErrMissingServerRegion = errors.New("missing server region")
ErrInvalidPrice = errors.New("invalid listing price")
ErrInvalidDeposit = errors.New("invalid listing deposit")
ErrDepositTooLow = errors.New("listing deposit too low")
ErrInvalidHafCoin = errors.New("invalid haf coin amount")
ErrMissingScreenshot = errors.New("missing screenshot")
ErrMissingOnlineTime = errors.New("missing online time")
ErrInvalidOnlineTime = errors.New("invalid online time")
ErrAgreementRequired = errors.New("listing publish agreement required")
ErrTargetOwnerInvalid = errors.New("target owner invalid")
ErrMissingUploaderName = errors.New("missing uploader name")
ErrMissingUploadData = errors.New("missing upload data")
ErrUploaderNotFound = errors.New("uploader not found")
ErrUploaderAmbiguous = errors.New("uploader ambiguous")
ErrTooManyUploadItems = errors.New("too many upload items")
ErrExternalListingRequired = errors.New("external listing required")
ErrExternalAdjustment = errors.New("invalid external listing adjustment")
ErrSaleRatioOutOfRange = errors.New("sale ratio out of range")
ErrDistributionSiteInvalid = errors.New("invalid distribution site")
ErrPremiumOwnerRequired = errors.New("premium listing requires quality owner")
)
type Service struct {
repo *Repository
config ConfigReader
}
type ConfigReader interface {
FindValue(ctx context.Context, key string) (string, error)
}
const (
reviewRequiredConfigKey = "listing.review_required"
publishOptionsConfigKey = "listing.publish_options"
publishCooldownMinutesKey = "listing.publish_cooldown_minutes"
defaultFireLevelMin = 38
defaultPublishCooldownMinutes = 5
maxExternalUploadItems = 10
defaultUploadScreenshot = "/api/listings/default-upload-screenshot?v=webp1"
CompensationPlanNormal = "normal"
CompensationPlanInsurance = "insurance"
)
type PublishCooldownError struct {
Cooldown time.Duration
Remaining time.Duration
}
func (e PublishCooldownError) Error() string {
return ErrPublishCooldown.Error()
}
func (e PublishCooldownError) Is(target error) bool {
return target == ErrPublishCooldown
}
type FireLevelTooLowError struct {
Min int
}
func (e FireLevelTooLowError) Error() string {
return "fire level too low"
}
type UploadValidationError struct {
Missing []string
Invalid []string
}
func (e UploadValidationError) Error() string {
parts := make([]string, 0, 2)
if len(e.Missing) > 0 {
parts = append(parts, "缺少必填字段:"+strings.Join(e.Missing, "、"))
}
if len(e.Invalid) > 0 {
parts = append(parts, "字段格式不正确:"+strings.Join(e.Invalid, "、"))
}
return strings.Join(parts, ";")
}
func NewService(repo *Repository, config ConfigReader) *Service {
return &Service{repo: repo, config: config}
}