fix(order): 修复分销收号商品在主站租用后报订单不存在的问题

This commit is contained in:
yml2213
2026-09-09 15:24:56 +08:00
parent f6ad7c34ee
commit 02d091434e
7 changed files with 85 additions and 31 deletions
@@ -51,11 +51,11 @@ func (r *Repository) ListConversations(ctx context.Context, principal Principal,
if principal.Type == "user" {
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 = ?)))"
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))"
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)
}
+2 -2
View File
@@ -76,10 +76,10 @@ func (r *Repository) CountUnreadMessages(ctx context.Context, principal Principa
if principal.Type == "user" {
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 = ?)))"
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')))"
query = query.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))"
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'))"
query = query.Where(mainFilter)
}
}
+5 -1
View File
@@ -87,10 +87,14 @@ func EnsureOrderConversation(tx *gorm.DB, order model.RentalOrder) (*model.ChatC
return nil, err
}
var siteID *uint64
if order.DistributionSiteID != nil && *order.DistributionSiteID > 0 && order.DistributionMode != "two_party_distributor_receive" {
siteID = order.DistributionSiteID
}
now := time.Now()
conversation := model.ChatConversation{
OrderID: &order.ID,
DistributionSiteID: order.DistributionSiteID,
DistributionSiteID: siteID,
Type: "order_group",
Title: orderConversationTitle(order),
Status: "active",