feat(tenant): 增加双站共享货架与跨站下单
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
// ListingChatCreator 发布群创建接口(由 chat 模块实现,避免直接依赖)
|
||||
@@ -49,13 +51,50 @@ func (r *Repository) SetShelfSyncer(syncer ListingShelfSyncer) {
|
||||
// syncPublishedShelf 只在商品真正对外可售(published + approved)时铺货到各分站货架。
|
||||
// 草稿、待审核、已下架商品不需要铺货:分站前台本身就要求 published + approved 才展示。
|
||||
func (r *Repository) syncPublishedShelf(tx *gorm.DB, listing *model.RentalListing) error {
|
||||
if r == nil || r.shelfSyncer == nil || listing == nil {
|
||||
if r == nil || listing == nil {
|
||||
return nil
|
||||
}
|
||||
if listing.Status != "published" || listing.ReviewStatus != "approved" {
|
||||
return nil
|
||||
}
|
||||
return r.shelfSyncer.EnsureListingShelvedTx(tx, listing.ID, listing.AccountID)
|
||||
if r.shelfSyncer != nil {
|
||||
if err := r.shelfSyncer.EnsureListingShelvedTx(tx, listing.ID, listing.AccountID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.ensureTenantListingOffersTx(tx, listing.ID)
|
||||
}
|
||||
|
||||
func (r *Repository) ensureTenantListingOffersTx(tx *gorm.DB, listingID uint64) error {
|
||||
if tx == nil || listingID == 0 {
|
||||
return nil
|
||||
}
|
||||
var tenantIDs []uint64
|
||||
if err := tx.Model(&model.Tenant{}).
|
||||
Where("status = ?", "active").
|
||||
Pluck("id", &tenantIDs).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if len(tenantIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
offers := make([]model.TenantListingOffer, 0, len(tenantIDs))
|
||||
for _, tenantID := range tenantIDs {
|
||||
offers = append(offers, model.TenantListingOffer{
|
||||
TenantID: tenantID,
|
||||
ListingID: listingID,
|
||||
DisplayStatus: "enabled",
|
||||
})
|
||||
}
|
||||
return tx.Clauses(clause.OnConflict{DoNothing: true}).Create(&offers).Error
|
||||
}
|
||||
|
||||
func userTenantID(ctx context.Context, tx *gorm.DB, userID uint64) uint64 {
|
||||
var tenantID uint64
|
||||
if err := tx.Model(&model.User{}).Select("tenant_id").Where("id = ?", userID).Scan(&tenantID).Error; err == nil && tenantID > 0 {
|
||||
return tenantID
|
||||
}
|
||||
return tenancy.IDFromContext(ctx)
|
||||
}
|
||||
|
||||
func (r *Repository) IsQualityOwner(ctx context.Context, userID uint64) (bool, error) {
|
||||
|
||||
Reference in New Issue
Block a user