Compare commits

...

2 Commits

Author SHA1 Message Date
566d95bc0f feat 供应商商品添加更新状态 2024-11-19 14:57:55 +08:00
217039202d feat 更新provider article时,更新库存 2024-11-19 14:51:38 +08:00

View File

@ -15,6 +15,7 @@ type ProviderArticleApi interface {
AutoMigrate() error
FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error
ProviderPrice(providerArticleID uint) (history []v2.ProviderPrice, err error)
UpdateStatus(article v2.ProviderArticle) error
}
type providerArticleApi struct {
@ -89,7 +90,7 @@ func (p *providerArticleApi) Get(query *GetProviderArticleQuery) (article v2.Pro
func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
if err := p.db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "provider_id"}, {Name: "sku_id"}},
DoUpdates: clause.AssignmentColumns([]string{"cost", "available", "updated_at"}),
DoUpdates: clause.AssignmentColumns([]string{"cost", "available", "updated_at", "ast"}),
}).Create(&article).Error; err != nil {
return err
}
@ -98,6 +99,9 @@ func (p *providerArticleApi) Upsert(article v2.ProviderArticle) error {
}
return nil
}
func (p *providerArticleApi) UpdateStatus(article v2.ProviderArticle) error {
return p.db.Where("id=?", article.ID).Select("status").Updates(&article).Error
}
func (p *providerArticleApi) FindInBatches(query *GetProviderArticleQuery, results *[]v2.ProviderArticle, f func(tx *gorm.DB, batch int) error) error {
err := p.db.Scopes(query.Scope).Preload("CalculateProcess").FindInBatches(results, 20, f).Error