feat: 客服封存订单功能(号主失联场景)
新增客服「封存订单」动作,用于号主失联、无法联系的场景:单事务内 完成关闭订单、全量原路退款、永久封存关联商品、解散发布群、双方通知 与审计日志。 - 新增 listing 终态 sealed(封存),区别于可恢复的 offline - listingLockedForOwnerMutation 锁定 sealed,号主无法再编辑/提审/上架 - 解散群聊按 listing_id 查发布群(listing_group)置 archived, 阻断所有成员发言并留系统消息 - 新增 order.AdminSeal 及 /admin/orders/:id/seal 路由 - 前端:卖家页 PC/移动端 sealed 视为终态禁用操作,客服后台新增 「封存订单」按钮与二次确认 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
8a11c2517e
commit
be5d322c10
@@ -22,3 +22,17 @@ func (a *ListingChatCreatorAdapter) EnsureListingConversation(tx *gorm.DB, listi
|
||||
}
|
||||
return conv.ID, nil
|
||||
}
|
||||
|
||||
// OrderChatArchiverAdapter 适配器,实现 order.OrderChatArchiver 接口,
|
||||
// 供订单封存时在同一事务内解散关联的发布群。
|
||||
type OrderChatArchiverAdapter struct{}
|
||||
|
||||
func NewOrderChatArchiverAdapter() *OrderChatArchiverAdapter {
|
||||
return &OrderChatArchiverAdapter{}
|
||||
}
|
||||
|
||||
// ArchiveListingConversation 将商品关联的发布群标记为已归档(解散),
|
||||
// 写入一条系统消息提示群聊已被客服解散。会话不存在时静默跳过。
|
||||
func (a *OrderChatArchiverAdapter) ArchiveListingConversation(tx *gorm.DB, listingID uint64, reason string) error {
|
||||
return ArchiveListingConversation(tx, listingID, reason)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package chat
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hfb_sys/backend/internal/model"
|
||||
@@ -366,3 +367,30 @@ func applyAdminChatStageFilter(db *gorm.DB, stage string, principal Principal) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// ArchiveListingConversation 将商品关联的发布群标记为已归档(解散),并写入系统提示。
|
||||
// 用于客服封存订单时同事务解散群聊;发布群不存在时静默跳过,不阻断封存流程。
|
||||
// 归档后 SendMessage 的 status 校验会阻断所有成员继续发言。
|
||||
func ArchiveListingConversation(tx *gorm.DB, listingID uint64, reason string) error {
|
||||
var conversation model.ChatConversation
|
||||
err := tx.Where("listing_id = ?", listingID).First(&conversation).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if conversation.Status == "archived" {
|
||||
return nil
|
||||
}
|
||||
if err := tx.Model(&model.ChatConversation{}).
|
||||
Where("id = ?", conversation.ID).
|
||||
Update("status", "archived").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
content := "群聊已由客服解散,订单已封存。"
|
||||
if trimmed := strings.TrimSpace(reason); trimmed != "" {
|
||||
content += "原因:" + trimmed
|
||||
}
|
||||
return sendSystemMessage(tx, conversation.ID, content)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user