- 实现 EnsureListingConversation: 发布时建发布群,发欢迎语+二维码 - 实现 AddRenterToListingConversation: 付款后拉租客进群 - 实现 RemoveRenterFromListingConversation: 订单终态移出租客 - 实现消息可见性过滤: 租客只能看到 joined_at 之后的消息 - listing 模块注入 ListingChatCreator 接口,发布时建群 - ListingDTO 新增 listing_group_conversation_id 字段 - 付款流程改为拉租客进发布群(替代建订单群) - 订单完成和取消时自动移出租客 - 创建 chat 适配器实现接口解耦 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package listing
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
"hfb_sys/backend/internal/model"
|
|
)
|
|
|
|
// ListingChatCreator 发布群创建接口(由 chat 模块实现,避免直接依赖)
|
|
type ListingChatCreator interface {
|
|
EnsureListingConversation(tx *gorm.DB, listing model.RentalListing) (conversationID uint64, err error)
|
|
}
|
|
|
|
type Repository struct {
|
|
db *gorm.DB
|
|
publicZoneCountsMu sync.Mutex
|
|
publicZoneCounts publicZoneCountCache
|
|
chatCreator ListingChatCreator
|
|
}
|
|
|
|
func NewRepository(db *gorm.DB, chatCreator ListingChatCreator) *Repository {
|
|
return &Repository{
|
|
db: db,
|
|
chatCreator: chatCreator,
|
|
}
|
|
}
|
|
|
|
type publicZoneCountCache struct {
|
|
Counts map[string]int64
|
|
ExpiresAt time.Time
|
|
}
|
|
|
|
const publicZoneCountCacheTTL = 5 * time.Second
|
|
|
|
func initialPublishState(reviewRequired bool) (string, string, *time.Time) {
|
|
if reviewRequired {
|
|
return "draft", "pending", nil
|
|
}
|
|
now := time.Now()
|
|
return "published", "approved", &now
|
|
}
|
|
|
|
func IsNotFound(err error) bool {
|
|
return errors.Is(err, gorm.ErrRecordNotFound)
|
|
}
|
|
|
|
// roundMoney 使用统一的角精度(0.1元)
|