增加客服分组管理
This commit is contained in:
@@ -34,9 +34,13 @@ type AdminConversationCountsDTO struct {
|
||||
func (r *Repository) TransferConversation(ctx context.Context, principal Principal, conversationID uint64, toAdminID uint64) error {
|
||||
return r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
// 验证当前操作者是会话参与者
|
||||
if _, err := r.findParticipant(tx, principal, conversationID, false); err != nil {
|
||||
current, err := r.findParticipant(tx, principal, conversationID, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if current.Role != "support" || current.ParticipantType != "admin" {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
// 验证目标客服存在、活跃且拥有客服角色,避免转接给超级管理员。
|
||||
if !adminIsSupport(tx, toAdminID) {
|
||||
return fmt.Errorf("目标客服不存在、已禁用或不是客服角色")
|
||||
@@ -51,20 +55,13 @@ func (r *Repository) TransferConversation(ctx context.Context, principal Princip
|
||||
if count > 0 {
|
||||
return fmt.Errorf("该客服已在会话中")
|
||||
}
|
||||
// 删除原客服参与者
|
||||
if err := tx.Where("conversation_id = ? AND participant_type = ? AND role = ?", conversationID, "admin", "support").
|
||||
Delete(&model.ChatParticipant{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// 添加新客服参与者
|
||||
participant := model.ChatParticipant{
|
||||
ConversationID: conversationID,
|
||||
ParticipantType: "admin",
|
||||
ParticipantID: toAdminID,
|
||||
Role: "support",
|
||||
JoinedAt: time.Now(),
|
||||
}
|
||||
if err := tx.Create(&participant).Error; err != nil {
|
||||
// 只转接当前客服本人,避免误删同群里的收号组/卖号组其他客服。
|
||||
if err := tx.Model(&model.ChatParticipant{}).
|
||||
Where("id = ?", current.ID).
|
||||
Updates(map[string]interface{}{
|
||||
"participant_id": toAdminID,
|
||||
"joined_at": time.Now(),
|
||||
}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// 添加系统消息记录转接
|
||||
|
||||
Reference in New Issue
Block a user