diff --git a/structs/storage/provider-article.go b/structs/storage/provider-article.go index 2e93f51..b548b2a 100644 --- a/structs/storage/provider-article.go +++ b/structs/storage/provider-article.go @@ -85,10 +85,16 @@ func (p *providerArticleApi) Get(query *GetProviderArticleQuery) (article v2.Pro } func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error { - return p.db.Clauses(clause.OnConflict{ + if err := p.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "provider_id"}, {Name: "sku_id"}}, DoUpdates: clause.AssignmentColumns([]string{"cost"}), - }).Create(&article).Error + }).Create(&article).Error; err != nil { + return err + } + if len(article.HistoryPrice) > 0 { + return p.db.Save(&article.HistoryPrice).Error + } + return nil } func (p *providerArticleApi) FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error { diff --git a/structs/storage/seller-article.go b/structs/storage/seller-article.go index 0b82592..cf0323d 100644 --- a/structs/storage/seller-article.go +++ b/structs/storage/seller-article.go @@ -81,10 +81,16 @@ func (p *sellerArticleApi) Get(query *GetSellerArticleQuery) (article v2.SellerA } func (p *sellerArticleApi) Upsert(article v2.SellerArticle) error { - return p.db.Clauses(clause.OnConflict{ + if err := p.db.Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "id"}}, DoUpdates: clause.AssignmentColumns([]string{"sell", "exclude"}), - }).Create(&article).Error + }).Create(&article).Error; err != nil { + return err + } + if len(article.HistoryPrice) > 0 { + return p.db.Save(&article.HistoryPrice).Error + } + return nil } func (p *sellerArticleApi) FindInBatches(query *GetSellerArticleQuery, results *[]v2.SellerArticle, f func(tx *gorm.DB, batch int) error) error {