Просмотр исходного кода

修复:删除商品分类时无效的商品引用

萤火科技 5 лет назад
Родитель
Сommit
8a93ab6ccf
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      app/store/model/GoodsCategoryRel.php

+ 5 - 1
app/store/model/GoodsCategoryRel.php

@@ -28,7 +28,11 @@ class GoodsCategoryRel extends GoodsCategoryRelModel
      */
      */
     public static function getCountByCategoryId(int $categoryId)
     public static function getCountByCategoryId(int $categoryId)
     {
     {
-        return (new static)->where('category_id', '=', $categoryId)->count();
+        return (new static)->alias('m')
+            ->join('goods', 'goods.goods_id = m.goods_id')
+            ->where('m.category_id', '=', $categoryId)
+            ->where('g.is_delete', '=', 0)
+            ->count();
     }
     }
 
 
     /**
     /**