fix(chat): 分销付款改为进入账号群,不再另建订单群
主站、分站和分站之间都只用发布时的账号群,二维码仍跟这个群走。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -28,6 +28,57 @@ func (r *Repository) resolveSite(ctx context.Context, siteCode string) (*model.D
|
||||
return &site, nil
|
||||
}
|
||||
|
||||
// userSiteConversationFilter 限制用户在当前站点能看到的会话。
|
||||
// 账号群只有一个:本站发布的群按站点归属显示;跨站成交时,租客在下单的站点也能看到这个群。
|
||||
func userSiteConversationFilter(siteID uint64, userID uint64) (string, []any) {
|
||||
if siteID > 0 {
|
||||
filter := `(
|
||||
c.distribution_site_id = ?
|
||||
OR (
|
||||
c.order_id IS NOT NULL
|
||||
AND c.order_id IN (
|
||||
SELECT ro.id FROM rental_orders ro
|
||||
WHERE ro.distribution_site_id = ?
|
||||
AND ro.distribution_mode != 'two_party_distributor_receive'
|
||||
)
|
||||
)
|
||||
OR (
|
||||
c.type = ?
|
||||
AND c.listing_id IN (
|
||||
SELECT ro.listing_id FROM rental_orders ro
|
||||
WHERE ro.distribution_site_id = ?
|
||||
AND ro.renter_id = ?
|
||||
AND ro.distribution_mode != 'two_party_distributor_receive'
|
||||
)
|
||||
)
|
||||
)`
|
||||
return filter, []any{siteID, siteID, ConversationTypeListingGroup, siteID, userID}
|
||||
}
|
||||
filter := `(
|
||||
(
|
||||
(c.distribution_site_id IS NULL OR c.distribution_site_id = 0)
|
||||
AND (
|
||||
c.order_id IS NULL
|
||||
OR c.order_id NOT IN (
|
||||
SELECT ro.id FROM rental_orders ro
|
||||
WHERE ro.distribution_site_id IS NOT NULL
|
||||
AND ro.distribution_site_id > 0
|
||||
AND ro.distribution_mode != 'two_party_distributor_receive'
|
||||
)
|
||||
)
|
||||
)
|
||||
OR (
|
||||
c.type = ?
|
||||
AND c.listing_id IN (
|
||||
SELECT ro.listing_id FROM rental_orders ro
|
||||
WHERE ro.renter_id = ?
|
||||
AND ro.distribution_mode = 'two_party_distributor_receive'
|
||||
)
|
||||
)
|
||||
)`
|
||||
return filter, []any{ConversationTypeListingGroup, userID}
|
||||
}
|
||||
|
||||
func (r *Repository) ListConversations(ctx context.Context, principal Principal, page, pageSize int, siteCode ...string) (*PaginatedResult, error) {
|
||||
page, pageSize = normalizePagination(page, pageSize)
|
||||
db := r.db.WithContext(ctx)
|
||||
@@ -50,15 +101,13 @@ func (r *Repository) ListConversations(ctx context.Context, principal Principal,
|
||||
Where("c.status = ?", "active")
|
||||
|
||||
if principal.Type == "user" {
|
||||
siteID := uint64(0)
|
||||
if site != nil {
|
||||
siteFilter := "(c.distribution_site_id = ? OR (c.order_id IS NOT NULL AND c.order_id IN (SELECT ro.id FROM rental_orders ro WHERE ro.distribution_site_id = ? AND ro.distribution_mode != 'two_party_distributor_receive')))"
|
||||
countDB = countDB.Where(siteFilter, site.ID, site.ID)
|
||||
dataQuery = dataQuery.Where(siteFilter, site.ID, site.ID)
|
||||
} else {
|
||||
mainFilter := "(c.distribution_site_id IS NULL OR c.distribution_site_id = 0) AND (c.order_id IS NULL OR c.order_id NOT IN (SELECT ro.id FROM rental_orders ro WHERE ro.distribution_site_id IS NOT NULL AND ro.distribution_site_id > 0 AND ro.distribution_mode != 'two_party_distributor_receive'))"
|
||||
countDB = countDB.Where(mainFilter)
|
||||
dataQuery = dataQuery.Where(mainFilter)
|
||||
siteID = site.ID
|
||||
}
|
||||
filter, args := userSiteConversationFilter(siteID, principal.ID)
|
||||
countDB = countDB.Where(filter, args...)
|
||||
dataQuery = dataQuery.Where(filter, args...)
|
||||
}
|
||||
|
||||
var total int64
|
||||
@@ -159,22 +208,6 @@ func (r *Repository) FindOrderConversation(ctx context.Context, userID uint64, o
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if order.DistributionSiteID != nil && *order.DistributionSiteID > 0 {
|
||||
var row conversationRow
|
||||
err := r.conversationQuery(ctx, principal).Where("c.order_id = ?", orderID).First(&row).Error
|
||||
if err == nil {
|
||||
participants, err := r.participants(ctx, row.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dto := row.toDTO(participants)
|
||||
return &dto, nil
|
||||
}
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if order.ListingID > 0 {
|
||||
var row conversationRow
|
||||
err := r.conversationQuery(ctx, principal).
|
||||
|
||||
Reference in New Issue
Block a user