feat: 接入旧站管理端并完整迁移后台能力
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"hfb_jysh/backend/internal/auditlog"
|
||||
"hfb_jysh/backend/internal/model"
|
||||
"hfb_jysh/backend/internal/modules/qualityowner"
|
||||
"hfb_jysh/backend/internal/modules/rentergrowth"
|
||||
smsnode "hfb_jysh/backend/internal/modules/sms"
|
||||
|
||||
@@ -39,6 +40,7 @@ var defaultConfigs = []defaultConfig{
|
||||
{Key: "order.return_overdue_grace_minutes", Value: "10", Description: "预计截止后结账宽限分钟数"},
|
||||
{Key: "listing.review_required", Value: "false", Description: "发布账号是否需要后台人工审核"},
|
||||
{Key: "listing.publish_cooldown_minutes", Value: "5", Description: "同一用户两次新增发布账号的最小间隔分钟数(0 表示关闭)"},
|
||||
{Key: qualityowner.ConfigKey, Value: qualityowner.DefaultConfigValue(), Description: "优质号主保证金、开通协议与无忧租号保险费率配置 JSON"},
|
||||
{Key: listingPublishAgreementsConfigKey, Value: defaultListingPublishAgreementsConfigValue(), Description: "发布账号前协议配置 JSON"},
|
||||
{Key: orderAgreementsConfigKey, Value: defaultOrderAgreementsConfigValue(), Description: "下单前协议配置 JSON"},
|
||||
{Key: postRentalNoticeConfigKey, Value: defaultPostRentalNoticeConfigValue(), Description: "租后须知配置 JSON"},
|
||||
@@ -89,6 +91,7 @@ var adminVisibleConfigKeys = []string{
|
||||
"order.pending_payment_timeout_minutes",
|
||||
"order.return_overdue_grace_minutes",
|
||||
"profile.post_rental_notice",
|
||||
qualityowner.ConfigKey,
|
||||
"renter.growth_level_rules",
|
||||
"sms.business_templates",
|
||||
}
|
||||
@@ -129,6 +132,12 @@ func (r *Repository) List(ctx context.Context) ([]ConfigDTO, error) {
|
||||
}
|
||||
items := make([]ConfigDTO, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
if row.Key == qualityowner.ConfigKey {
|
||||
rules, err := qualityowner.ParseConfigValue(row.Value)
|
||||
if err == nil {
|
||||
row.Value, _ = qualityowner.MarshalConfig(rules)
|
||||
}
|
||||
}
|
||||
items = append(items, toDTO(row))
|
||||
}
|
||||
return items, nil
|
||||
@@ -328,6 +337,15 @@ func normalizePublishOptionsValue(value string) (string, error) {
|
||||
if err := json.Unmarshal([]byte(value), &fields); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if !hasNestedJSONField(fields, "ratio_config", "quality_owner_ratio_discount") {
|
||||
options.RatioConfig.QualityOwnerRatioDiscount =
|
||||
DefaultPublishOptions().RatioConfig.QualityOwnerRatioDiscount
|
||||
}
|
||||
if !hasNestedJSONField(fields, "ratio_config", "premium_review_ratio_markup") {
|
||||
options.RatioConfig.PremiumReviewRatioMarkup =
|
||||
DefaultPublishOptions().RatioConfig.PremiumReviewRatioMarkup
|
||||
}
|
||||
originalVersion := options.SchemaVersion
|
||||
if options.SchemaVersion < publishOptionsSchemaVersion {
|
||||
if hasLegacyPublishQuantityItem(options.QuantityItems) {
|
||||
options = DefaultPublishOptions()
|
||||
@@ -340,6 +358,12 @@ func normalizePublishOptionsValue(value string) (string, error) {
|
||||
} else {
|
||||
normalizePublishOptions(&options)
|
||||
}
|
||||
// v2 一次性迁移:新增「是否解锁德穆兰」开关并默认关闭,同时打开「下赛季是否购买通行证」。
|
||||
// 已经是 v2 的配置不再覆盖,保留后台手动调整的结果。
|
||||
if originalVersion < 2 {
|
||||
options.UnlockDemulanEnabled = false
|
||||
options.NextSeasonPassEnabled = true
|
||||
}
|
||||
options.SchemaVersion = publishOptionsSchemaVersion
|
||||
raw, err := json.Marshal(options)
|
||||
if err != nil {
|
||||
@@ -348,6 +372,19 @@ func normalizePublishOptionsValue(value string) (string, error) {
|
||||
return string(raw), nil
|
||||
}
|
||||
|
||||
func hasNestedJSONField(fields map[string]json.RawMessage, parent, child string) bool {
|
||||
raw, ok := fields[parent]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
var nested map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &nested); err != nil {
|
||||
return false
|
||||
}
|
||||
_, ok = nested[child]
|
||||
return ok
|
||||
}
|
||||
|
||||
func hasLegacyPublishQuantityItem(items []PublishQuantityItem) bool {
|
||||
for _, item := range items {
|
||||
if item.Key == "kit5" {
|
||||
|
||||
Reference in New Issue
Block a user