作者 lyh

gx

... ... @@ -40,7 +40,7 @@ class CategoryController extends BaseController
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST);//获取模版id
foreach ($list as $k =>$v){
$v['url'] = $this->user['domain'] . $v['route'].'/';
$v['product_num'] = $category->getProductNum($v['id']);
$v['product_num'] = $category->getProductNum($list,$v['id']);
$v['image_link'] = getImageUrl($v['image'],$this->user['storage_type'],$this->user['project_location']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
$list[$k] = $v;
... ...
... ... @@ -48,12 +48,11 @@ class Category extends Base
* @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){
public function getAllSub($list,$id,&$str = []){
foreach ($list as $k =>$v){
if($v['pid'] == $id){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
$this->getAllSub($list,$v['id'],$str);
}
}
return $str;
... ... @@ -66,9 +65,9 @@ class Category extends Base
* @author zbj
* @date 2023/4/28
*/
public function getProductNum($cate_id){
public function getProductNum($list,$cate_id){
$str[] = $cate_id;
$cate_ids = $this->getAllSub($cate_id,$str);
$cate_ids = $this->getAllSub($list,$cate_id,$str);
$productArr = CategoryRelated::whereIn('cate_id',$cate_ids)->pluck('product_id')->unique()->toArray();
$count = count($productArr);
return $count;
... ...