feat(distribution): 站内信与通知体系多租户独立分支隔离
- 新增 000071 数据库迁移:notifications 表支持 distribution_site_id 并自动回填历史分销订单通知 - 通知自动归属:在事务内根据订单或申诉自动关联当前分销站点 ID - 隔离查询与已读控制:列表、未读统计与批量已读均严格按站点隔离,防止主站与分站交叉泄漏 - 前台界面联动:消息中心通知 Tab 及移动端/PC端站内信页面展示分站专属标识与精准过滤
This commit is contained in:
@@ -40,7 +40,8 @@ func (h *Handler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
page, pageSize := parsePagination(c)
|
||||
result, err := h.service.List(c.Request.Context(), userID, page, pageSize)
|
||||
siteCode := parseSiteCode(c)
|
||||
result, err := h.service.List(c.Request.Context(), userID, page, pageSize, siteCode)
|
||||
if err != nil {
|
||||
writeNotificationError(c, err)
|
||||
return
|
||||
@@ -54,7 +55,8 @@ func (h *Handler) UnreadCount(c *gin.Context) {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
result, err := h.service.UnreadCount(c.Request.Context(), userID)
|
||||
siteCode := parseSiteCode(c)
|
||||
result, err := h.service.UnreadCount(c.Request.Context(), userID, siteCode)
|
||||
if err != nil {
|
||||
writeNotificationError(c, err)
|
||||
return
|
||||
@@ -68,7 +70,8 @@ func (h *Handler) MarkAllRead(c *gin.Context) {
|
||||
response.Unauthorized(c, "缺少用户上下文")
|
||||
return
|
||||
}
|
||||
count, err := h.service.MarkAllRead(c.Request.Context(), userID)
|
||||
siteCode := parseSiteCode(c)
|
||||
count, err := h.service.MarkAllRead(c.Request.Context(), userID, siteCode)
|
||||
if err != nil {
|
||||
writeNotificationError(c, err)
|
||||
return
|
||||
@@ -87,13 +90,28 @@ func (h *Handler) MarkRead(c *gin.Context) {
|
||||
response.BadRequest(c, "ID 不正确")
|
||||
return
|
||||
}
|
||||
if err := h.service.MarkRead(c.Request.Context(), userID, id); err != nil {
|
||||
siteCode := parseSiteCode(c)
|
||||
if err := h.service.MarkRead(c.Request.Context(), userID, id, siteCode); err != nil {
|
||||
writeNotificationError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"read": true})
|
||||
}
|
||||
|
||||
func parseSiteCode(c *gin.Context) string {
|
||||
siteCode := c.Query("distribution_site_code")
|
||||
if siteCode == "" {
|
||||
siteCode = c.Query("site_code")
|
||||
}
|
||||
if siteCode == "" {
|
||||
siteCode = c.GetHeader("X-Distribution-Site-Code")
|
||||
}
|
||||
if siteCode == "" {
|
||||
siteCode = c.GetHeader("X-Site-Code")
|
||||
}
|
||||
return siteCode
|
||||
}
|
||||
|
||||
func currentUserID(c *gin.Context) (uint64, bool) {
|
||||
value, ok := c.Get(middleware.ContextUserID)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user