fix 修复saveProduct通知的id为0的bug
All checks were successful
Build image / build (push) Successful in 8m3s

This commit is contained in:
timerzz 2024-12-01 16:32:13 +08:00
parent 1b0d5ee30c
commit a4e217d17a

View File

@ -229,15 +229,16 @@ func (c *Controller) saveProducts(articles []v2.Article) {
}
// 如果已经存在了那么不需要重新创建article
if err == nil {
article.ID = oldArticle.ID
// 查看现在有没有这个供应商的商品
oldProviderArticle, _, exist := lo.FindIndexOf(oldArticle.Providers, func(item v2.ProviderArticle) bool {
return item.ProviderId == c.providerId
})
// 创建供应商商品
if !exist {
oldArticle.Providers = append(oldArticle.Providers, article.Providers...)
oldArticle.Providers = article.Providers
// 保存商品信息
if err = c.storage.Article().Upsert(article); err != nil {
if err = c.storage.Article().Upsert(oldArticle); err != nil {
glog.Errorf("保存商品信息失败: %v", err)
continue
}
@ -248,6 +249,7 @@ func (c *Controller) saveProducts(articles []v2.Article) {
}
oldProviderArticle.Cost = pArticle.Cost
oldProviderArticle.Ast = pArticle.Ast
oldProviderArticle.Available = pArticle.Available
if err = c.storage.ProviderArticle().Upsert(oldProviderArticle); err != nil {
glog.Errorf("保存供应商商品信息失败: %v", err)
continue
@ -261,6 +263,10 @@ func (c *Controller) saveProducts(articles []v2.Article) {
glog.Errorf("保存商品信息失败: %v", err)
continue
}
if err = c.storage.DB().Model(&v2.Article{}).Where("pid = ? and brand = ?", article.Pid, article.Brand).Select("id").First(&article.ID).Error; err != nil {
glog.Errorf("获取商品ID失败: %v", err)
continue
}
}
if err = c.subscribeClient.Publish(c.ctx, utils.ProfitRate_Channel, strconv.Itoa(int(article.ID))); err != nil {