优化发布群配置与二维码池界面
This commit is contained in:
@@ -97,3 +97,23 @@ func (h *Handler) AdminUpdateAutoWelcome(c *gin.Context) {
|
||||
}
|
||||
response.OK(c, gin.H{"updated": true})
|
||||
}
|
||||
|
||||
func (h *Handler) AdminGetListingGroupWelcome(c *gin.Context) {
|
||||
message := h.service.GetListingGroupWelcomeMessage(c.Request.Context())
|
||||
response.OK(c, gin.H{"message": message})
|
||||
}
|
||||
|
||||
func (h *Handler) AdminUpdateListingGroupWelcome(c *gin.Context) {
|
||||
var req struct {
|
||||
Message string `json:"message" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "欢迎语内容不能为空")
|
||||
return
|
||||
}
|
||||
if err := h.service.UpdateListingGroupWelcomeMessage(c.Request.Context(), req.Message); err != nil {
|
||||
writeChatError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"updated": true})
|
||||
}
|
||||
|
||||
@@ -189,14 +189,12 @@ func listingConversationTitle(listing model.RentalListing) string {
|
||||
}
|
||||
|
||||
func getListingGroupWelcomeMessage(tx *gorm.DB) string {
|
||||
defaultMsg := "欢迎加入账号群!请号主扫描下方二维码加入企业微信群,方便客服与您及时联系。"
|
||||
|
||||
var cfg model.SystemConfig
|
||||
if err := tx.Where("`key` = ?", "chat.listing_group_welcome").First(&cfg).Error; err == nil && cfg.Value != "" {
|
||||
if err := tx.Where("`key` = ?", listingGroupWelcomeConfigKey).First(&cfg).Error; err == nil && cfg.Value != "" {
|
||||
return cfg.Value
|
||||
}
|
||||
|
||||
return defaultMsg
|
||||
return defaultListingGroupWelcome
|
||||
}
|
||||
|
||||
func sendSystemMessage(tx *gorm.DB, conversationID uint64, content string) error {
|
||||
@@ -218,7 +216,6 @@ func sendSystemMessage(tx *gorm.DB, conversationID uint64, content string) error
|
||||
}
|
||||
|
||||
func sendQrCodeImage(tx *gorm.DB, conversationID uint64, imageURL string) error {
|
||||
attachmentURLs := `["` + imageURL + `"]`
|
||||
content := "👇 请扫码加入企业微信群"
|
||||
|
||||
message := model.ChatMessage{
|
||||
@@ -227,7 +224,7 @@ func sendQrCodeImage(tx *gorm.DB, conversationID uint64, imageURL string) error
|
||||
SenderRole: "system",
|
||||
ContentType: "image",
|
||||
Content: content,
|
||||
AttachmentURLS: []byte(attachmentURLs),
|
||||
AttachmentURLS: encodeStringList([]string{imageURL}),
|
||||
}
|
||||
|
||||
if err := tx.Create(&message).Error; err != nil {
|
||||
|
||||
@@ -5,6 +5,13 @@ import (
|
||||
"hfb_sys/backend/internal/model"
|
||||
)
|
||||
|
||||
const (
|
||||
autoWelcomeConfigKey = "chat.auto_welcome_message"
|
||||
defaultAutoWelcomeMessage = "欢迎加入订单群聊!如有任何问题,请随时沟通。"
|
||||
listingGroupWelcomeConfigKey = "chat.listing_group_welcome"
|
||||
defaultListingGroupWelcome = "欢迎加入账号群!请号主扫描下方二维码加入企业微信群,方便客服与您及时联系。"
|
||||
)
|
||||
|
||||
func (r *Repository) UpdateRemark(ctx context.Context, principal Principal, conversationID uint64, remark string) error {
|
||||
return r.db.WithContext(ctx).Model(&model.ChatParticipant{}).
|
||||
Where("conversation_id = ? AND participant_type = ? AND participant_id = ?", conversationID, principal.Type, principal.ID).
|
||||
@@ -77,13 +84,27 @@ func (r *Repository) DeleteQuickReply(ctx context.Context, adminID uint64, reply
|
||||
}
|
||||
func (r *Repository) GetAutoWelcomeMessage(ctx context.Context) string {
|
||||
var cfg model.SystemConfig
|
||||
if err := r.db.WithContext(ctx).Where("`key` = ?", "chat.auto_welcome_message").First(&cfg).Error; err != nil {
|
||||
return "欢迎加入订单群聊!如有任何问题,请随时沟通。"
|
||||
if err := r.db.WithContext(ctx).Where("`key` = ?", autoWelcomeConfigKey).First(&cfg).Error; err != nil {
|
||||
return defaultAutoWelcomeMessage
|
||||
}
|
||||
return cfg.Value
|
||||
}
|
||||
func (r *Repository) UpdateAutoWelcomeMessage(ctx context.Context, message string) error {
|
||||
return r.db.WithContext(ctx).Model(&model.SystemConfig{}).
|
||||
Where("`key` = ?", "chat.auto_welcome_message").
|
||||
Where("`key` = ?", autoWelcomeConfigKey).
|
||||
Update("value", message).Error
|
||||
}
|
||||
|
||||
func (r *Repository) GetListingGroupWelcomeMessage(ctx context.Context) string {
|
||||
var cfg model.SystemConfig
|
||||
if err := r.db.WithContext(ctx).Where("`key` = ?", listingGroupWelcomeConfigKey).First(&cfg).Error; err != nil {
|
||||
return defaultListingGroupWelcome
|
||||
}
|
||||
return cfg.Value
|
||||
}
|
||||
|
||||
func (r *Repository) UpdateListingGroupWelcomeMessage(ctx context.Context, message string) error {
|
||||
return r.db.WithContext(ctx).Model(&model.SystemConfig{}).
|
||||
Where("`key` = ?", listingGroupWelcomeConfigKey).
|
||||
Update("value", message).Error
|
||||
}
|
||||
|
||||
@@ -208,3 +208,17 @@ func (s *Service) UpdateAutoWelcomeMessage(ctx context.Context, message string)
|
||||
}
|
||||
return s.repo.UpdateAutoWelcomeMessage(ctx, message)
|
||||
}
|
||||
|
||||
func (s *Service) GetListingGroupWelcomeMessage(ctx context.Context) string {
|
||||
if s.repo == nil {
|
||||
return ""
|
||||
}
|
||||
return s.repo.GetListingGroupWelcomeMessage(ctx)
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListingGroupWelcomeMessage(ctx context.Context, message string) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.UpdateListingGroupWelcomeMessage(ctx, message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user