feat(distribution): 分站品牌装修可配置首页入口并上传图片
分站可单独配置回收、合作反馈和客服二维码,未配置时继承主站;Logo、图标和轮播支持直接上传。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,9 @@ package systemconfig
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
)
|
||||
|
||||
func (s *Service) HomeAnnouncements(ctx context.Context) (*HomeAnnouncementsDTO, error) {
|
||||
@@ -16,7 +19,7 @@ func (s *Service) HomeAnnouncements(ctx context.Context) (*HomeAnnouncementsDTO,
|
||||
return &HomeAnnouncementsDTO{Items: items}, nil
|
||||
}
|
||||
|
||||
func (s *Service) HomeConfig(ctx context.Context) (*HomeConfigDTO, error) {
|
||||
func (s *Service) HomeConfig(ctx context.Context, siteCode string) (*HomeConfigDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
@@ -40,13 +43,61 @@ func (s *Service) HomeConfig(ctx context.Context) (*HomeConfigDTO, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &HomeConfigDTO{
|
||||
config := &HomeConfigDTO{
|
||||
Announcements: announcements,
|
||||
Banners: banners,
|
||||
PublishOptions: publishOptions,
|
||||
AWRecycle: awRecycle,
|
||||
CooperationFeedback: cooperationFeedback,
|
||||
}, nil
|
||||
}
|
||||
s.applySiteHomeOverrides(ctx, siteCode, config)
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// applySiteHomeOverrides 用分站自己的首页入口覆盖主站配置。字段为空表示继续继承主站。
|
||||
func (s *Service) applySiteHomeOverrides(ctx context.Context, siteCode string, config *HomeConfigDTO) {
|
||||
siteCode = strings.TrimSpace(siteCode)
|
||||
if s == nil || s.repo == nil || s.repo.db == nil || config == nil || siteCode == "" {
|
||||
return
|
||||
}
|
||||
var site model.DistributionSite
|
||||
err := s.repo.db.WithContext(ctx).
|
||||
Select("aw_recycle_json", "cooperation_feedback_json").
|
||||
Where("site_code = ? AND status = ?", siteCode, "active").
|
||||
First(&site).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if item, ok := parseAWRecycleOverride(site.AWRecycleJSON); ok {
|
||||
config.AWRecycle = item
|
||||
}
|
||||
if item, ok := parseCooperationFeedbackOverride(site.CooperationFeedbackJSON); ok {
|
||||
config.CooperationFeedback = item
|
||||
}
|
||||
}
|
||||
|
||||
func parseAWRecycleOverride(raw string) (AWRecycleConfig, bool) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return AWRecycleConfig{}, false
|
||||
}
|
||||
var item AWRecycleConfig
|
||||
if err := json.Unmarshal([]byte(raw), &item); err != nil {
|
||||
return AWRecycleConfig{}, false
|
||||
}
|
||||
return normalizeAWRecycle(item), true
|
||||
}
|
||||
|
||||
func parseCooperationFeedbackOverride(raw string) (CooperationFeedbackConfig, bool) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return CooperationFeedbackConfig{}, false
|
||||
}
|
||||
var item CooperationFeedbackConfig
|
||||
if err := json.Unmarshal([]byte(raw), &item); err != nil {
|
||||
return CooperationFeedbackConfig{}, false
|
||||
}
|
||||
return normalizeCooperationFeedback(item), true
|
||||
}
|
||||
|
||||
func (s *Service) homeAnnouncements(ctx context.Context) ([]string, error) {
|
||||
|
||||
Reference in New Issue
Block a user