优化发布界面
This commit is contained in:
@@ -3,6 +3,7 @@ package systemconfig
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
@@ -132,11 +133,54 @@ func (r *Repository) ensureDefaults() error {
|
||||
if err := tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&row).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if item.Key == publishOptionsConfigKey {
|
||||
if err := updateLegacyPublishOptions(tx, item); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func updateLegacyPublishOptions(tx *gorm.DB, item defaultConfig) error {
|
||||
var row model.SystemConfig
|
||||
if err := tx.Where("`key` = ?", item.Key).First(&row).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if !isLegacyPublishOptionsValue(row.Value) {
|
||||
return nil
|
||||
}
|
||||
row.Value = item.Value
|
||||
row.Description = item.Description
|
||||
return tx.Save(&row).Error
|
||||
}
|
||||
|
||||
func isLegacyPublishOptionsValue(value string) bool {
|
||||
legacyMarkers := []string{
|
||||
`"kit5"`,
|
||||
"5级全装套",
|
||||
"6级子弹",
|
||||
"6头数量",
|
||||
"6甲数量",
|
||||
"0.26元/发",
|
||||
"0.8元/发",
|
||||
"çº",
|
||||
"å¼",
|
||||
"å…",
|
||||
"å¤",
|
||||
"ä½",
|
||||
"é«",
|
||||
"ï¼",
|
||||
}
|
||||
for _, marker := range legacyMarkers {
|
||||
if strings.Contains(value, marker) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizID uint64, meta AuditMeta, detail map[string]any) error {
|
||||
raw, err := json.Marshal(detail)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user