feat(distribution): 公告中心支持分站自定义

公告中心(前台公告列表/详情)此前完全没有站点概念,分站访客只能看到主站公告。
本次按「默认继承主站、站长可切仅本站」的口径支持分站自定义。

数据与口径:
- 新增 announcements.distribution_site_id(0=主站),前台按站点隔离
- 新增 distribution_sites.announcement_mode:inherit(默认,主站+本站)/ own_only(仅本站)

后端:
- 公告模块新增 ResolvePublicSiteScope:主站 [0]、inherit [0, siteID]、own_only [siteID],
  站点编码无效/已停用回落主站;列表与详情都按该范围过滤,详情不再允许跨站按 ID 读取
- 管理端公告列表支持按站点筛选(site_id:不传=全部,0=主站,>0=分站)并带出站点名
- 分销模块新增本站公告 CRUD(distribution/announcement.go):强制 distribution_site_id=本站,
  先过 ensureSiteAccess,跨站更新/删除/上下架一律 ErrAnnouncementNotFound
- UpdateSiteBranding 支持 announcement_mode 切换(非法值报错,读侧非法历史值回落 inherit)
- 新增权限 distribution:announcement_view|manage 并授予 super_admin/ops/finance,
  站长开通时继承 ops 角色即自动获得
- 路由:站长侧 /api/distribution/announcements*,平台侧 /api/admin/distribution/announcements*

前端:
- 分销后台新增「公告中心」页:来源开关(继承主站+本站 / 仅本站)、本站公告列表与
  新建/编辑/发布/下架/归档/恢复/删除,空态按来源模式给出引导
- 平台后台公告页新增「站点」列与筛选,新建公告可选择归属站点(主站或指定分站代发)
- 前台 PC/移动无需改动:请求已带 X-Distribution-Site-Code,后端按站点隔离,页面已有空态

测试:
- 公告模块:主站/继承/仅本站三种可见范围、跨站详情拦截、无效站点回落、管理端站点筛选
- 分销模块:本站公告 CRUD 与跨站防护、公告来源开关校验与非法值容错
This commit is contained in:
yml2213
2026-10-01 10:02:31 +08:00
parent 329d0f75bb
commit 2a76d59a30
24 changed files with 1676 additions and 88 deletions
+46 -1
View File
@@ -17,6 +17,7 @@ type SiteDTO struct {
AWRecycleJSON string `json:"aw_recycle_json"`
CooperationFeedbackJSON string `json:"cooperation_feedback_json"`
StorefrontTextJSON string `json:"storefront_text_json"`
AnnouncementMode string `json:"announcement_mode"`
DefaultSupportGroupID *uint64 `json:"default_support_group_id,omitempty"`
ListingQrcodeURL string `json:"listing_qrcode_url"`
ReceiveRatioDelta float64 `json:"receive_ratio_delta"`
@@ -431,7 +432,51 @@ type UpdateSiteBrandingRequest struct {
AWRecycleJSON *string `json:"aw_recycle_json"`
CooperationFeedbackJSON *string `json:"cooperation_feedback_json"`
StorefrontTextJSON *string `json:"storefront_text_json"`
ListingQrcodeURL *string `json:"listing_qrcode_url"`
// AnnouncementMode 公告中心来源:inherit(主站+本站)/ own_only(仅本站)。
AnnouncementMode *string `json:"announcement_mode"`
ListingQrcodeURL *string `json:"listing_qrcode_url"`
}
// SiteAnnouncementDTO 分站公告(站长自助维护)。
type SiteAnnouncementDTO struct {
ID uint64 `json:"id"`
DistributionSiteID uint64 `json:"distribution_site_id"`
Title string `json:"title"`
Content string `json:"content"`
Category string `json:"category"`
Priority int `json:"priority"`
IsPinned bool `json:"is_pinned"`
IsImportant bool `json:"is_important"`
ViewCount int `json:"view_count"`
Status string `json:"status"`
PublishedAt *time.Time `json:"published_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type SiteAnnouncementPage struct {
Items []SiteAnnouncementDTO `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
type CreateSiteAnnouncementRequest struct {
Title string `json:"title" binding:"required,max=255"`
Content string `json:"content" binding:"required"`
Category string `json:"category" binding:"omitempty,oneof=notice tutorial rule faq"`
Priority int `json:"priority"`
IsPinned bool `json:"is_pinned"`
IsImportant bool `json:"is_important"`
}
type UpdateSiteAnnouncementRequest struct {
Title string `json:"title" binding:"max=255"`
Content string `json:"content"`
Category string `json:"category" binding:"omitempty,oneof=notice tutorial rule faq"`
Priority int `json:"priority"`
IsPinned bool `json:"is_pinned"`
IsImportant bool `json:"is_important"`
}
// 自主加价 DTO:增加该站「1 元兑换哈夫币」比例,不是人民币。