Files
yml2213 e024319860 feat(distribution): 分销站点消息中心与钱包提现多租户独立分支隔离
- 新增 000070 数据库迁移:支持 chat_conversations、wallet_accounts、wallet_ledger、withdrawal_requests 按 distribution_site_id 隔离
- 消息中心:会话列表、未读数统计、站点专属客服及订单群聊与主站实现双向完全隔离
- 资金账户与提现:独立按 (user_id, distribution_site_id) 建账,分销订单自动结算至对应分站钱包,提现与流水相互独立
- 前台界面:Axios 自动透传 X-Distribution-Site-Code,钱包、提现与消息页面呈现分站专属标牌与独立说明
2026-09-07 18:11:27 +08:00

107 lines
2.4 KiB
Go

package chat
import (
"hfb_sys/backend/pkg/response"
"github.com/gin-gonic/gin"
)
func (h *Handler) List(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
h.list(c, Principal{Type: "user", ID: userID})
}
func (h *Handler) UnreadCount(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
siteCode := parseSiteCode(c)
result, err := h.service.CountUnreadMessages(c.Request.Context(), Principal{Type: "user", ID: userID}, siteCode)
if err != nil {
writeChatError(c, err)
return
}
response.OK(c, result)
}
func (h *Handler) Detail(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
h.detail(c, Principal{Type: "user", ID: userID})
}
func (h *Handler) OrderConversation(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
orderID, ok := parseID(c, "id")
if !ok {
return
}
item, err := h.service.FindOrderConversation(c.Request.Context(), userID, orderID)
if err != nil {
writeChatError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) EnsureSupportConversation(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
var req EnsureSupportRequest
// scene 可选;空 body 仍按平台客服处理
_ = c.ShouldBindJSON(&req)
siteCode := parseSiteCode(c)
if siteCode == "" && req.DistributionSiteCode != "" {
siteCode = req.DistributionSiteCode
}
item, err := h.service.EnsureSupportConversation(c.Request.Context(), userID, req.Scene, siteCode)
if err != nil {
writeChatError(c, err)
return
}
response.OK(c, item)
}
func (h *Handler) Messages(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
h.messages(c, Principal{Type: "user", ID: userID})
}
func (h *Handler) Send(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
h.send(c, Principal{Type: "user", ID: userID})
}
func (h *Handler) MarkRead(c *gin.Context) {
userID, ok := currentUserID(c)
if !ok {
response.Unauthorized(c, "缺少用户上下文")
return
}
h.markRead(c, Principal{Type: "user", ID: userID})
}