93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package listing
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"hfb_sys/backend/internal/modules/systemconfig"
|
|
)
|
|
|
|
func (s *Service) reviewRequired(ctx context.Context) (bool, error) {
|
|
if s.config == nil {
|
|
return false, nil
|
|
}
|
|
value, err := s.config.FindValue(ctx, reviewRequiredConfigKey)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
required, err := strconv.ParseBool(strings.TrimSpace(value))
|
|
if err != nil {
|
|
return false, nil
|
|
}
|
|
return required, nil
|
|
}
|
|
|
|
// externalPublishOptions 读取发布页的实时配置,供外部上传的皮肤归类与消耗品折算使用。
|
|
//
|
|
// 外部上传只收平铺的皮肤名与数量,需要按后台配置(而不是代码里的快照)还原分组与单价,
|
|
// 否则运营在后台新增皮肤/改价后,上传的商品会落进“其他皮肤”且按旧价折算。
|
|
func (s *Service) externalPublishOptions(ctx context.Context) systemconfig.PublishOptionsDTO {
|
|
options := systemconfig.DefaultPublishOptions()
|
|
if s == nil || s.config == nil {
|
|
return options
|
|
}
|
|
value, err := s.config.FindValue(ctx, publishOptionsConfigKey)
|
|
if err != nil || strings.TrimSpace(value) == "" {
|
|
return options
|
|
}
|
|
var parsed systemconfig.PublishOptionsDTO
|
|
if err := json.Unmarshal([]byte(value), &parsed); err != nil {
|
|
return options
|
|
}
|
|
// 配置里只覆盖了一部分时,其余字段沿用默认值,避免整份配置失效。
|
|
if len(parsed.SkinGroups) > 0 {
|
|
options.SkinGroups = parsed.SkinGroups
|
|
}
|
|
if len(parsed.QuantityItems) > 0 {
|
|
options.QuantityItems = parsed.QuantityItems
|
|
}
|
|
return options
|
|
}
|
|
|
|
func (s *Service) publishRules(ctx context.Context) (publishRules, error) {
|
|
rules := publishRules{FireLevelMin: defaultFireLevelMin}
|
|
if s.config == nil {
|
|
return rules, nil
|
|
}
|
|
value, err := s.config.FindValue(ctx, publishOptionsConfigKey)
|
|
if err != nil {
|
|
return rules, err
|
|
}
|
|
var raw struct {
|
|
FireLevelMin int `json:"fire_level_min"`
|
|
}
|
|
if err := json.Unmarshal([]byte(value), &raw); err != nil {
|
|
return rules, nil
|
|
}
|
|
if raw.FireLevelMin > 0 {
|
|
rules.FireLevelMin = raw.FireLevelMin
|
|
}
|
|
return rules, nil
|
|
}
|
|
|
|
func (s *Service) publishCooldown(ctx context.Context) (time.Duration, error) {
|
|
if s.config == nil {
|
|
return time.Duration(defaultPublishCooldownMinutes) * time.Minute, nil
|
|
}
|
|
value, err := s.config.FindValue(ctx, publishCooldownMinutesKey)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
minutes, err := strconv.Atoi(strings.TrimSpace(value))
|
|
if err != nil {
|
|
return time.Duration(defaultPublishCooldownMinutes) * time.Minute, nil
|
|
}
|
|
if minutes <= 0 {
|
|
return 0, nil
|
|
}
|
|
return time.Duration(minutes) * time.Minute, nil
|
|
}
|