<?php

namespace App\Services\goods;

use App\Models\goods\mysql\Category;

class CategoryService
{
    public static function getCategoryList()
    {
        //todo::加上redis
        $allCaregoryList = Category::getRecordList([], ['category_id', 'parent_category_id', 'name', 'level']);
        $data = [];
        if (!empty($allCaregoryList)) {
            foreach ($allCaregoryList as $caregory) {
                if ($caregory["level"] == Category::LEVEL_1) {
                    $data["level_1"][] = [
                        "category_id" => $caregory["category_id"],
                        "name" => $caregory["name"]
                    ];
                }
                if ($caregory["level"] == Category::LEVEL_2) {
                    $data["level_2"][$caregory["parent_category_id"]][] = [
                        "category_id" => $caregory["category_id"],
                        "name" => $caregory["name"]
                    ];
                }
            }
        }
        return $data;
    }
}