作者 lyh

gx

... ... @@ -41,24 +41,7 @@ class Category extends Base
return $ids;
}
/**
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/18 15:10
*/
public static function getAllSub($id,&$str = []){
$cateModel = new Category();
$list = $cateModel->list(['pid'=>$id,'status'=>1],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
self::getAllSub($v['id'],$str);
}
}
return $str;
}
/**
* 关联产品数量
... ... @@ -68,8 +51,9 @@ class Category extends Base
* @date 2023/4/28
*/
public static function getProductNum($cate_id){
$cate_ids = self::getAllSub($cate_id,$str);
$cate_ids = self::getChildIdsArr($cate_id);
$count = CategoryRelated::whereIn('cate_id',$cate_ids)->count();
// $str = 0;
return $count;
}
}
... ...