修正默认客服分配逻辑

This commit is contained in:
yml2213
2026-06-08 06:35:56 +08:00
parent ebf9b95f5a
commit 9d6b1d945c
3 changed files with 50 additions and 60 deletions
@@ -34,7 +34,7 @@ var defaultConfigs = []defaultConfig{
{Key: listingPublishAgreementsConfigKey, Value: defaultListingPublishAgreementsConfigValue(), Description: "发布账号前协议配置 JSON"},
{Key: orderAgreementsConfigKey, Value: defaultOrderAgreementsConfigValue(), Description: "下单前协议配置 JSON"},
{Key: postRentalNoticeConfigKey, Value: defaultPostRentalNoticeConfigValue(), Description: "租后须知配置 JSON"},
{Key: "chat.default_support_admin_id", Value: "1", Description: "订单群聊回退客服 ID(仅当无可用客服时使用"},
{Key: "chat.default_support_admin_id", Value: "2", Description: "默认客服 ID(必须是启用状态的客服角色"},
{Key: "chat.auto_welcome_message", Value: "欢迎加入订单群聊!如有任何问题,请随时沟通。", Description: "建群后自动发送的欢迎话术"},
{Key: homeAnnouncementsConfigKey, Value: defaultHomeAnnouncementsConfigValue(), Description: "移动端首页公告 JSON 数组"},
{Key: homeBannersConfigKey, Value: defaultHomeBannersConfigValue(), Description: "移动端首页轮播图 JSON 数组"},
@@ -150,7 +150,7 @@ func (r *Repository) ensureDefaults() error {
return err
}
if item.Key == "chat.default_support_admin_id" {
if err := updateDefaultDescription(tx, item); err != nil {
if err := updateDefaultSupportConfig(tx, item); err != nil {
return err
}
}
@@ -164,15 +164,23 @@ func (r *Repository) ensureDefaults() error {
})
}
func updateDefaultDescription(tx *gorm.DB, item defaultConfig) error {
func updateDefaultSupportConfig(tx *gorm.DB, item defaultConfig) error {
var row model.SystemConfig
if err := tx.Where("`key` = ?", item.Key).First(&row).Error; err != nil {
return err
}
if row.Description == item.Description {
changed := false
if strings.TrimSpace(row.Value) == "1" {
row.Value = item.Value
changed = true
}
if row.Description != item.Description {
row.Description = item.Description
changed = true
}
if !changed {
return nil
}
row.Description = item.Description
return tx.Save(&row).Error
}