二维码自动补发
This commit is contained in:
@@ -112,7 +112,7 @@ func EnsureListingConversation(tx *gorm.DB, listing model.RentalListing, preferr
|
||||
|
||||
// 6. 发二维码图片(如果有)
|
||||
if qrcodeImageURL != "" {
|
||||
if err := sendQrCodeImage(tx, conversation.ID, qrcodeImageURL); err != nil {
|
||||
if _, err := sendQrCodeImage(tx, conversation.ID, qrcodeImageURL); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
@@ -121,6 +121,9 @@ func EnsureListingConversation(tx *gorm.DB, listing model.RentalListing, preferr
|
||||
if err := sendSystemMessage(tx, conversation.ID, noQrTip); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := createQrCodeDeliveryTask(tx, conversation.ID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 7. 库存预警检查
|
||||
@@ -262,7 +265,7 @@ func sendSystemMessage(tx *gorm.DB, conversationID uint64, content string) error
|
||||
return updateConversationLastMessage(tx, conversationID, &message)
|
||||
}
|
||||
|
||||
func sendQrCodeImage(tx *gorm.DB, conversationID uint64, imageURL string) error {
|
||||
func sendQrCodeImage(tx *gorm.DB, conversationID uint64, imageURL string) (*model.ChatMessage, error) {
|
||||
content := "👇 请扫码加入企业微信群"
|
||||
|
||||
message := model.ChatMessage{
|
||||
@@ -275,11 +278,14 @@ func sendQrCodeImage(tx *gorm.DB, conversationID uint64, imageURL string) error
|
||||
}
|
||||
|
||||
if err := tx.Create(&message).Error; err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 更新会话的最后消息
|
||||
return updateConversationLastMessage(tx, conversationID, &message)
|
||||
if err := updateConversationLastMessage(tx, conversationID, &message); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &message, nil
|
||||
}
|
||||
|
||||
func updateConversationLastMessage(tx *gorm.DB, conversationID uint64, message *model.ChatMessage) error {
|
||||
@@ -326,6 +332,14 @@ func markQrCodeAsUsed(tx *gorm.DB, qrcodeID uint64, conversationID uint64) error
|
||||
}).Error
|
||||
}
|
||||
|
||||
func createQrCodeDeliveryTask(tx *gorm.DB, conversationID uint64) error {
|
||||
task := model.ChatQrCodeDeliveryTask{
|
||||
ConversationID: conversationID,
|
||||
Status: "pending",
|
||||
}
|
||||
return tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&task).Error
|
||||
}
|
||||
|
||||
// pushAlert 事务提交后需要发送的外部推送。
|
||||
type pushAlert struct {
|
||||
providers []push.Provider
|
||||
|
||||
Reference in New Issue
Block a user