|
...
|
...
|
@@ -17,6 +17,8 @@ use App\Models\CustomModule\CustomModule; |
|
|
|
use App\Models\CustomModule\CustomModuleCategory;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\News\News;
|
|
|
|
use App\Models\Product\Category;
|
|
|
|
use App\Models\Product\CategoryRelated;
|
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
...
|
...
|
@@ -354,11 +356,14 @@ class TranslateController extends BaseController |
|
|
|
}else{
|
|
|
|
$catelists = Cache::get('product_category_trans');
|
|
|
|
if(!$catelists){
|
|
|
|
$catelists = $productModel->list(['status'=>1],'id',['id','pid']);
|
|
|
|
$cateModel = new Category();
|
|
|
|
$catelists = $cateModel->list(['status'=>1],'id',['id','pid']);
|
|
|
|
Cache::put('product_category_trans',$catelists,3600 * 24);
|
|
|
|
}
|
|
|
|
$count = $this->getCategoryWithChildrenCountIterative($catelists,$v['source_id']);
|
|
|
|
// $count = $productModel->formatQuery(['category_id'=>['like','%,'.$v['source_id'].',%'],'status'=>1])->count();
|
|
|
|
$ids = $this->getCategoryWithChildrenCountIterative($catelists,$v['source_id']);
|
|
|
|
$cateRelateModel = new CategoryRelated();
|
|
|
|
$product_ids = $cateRelateModel->whereIn('id',$ids)->distinct(true)->value('product_id');
|
|
|
|
$count = count($product_ids);
|
|
|
|
}
|
|
|
|
$this->pageSixList($data,$count,$v,1,15);
|
|
|
|
break;
|
|
...
|
...
|
@@ -488,24 +493,20 @@ class TranslateController extends BaseController |
|
|
|
* @param int $categoryId 分类ID
|
|
|
|
* @return int 分类总数
|
|
|
|
*/
|
|
|
|
function getCategoryWithChildrenCountIterative($categories, $categoryId) {
|
|
|
|
$count = 0;
|
|
|
|
public function getCategoryWithChildrenIds($categories, $categoryId) {
|
|
|
|
$ids = []; // 存储所有ID的数组
|
|
|
|
$queue = [$categoryId]; // 待处理的ID队列
|
|
|
|
while (!empty($queue)) {
|
|
|
|
$currentId = array_shift($queue);
|
|
|
|
// 如果是第一个ID,计数自身
|
|
|
|
if ($currentId == $categoryId) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
// 查找并计数所有子分类
|
|
|
|
// 将当前ID添加到结果数组
|
|
|
|
$ids[] = $currentId;
|
|
|
|
// 查找所有子分类
|
|
|
|
foreach ($categories as $category) {
|
|
|
|
if (isset($category['pid']) && $category['pid'] == $currentId) {
|
|
|
|
$count++;
|
|
|
|
$queue[] = $category['id']; // 将子分类ID加入队列
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
return $ids;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|