feat 修改子article的upsert

This commit is contained in:
timerzz 2024-09-04 14:30:15 +08:00
parent 047dbb0d7f
commit 4e3069f229
2 changed files with 16 additions and 4 deletions

View File

@ -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 {

View File

@ -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 {