正在显示
1 个修改的文件
包含
14 行增加
和
13 行删除
| @@ -17,6 +17,8 @@ use App\Models\CustomModule\CustomModule; | @@ -17,6 +17,8 @@ use App\Models\CustomModule\CustomModule; | ||
| 17 | use App\Models\CustomModule\CustomModuleCategory; | 17 | use App\Models\CustomModule\CustomModuleCategory; |
| 18 | use App\Models\CustomModule\CustomModuleContent; | 18 | use App\Models\CustomModule\CustomModuleContent; |
| 19 | use App\Models\News\News; | 19 | use App\Models\News\News; |
| 20 | +use App\Models\Product\Category; | ||
| 21 | +use App\Models\Product\CategoryRelated; | ||
| 20 | use App\Models\Product\Product; | 22 | use App\Models\Product\Product; |
| 21 | use App\Models\Project\Project; | 23 | use App\Models\Project\Project; |
| 22 | use App\Models\RouteMap\RouteMap; | 24 | use App\Models\RouteMap\RouteMap; |
| @@ -354,11 +356,14 @@ class TranslateController extends BaseController | @@ -354,11 +356,14 @@ class TranslateController extends BaseController | ||
| 354 | }else{ | 356 | }else{ |
| 355 | $catelists = Cache::get('product_category_trans'); | 357 | $catelists = Cache::get('product_category_trans'); |
| 356 | if(!$catelists){ | 358 | if(!$catelists){ |
| 357 | - $catelists = $productModel->list(['status'=>1],'id',['id','pid']); | 359 | + $cateModel = new Category(); |
| 360 | + $catelists = $cateModel->list(['status'=>1],'id',['id','pid']); | ||
| 358 | Cache::put('product_category_trans',$catelists,3600 * 24); | 361 | Cache::put('product_category_trans',$catelists,3600 * 24); |
| 359 | } | 362 | } |
| 360 | - $count = $this->getCategoryWithChildrenCountIterative($catelists,$v['source_id']); | ||
| 361 | -// $count = $productModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%'],'status'=>1])->count(); | 363 | + $ids = $this->getCategoryWithChildrenCountIterative($catelists,$v['source_id']); |
| 364 | + $cateRelateModel = new CategoryRelated(); | ||
| 365 | + $product_ids = $cateRelateModel->whereIn('id',$ids)->distinct(true)->value('product_id'); | ||
| 366 | + $count = count($product_ids); | ||
| 362 | } | 367 | } |
| 363 | $this->pageSixList($data,$count,$v,1,15); | 368 | $this->pageSixList($data,$count,$v,1,15); |
| 364 | break; | 369 | break; |
| @@ -488,24 +493,20 @@ class TranslateController extends BaseController | @@ -488,24 +493,20 @@ class TranslateController extends BaseController | ||
| 488 | * @param int $categoryId 分类ID | 493 | * @param int $categoryId 分类ID |
| 489 | * @return int 分类总数 | 494 | * @return int 分类总数 |
| 490 | */ | 495 | */ |
| 491 | - function getCategoryWithChildrenCountIterative($categories, $categoryId) { | ||
| 492 | - $count = 0; | 496 | + public function getCategoryWithChildrenIds($categories, $categoryId) { |
| 497 | + $ids = []; // 存储所有ID的数组 | ||
| 493 | $queue = [$categoryId]; // 待处理的ID队列 | 498 | $queue = [$categoryId]; // 待处理的ID队列 |
| 494 | while (!empty($queue)) { | 499 | while (!empty($queue)) { |
| 495 | $currentId = array_shift($queue); | 500 | $currentId = array_shift($queue); |
| 496 | - // 如果是第一个ID,计数自身 | ||
| 497 | - if ($currentId == $categoryId) { | ||
| 498 | - $count++; | ||
| 499 | - } | ||
| 500 | - // 查找并计数所有子分类 | 501 | + // 将当前ID添加到结果数组 |
| 502 | + $ids[] = $currentId; | ||
| 503 | + // 查找所有子分类 | ||
| 501 | foreach ($categories as $category) { | 504 | foreach ($categories as $category) { |
| 502 | if (isset($category['pid']) && $category['pid'] == $currentId) { | 505 | if (isset($category['pid']) && $category['pid'] == $currentId) { |
| 503 | - $count++; | ||
| 504 | $queue[] = $category['id']; // 将子分类ID加入队列 | 506 | $queue[] = $category['id']; // 将子分类ID加入队列 |
| 505 | } | 507 | } |
| 506 | } | 508 | } |
| 507 | } | 509 | } |
| 508 | - | ||
| 509 | - return $count; | 510 | + return $ids; |
| 510 | } | 511 | } |
| 511 | } | 512 | } |
-
请 注册 或 登录 后发表评论