fix(#279): only auto-link active pdd products
This commit is contained in:
@@ -40,6 +40,16 @@ func (service *Service) autoLinkImageSearch(ctx context.Context, taskID uint64)
|
||||
if strings.ToUpper(strings.TrimSpace(product.Currency)) != "CNY" {
|
||||
return nil
|
||||
}
|
||||
var pdd models.PDDProduct
|
||||
if err := service.DB.WithContext(ctx).Select("id", "status").First(&pdd, *task.PDDProductID).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil
|
||||
}
|
||||
return internalError(err)
|
||||
}
|
||||
if pdd.Status != "active" {
|
||||
return nil
|
||||
}
|
||||
result := service.DB.WithContext(ctx).Model(&models.ShopeeProduct{}).
|
||||
Where("id = ? AND pdd_product_id IS NULL AND image_search_linked = ?", product.ID, false).
|
||||
Updates(map[string]any{"pdd_product_id": *task.PDDProductID, "image_search_linked": true})
|
||||
|
||||
Reference in New Issue
Block a user