作者 lyh

gx

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