提交2: 发布群核心功能实现

- 实现 EnsureListingConversation: 发布时建发布群,发欢迎语+二维码
- 实现 AddRenterToListingConversation: 付款后拉租客进群
- 实现 RemoveRenterFromListingConversation: 订单终态移出租客
- 实现消息可见性过滤: 租客只能看到 joined_at 之后的消息
- listing 模块注入 ListingChatCreator 接口,发布时建群
- ListingDTO 新增 listing_group_conversation_id 字段
- 付款流程改为拉租客进发布群(替代建订单群)
- 订单完成和取消时自动移出租客
- 创建 chat 适配器实现接口解耦

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
yml
2026-06-17 15:57:10 +08:00
co-authored by Claude Opus 4.8
parent 423c142967
commit ad70b24fb6
9 changed files with 446 additions and 39 deletions
+19 -3
View File
@@ -182,10 +182,18 @@ func (r *Repository) ConfirmPaidFromChannelTx(tx *gorm.DB, orderID uint64) (uint
order.HandoffStatus = handoffStatusPendingOwner
order.HandoffStartedAt = &now
markAssetsRented(listing, account)
conv, err := chat.EnsureOrderConversation(tx, *order)
if err != nil {
// 拉租客进发布群(替代原来的建订单群)
conversationID := uint64(0)
if err := chat.AddRenterToListingConversation(tx, listing.ID, order.RenterID, order.OrderNo); err != nil {
return 0, err
}
// 查询发布群ID用于返回
var listingConv model.ChatConversation
if err := tx.Where("listing_id = ?", listing.ID).First(&listingConv).Error; err == nil {
conversationID = listingConv.ID
}
if err := notification.Append(tx,
notification.Entry{
UserID: order.OwnerID,
@@ -215,7 +223,7 @@ func (r *Repository) ConfirmPaidFromChannelTx(tx *gorm.DB, orderID uint64) (uint
if err := tx.Save(account).Error; err != nil {
return 0, err
}
return conv.ID, nil
return conversationID, nil
}
func (r *Repository) Cancel(ctx context.Context, userID uint64, orderID uint64) error {
@@ -271,6 +279,14 @@ func (r *Repository) Cancel(ctx context.Context, userID uint64, orderID uint64)
if err := closePendingOrderPayments(tx, order.ID, "order_cancel"); err != nil {
return err
}
// 订单取消,移出租客(仅付款后取消需要移出)
if beforeStatus == orderStatusPendingHandoff {
if err := chat.RemoveRenterFromListingConversation(tx, listing.ID, order.RenterID); err != nil {
// 移出失败不阻塞订单取消
}
}
if err := tx.Save(&order).Error; err != nil {
return err
}