内部加价分离, 不展示
This commit is contained in:
@@ -52,7 +52,6 @@ type PublishOptionsDTO struct {
|
||||
FireLevelMin int `json:"fire_level_min"`
|
||||
PriceConfig PublishPriceConfig `json:"price_config"`
|
||||
RatioConfig PublishRatioConfig `json:"ratio_config"`
|
||||
SalePriceConfig PublishSalePriceConfig `json:"sale_price_config"`
|
||||
}
|
||||
|
||||
type PublishOptionGroup struct {
|
||||
|
||||
@@ -36,6 +36,15 @@ func (h *Handler) PublishOptions(c *gin.Context) {
|
||||
response.OK(c, options)
|
||||
}
|
||||
|
||||
func (h *Handler) SalePriceConfig(c *gin.Context) {
|
||||
config, err := h.service.SalePriceConfig()
|
||||
if err != nil {
|
||||
writeConfigError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, config)
|
||||
}
|
||||
|
||||
func (h *Handler) HomeAnnouncements(c *gin.Context) {
|
||||
announcements, err := h.service.HomeAnnouncements()
|
||||
if err != nil {
|
||||
|
||||
@@ -108,22 +108,5 @@ func DefaultPublishOptions() PublishOptionsDTO {
|
||||
{ThresholdM: 530, Correction: 5},
|
||||
},
|
||||
},
|
||||
SalePriceConfig: PublishSalePriceConfig{
|
||||
FixedMarkupRules: []PublishSaleFixedMarkupRule{
|
||||
{MinM: 10, MaxM: 30, MarkupAmount: 28},
|
||||
{MinM: 30, MaxM: 50, MarkupAmount: 31},
|
||||
{MinM: 50, MaxM: 70, MarkupAmount: 34},
|
||||
{MinM: 70, MaxM: 90, MarkupAmount: 38},
|
||||
},
|
||||
RatioAdjustmentRules: []PublishSaleRatioAdjustmentRule{
|
||||
{MinM: 90, MaxM: 150, RatioSubtract: 5},
|
||||
{MinM: 150, MaxM: 230, RatioSubtract: 4},
|
||||
{MinM: 230, MaxM: 310, RatioSubtract: 3.5},
|
||||
{MinM: 310, MaxM: 390, RatioSubtract: 3},
|
||||
{MinM: 390, MaxM: 470, RatioSubtract: 0},
|
||||
{MinM: 470, MaxM: 550, RatioSubtract: 0},
|
||||
{MinM: 550, RatioSubtract: 0},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ var defaultConfigs = []defaultConfig{
|
||||
{Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"},
|
||||
{Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"},
|
||||
{Key: publishOptionsConfigKey, Value: defaultPublishOptionsConfigValue(), Description: "发布页选项配置 JSON"},
|
||||
{Key: salePriceConfigKey, Value: defaultSalePriceConfigValue(), Description: "内部出售定价规则 JSON"},
|
||||
}
|
||||
|
||||
func NewRepository(db *gorm.DB) *Repository {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package systemconfig
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
const salePriceConfigKey = "listing.sale_price_config"
|
||||
|
||||
func defaultSalePriceConfigValue() string {
|
||||
raw, err := json.Marshal(DefaultSalePriceConfig())
|
||||
if err != nil {
|
||||
return "{}"
|
||||
}
|
||||
return string(raw)
|
||||
}
|
||||
|
||||
func DefaultSalePriceConfig() PublishSalePriceConfig {
|
||||
return PublishSalePriceConfig{
|
||||
FixedMarkupRules: []PublishSaleFixedMarkupRule{
|
||||
{MinM: 10, MaxM: 30, MarkupAmount: 28},
|
||||
{MinM: 30, MaxM: 50, MarkupAmount: 31},
|
||||
{MinM: 50, MaxM: 70, MarkupAmount: 34},
|
||||
{MinM: 70, MaxM: 90, MarkupAmount: 38},
|
||||
},
|
||||
RatioAdjustmentRules: []PublishSaleRatioAdjustmentRule{
|
||||
{MinM: 90, MaxM: 150, RatioSubtract: 5},
|
||||
{MinM: 150, MaxM: 230, RatioSubtract: 4},
|
||||
{MinM: 230, MaxM: 310, RatioSubtract: 3.5},
|
||||
{MinM: 310, MaxM: 390, RatioSubtract: 3},
|
||||
{MinM: 390, MaxM: 470, RatioSubtract: 0},
|
||||
{MinM: 470, MaxM: 550, RatioSubtract: 0},
|
||||
{MinM: 550, RatioSubtract: 0},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,17 @@ func (s *Service) PublishOptions() (*PublishOptionsDTO, error) {
|
||||
return &options, nil
|
||||
}
|
||||
|
||||
func (s *Service) SalePriceConfig() (*PublishSalePriceConfig, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
config, err := s.salePriceConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func (s *Service) publishOptions() (PublishOptionsDTO, error) {
|
||||
value, err := s.repo.FindValue(publishOptionsConfigKey)
|
||||
if err != nil {
|
||||
@@ -50,6 +61,19 @@ func (s *Service) publishOptions() (PublishOptionsDTO, error) {
|
||||
return options, nil
|
||||
}
|
||||
|
||||
func (s *Service) salePriceConfig() (PublishSalePriceConfig, error) {
|
||||
value, err := s.repo.FindValue(salePriceConfigKey)
|
||||
if err != nil {
|
||||
return PublishSalePriceConfig{}, err
|
||||
}
|
||||
config := DefaultSalePriceConfig()
|
||||
if err := json.Unmarshal([]byte(value), &config); err != nil {
|
||||
config = DefaultSalePriceConfig()
|
||||
}
|
||||
normalizeSalePriceConfig(&config)
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func (s *Service) HomeAnnouncements() (*HomeAnnouncementsDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
@@ -214,10 +238,14 @@ func normalizePublishOptions(options *PublishOptionsDTO) {
|
||||
if len(options.RatioConfig.CoinCorrections) == 0 {
|
||||
options.RatioConfig.CoinCorrections = defaults.RatioConfig.CoinCorrections
|
||||
}
|
||||
if len(options.SalePriceConfig.FixedMarkupRules) == 0 {
|
||||
options.SalePriceConfig.FixedMarkupRules = defaults.SalePriceConfig.FixedMarkupRules
|
||||
}
|
||||
|
||||
func normalizeSalePriceConfig(config *PublishSalePriceConfig) {
|
||||
defaults := DefaultSalePriceConfig()
|
||||
if len(config.FixedMarkupRules) == 0 {
|
||||
config.FixedMarkupRules = defaults.FixedMarkupRules
|
||||
}
|
||||
if len(options.SalePriceConfig.RatioAdjustmentRules) == 0 {
|
||||
options.SalePriceConfig.RatioAdjustmentRules = defaults.SalePriceConfig.RatioAdjustmentRules
|
||||
if len(config.RatioAdjustmentRules) == 0 {
|
||||
config.RatioAdjustmentRules = defaults.RatioAdjustmentRules
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user