新增合作与反馈入口配置
This commit is contained in:
@@ -72,7 +72,8 @@ func (h *Handler) writeObject(c *gin.Context, publicOnly bool) {
|
||||
!strings.HasPrefix(key, "announcement/") &&
|
||||
!strings.HasPrefix(key, "mohong/") &&
|
||||
!strings.HasPrefix(key, "crash/") &&
|
||||
!strings.HasPrefix(key, "aw-recycle/") {
|
||||
!strings.HasPrefix(key, "aw-recycle/") &&
|
||||
!strings.HasPrefix(key, "cooperation-feedback/") {
|
||||
response.Error(c, http.StatusNotFound, "not_found", "文件不存在或暂不可访问")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func normalizeContentType(contentType string, data []byte) string {
|
||||
|
||||
func fileURLForScene(scene string, key string) string {
|
||||
fileURL := "/api/files/object?key=" + url.QueryEscape(key)
|
||||
if scene == "home-banner" || scene == "avatar" || scene == "payment-cert" || scene == "announcement" || scene == "mohong" || scene == "crash" || scene == "aw-recycle" {
|
||||
if scene == "home-banner" || scene == "avatar" || scene == "payment-cert" || scene == "announcement" || scene == "mohong" || scene == "crash" || scene == "aw-recycle" || scene == "cooperation-feedback" {
|
||||
fileURL = "/api/public/files/object?key=" + url.QueryEscape(key)
|
||||
}
|
||||
return fileURL
|
||||
@@ -115,7 +115,7 @@ func fileURLForScene(scene string, key string) string {
|
||||
func normalizeScene(scene string) string {
|
||||
scene = strings.TrimSpace(strings.ToLower(scene))
|
||||
switch scene {
|
||||
case "listing", "handoff", "dispute", "realname", "avatar", "home-banner", "chat", "payment-cert", "announcement", "qrcode", "mohong", "crash", "aw-recycle", "manual-disbursement":
|
||||
case "listing", "handoff", "dispute", "realname", "avatar", "home-banner", "chat", "payment-cert", "announcement", "qrcode", "mohong", "crash", "aw-recycle", "cooperation-feedback", "manual-disbursement":
|
||||
return scene
|
||||
default:
|
||||
return "misc"
|
||||
|
||||
@@ -40,3 +40,14 @@ func TestAWRecycleSceneUsesPublicFileURL(t *testing.T) {
|
||||
t.Fatalf("aw-recycle file url = %q, want public file endpoint", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCooperationFeedbackSceneUsesPublicFileURL(t *testing.T) {
|
||||
if got := normalizeScene("cooperation-feedback"); got != "cooperation-feedback" {
|
||||
t.Fatalf("normalize cooperation-feedback scene = %q", got)
|
||||
}
|
||||
key := "cooperation-feedback/2026/07/19/example.webp"
|
||||
got := fileURLForScene("cooperation-feedback", key)
|
||||
if !strings.HasPrefix(got, "/api/public/files/object?") {
|
||||
t.Fatalf("cooperation-feedback file url = %q, want public file endpoint", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package systemconfig
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const cooperationFeedbackConfigKey = "mobile.cooperation_feedback"
|
||||
|
||||
func defaultCooperationFeedback() CooperationFeedbackConfig {
|
||||
return CooperationFeedbackConfig{
|
||||
Title: "合作与反馈",
|
||||
Subtitle: "点击查看联系方式",
|
||||
ImageURL: "",
|
||||
Enabled: true,
|
||||
}
|
||||
}
|
||||
|
||||
func defaultCooperationFeedbackConfigValue() string {
|
||||
raw, err := json.Marshal(defaultCooperationFeedback())
|
||||
if err != nil {
|
||||
return `{"title":"合作与反馈","subtitle":"点击查看联系方式","image_url":"","enabled":true}`
|
||||
}
|
||||
return string(raw)
|
||||
}
|
||||
|
||||
func normalizeCooperationFeedback(item CooperationFeedbackConfig) CooperationFeedbackConfig {
|
||||
def := defaultCooperationFeedback()
|
||||
title := strings.TrimSpace(item.Title)
|
||||
if title == "" {
|
||||
title = def.Title
|
||||
}
|
||||
subtitle := strings.TrimSpace(item.Subtitle)
|
||||
if subtitle == "" {
|
||||
subtitle = def.Subtitle
|
||||
}
|
||||
return CooperationFeedbackConfig{
|
||||
Title: title,
|
||||
Subtitle: subtitle,
|
||||
ImageURL: strings.TrimSpace(item.ImageURL),
|
||||
Enabled: item.Enabled,
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,11 @@ type HomeAnnouncementsDTO struct {
|
||||
}
|
||||
|
||||
type HomeConfigDTO struct {
|
||||
Announcements []string `json:"announcements"`
|
||||
Banners []HomeBannerItem `json:"banners"`
|
||||
PublishOptions PublishOptionsDTO `json:"publish_options"`
|
||||
AWRecycle AWRecycleConfig `json:"aw_recycle"`
|
||||
Announcements []string `json:"announcements"`
|
||||
Banners []HomeBannerItem `json:"banners"`
|
||||
PublishOptions PublishOptionsDTO `json:"publish_options"`
|
||||
AWRecycle AWRecycleConfig `json:"aw_recycle"`
|
||||
CooperationFeedback CooperationFeedbackConfig `json:"cooperation_feedback"`
|
||||
}
|
||||
|
||||
// AWRecycleConfig 首页「AW炫彩回收」入口:点击展示可配置图片。
|
||||
@@ -36,6 +37,14 @@ type AWRecycleConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// CooperationFeedbackConfig 首页「合作与反馈」入口:点击展示可配置图片。
|
||||
type CooperationFeedbackConfig struct {
|
||||
Title string `json:"title"`
|
||||
Subtitle string `json:"subtitle"`
|
||||
ImageURL string `json:"image_url"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
type OrderAgreementsDTO struct {
|
||||
VirtualAssetPurchase AgreementContentDTO `json:"virtual_asset_purchase"`
|
||||
RenterAgreement AgreementContentDTO `json:"renter_agreement"`
|
||||
|
||||
@@ -48,6 +48,7 @@ var defaultConfigs = []defaultConfig{
|
||||
{Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"},
|
||||
{Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"},
|
||||
{Key: awRecycleConfigKey, Value: defaultAWRecycleConfigValue(), Description: "首页 AW炫彩回收入口配置 JSON(标题/副标题/展示图片)"},
|
||||
{Key: cooperationFeedbackConfigKey, Value: defaultCooperationFeedbackConfigValue(), Description: "首页 合作与反馈入口配置 JSON(标题/副标题/展示图片)"},
|
||||
{Key: publishOptionsConfigKey, Value: defaultPublishOptionsConfigValue(), Description: "发布页选项配置 JSON"},
|
||||
{Key: salePriceConfigKey, Value: defaultSalePriceConfigValue(), Description: "内部出售定价规则 JSON"},
|
||||
}
|
||||
@@ -71,6 +72,7 @@ var adminVisibleConfigKeys = []string{
|
||||
"mobile.home_announcements",
|
||||
"mobile.home_banners",
|
||||
"mobile.aw_recycle",
|
||||
"mobile.cooperation_feedback",
|
||||
"order.agreements",
|
||||
"order.pending_payment_timeout_minutes",
|
||||
"order.return_overdue_grace_minutes",
|
||||
|
||||
@@ -32,15 +32,20 @@ func (s *Service) HomeConfig(ctx context.Context) (*HomeConfigDTO, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cooperationFeedback, err := s.cooperationFeedback(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
publishOptions, err := s.publishOptions(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &HomeConfigDTO{
|
||||
Announcements: announcements,
|
||||
Banners: banners,
|
||||
PublishOptions: publishOptions,
|
||||
AWRecycle: awRecycle,
|
||||
Announcements: announcements,
|
||||
Banners: banners,
|
||||
PublishOptions: publishOptions,
|
||||
AWRecycle: awRecycle,
|
||||
CooperationFeedback: cooperationFeedback,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -79,3 +84,15 @@ func (s *Service) awRecycle(ctx context.Context) (AWRecycleConfig, error) {
|
||||
}
|
||||
return normalizeAWRecycle(item), nil
|
||||
}
|
||||
|
||||
func (s *Service) cooperationFeedback(ctx context.Context) (CooperationFeedbackConfig, error) {
|
||||
value, err := s.repo.FindValue(ctx, cooperationFeedbackConfigKey)
|
||||
if err != nil {
|
||||
return defaultCooperationFeedback(), err
|
||||
}
|
||||
item := defaultCooperationFeedback()
|
||||
if err := json.Unmarshal([]byte(value), &item); err != nil {
|
||||
item = defaultCooperationFeedback()
|
||||
}
|
||||
return normalizeCooperationFeedback(item), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user