Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

semour / semour_web

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
BlameHistoryPermalink
Switch branch/tag
  • semour_web
  • app
  • Http
  • Services
  • ClassService.php
  • 杨树贤's avatar
    分类过滤问题 · ac0ad9fa
    杨树贤 committed 2 years ago
    ac0ad9fa
ClassService.php 1.82 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
<?php

namespace App\Http\Services;

use Illuminate\Support\Facades\Redis;

class ClassService
{
    //获取首页需要的所有分类,没有英文名称的不要
    public static function getClassificationForHome()
    {
        //先获取所有分类
        $classCache = Redis::hgetall('pool_class_info');
        $topClassList = [];
        foreach ($classCache as $key => &$class) {
            $class = json_decode($class, true);
            if (!$class['parent_id']) {
                if (empty($class['class_name_en'])) {
                    continue;
                }
                $topClassList[] = $class;
            }
        }
        unset($class);
        foreach ($classCache as $key => $class) {
            if (!$class['parent_id']) {
                continue;
            }
            foreach ($topClassList as &$topClass) {
                if ($topClass['class_id'] == $class['parent_id']) {
                    if (empty($class['class_name_en'])) {
                        continue;
                    }
                    $topClass['children'][] = $class;
                }
            }
            unset($topClass);
        }

        $topClassMapping = config('field.top_class_mapping');
        $topFields = [];
        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'])) {
                        continue;
                    }
                    $topFields[$key]['children'][] = $topClass;
                }
            }
        }
        return array_values($topFields);
    }

}