fix 修复saveProduct通知的id为0的bug
All checks were successful
Build image / build (push) Successful in 8m3s
All checks were successful
Build image / build (push) Successful in 8m3s
This commit is contained in:
parent
1b0d5ee30c
commit
a4e217d17a
@ -229,15 +229,16 @@ func (c *Controller) saveProducts(articles []v2.Article) {
|
|||||||
}
|
}
|
||||||
// 如果已经存在了,那么不需要重新创建article
|
// 如果已经存在了,那么不需要重新创建article
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
article.ID = oldArticle.ID
|
||||||
// 查看现在有没有这个供应商的商品
|
// 查看现在有没有这个供应商的商品
|
||||||
oldProviderArticle, _, exist := lo.FindIndexOf(oldArticle.Providers, func(item v2.ProviderArticle) bool {
|
oldProviderArticle, _, exist := lo.FindIndexOf(oldArticle.Providers, func(item v2.ProviderArticle) bool {
|
||||||
return item.ProviderId == c.providerId
|
return item.ProviderId == c.providerId
|
||||||
})
|
})
|
||||||
// 创建供应商商品
|
// 创建供应商商品
|
||||||
if !exist {
|
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)
|
glog.Errorf("保存商品信息失败: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -248,6 +249,7 @@ func (c *Controller) saveProducts(articles []v2.Article) {
|
|||||||
}
|
}
|
||||||
oldProviderArticle.Cost = pArticle.Cost
|
oldProviderArticle.Cost = pArticle.Cost
|
||||||
oldProviderArticle.Ast = pArticle.Ast
|
oldProviderArticle.Ast = pArticle.Ast
|
||||||
|
oldProviderArticle.Available = pArticle.Available
|
||||||
if err = c.storage.ProviderArticle().Upsert(oldProviderArticle); err != nil {
|
if err = c.storage.ProviderArticle().Upsert(oldProviderArticle); err != nil {
|
||||||
glog.Errorf("保存供应商商品信息失败: %v", err)
|
glog.Errorf("保存供应商商品信息失败: %v", err)
|
||||||
continue
|
continue
|
||||||
@ -261,6 +263,10 @@ func (c *Controller) saveProducts(articles []v2.Article) {
|
|||||||
glog.Errorf("保存商品信息失败: %v", err)
|
glog.Errorf("保存商品信息失败: %v", err)
|
||||||
continue
|
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 {
|
if err = c.subscribeClient.Publish(c.ctx, utils.ProfitRate_Channel, strconv.Itoa(int(article.ID))); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user