Commit ba2c5366 by 杨树贤

分类数量返回

parent 90af3681
Showing with 12 additions and 11 deletions
......@@ -11,14 +11,14 @@ class ClassService
{
//先获取所有分类
$classCache = Redis::hgetall('pool_class_info');
$topClassList = [];
$secondClassList = [];
foreach ($classCache as $key => &$class) {
$class = json_decode($class, true);
if (!$class['parent_id']) {
if (empty($class['class_name_en'])) {
continue;
}
$topClassList[] = $class;
$secondClassList[] = $class;
}
}
unset($class);
......@@ -26,15 +26,16 @@ class ClassService
if (!$class['parent_id']) {
continue;
}
foreach ($topClassList as &$topClass) {
if ($topClass['class_id'] == $class['parent_id']) {
foreach ($secondClassList as &$secondClass) {
if ($secondClass['class_id'] == $class['parent_id']) {
if (empty($class['class_name_en'])) {
continue;
}
$topClass['children'][] = $class;
$class['sku_number'] = Redis::hget('pool_class_info_count', $class['class_id']) ?: 0;
$secondClass['children'][] = $class;
}
}
unset($topClass);
unset($secondClass);
}
$topClassMapping = config('field.top_class_mapping');
......@@ -42,15 +43,15 @@ class ClassService
foreach ($topClassMapping as $key => $mapping) {
$topFields[$key] = [
'class_name' => $key,
];
];
}
foreach ($topClassMapping as $key => $mapping) {
foreach ($topClassList as $topClass) {
if (in_array($topClass['class_id'], $topClassMapping[$key])) {
if (empty($topClass['class_name_en'])) {
foreach ($secondClassList as $secondClass) {
if (in_array($secondClass['class_id'], $topClassMapping[$key])) {
if (empty($secondClass['class_name_en'])) {
continue;
}
$topFields[$key]['children'][] = $topClass;
$topFields[$key]['children'][] = $secondClass;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment