增加客服分组管理
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/supportgroup"
|
||||
)
|
||||
|
||||
// 会话类型常量
|
||||
@@ -56,10 +57,16 @@ func EnsureListingConversation(tx *gorm.DB, listing model.RentalListing, preferr
|
||||
},
|
||||
}
|
||||
|
||||
// 获取客服。开放上传场景优先拉上传管理员,普通发布回退到默认客服。
|
||||
supportID := preferredSupportAdminID
|
||||
// 获取收号组客服。分组未配置时回退到开放上传管理员或默认客服。
|
||||
supportID, err := supportgroup.PickSupportAdmin(tx, supportgroup.GroupCodeOwnerOnboarding)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if supportID <= 0 {
|
||||
supportID = defaultSupportAdminID(tx)
|
||||
supportID = preferredSupportAdminID
|
||||
if supportID <= 0 {
|
||||
supportID = defaultSupportAdminID(tx)
|
||||
}
|
||||
}
|
||||
if supportID > 0 {
|
||||
participants = append(participants, model.ChatParticipant{
|
||||
@@ -123,7 +130,7 @@ func EnsureListingConversation(tx *gorm.DB, listing model.RentalListing, preferr
|
||||
return &conversation, nil
|
||||
}
|
||||
|
||||
// AddRenterToListingConversation 拉租客进发布群
|
||||
// AddRenterToListingConversation 拉租客与卖号组客服进发布群
|
||||
func AddRenterToListingConversation(tx *gorm.DB, listingID uint64, renterID uint64, orderNo string) error {
|
||||
// 1. 查找发布群
|
||||
var conv model.ChatConversation
|
||||
@@ -150,8 +157,29 @@ func AddRenterToListingConversation(tx *gorm.DB, listingID uint64, renterID uint
|
||||
return err
|
||||
}
|
||||
|
||||
// 3. 发系统消息
|
||||
// 3. 支付后由卖号组客服接入跟进交接和售后。
|
||||
handoffSupportID, err := supportgroup.PickSupportAdmin(tx, supportgroup.GroupCodeRenterHandoff)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if handoffSupportID > 0 {
|
||||
support := model.ChatParticipant{
|
||||
ConversationID: conv.ID,
|
||||
ParticipantType: "admin",
|
||||
ParticipantID: handoffSupportID,
|
||||
Role: "support",
|
||||
JoinedAt: now,
|
||||
}
|
||||
if err := tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&support).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 发系统消息
|
||||
message := "租客已加入群聊(订单 " + orderNo + ")"
|
||||
if handoffSupportID > 0 {
|
||||
message += ",卖号组客服已接入"
|
||||
}
|
||||
return sendSystemMessage(tx, conv.ID, message)
|
||||
}
|
||||
|
||||
|
||||
@@ -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