<?php
/**
 * Copyright: Shanghai NuLang Network Technology Co., Ltd.
 * Faith: Some things do not need others to understand.
 * Project: CoverCMS <Your world, your ambition>
 * License: http://www.svipplus.cn/license/
 * Author: The Rain° <rain@svipplus.cn>
 * File: MenuKit.php
 * Time: 10:28
 */

namespace app\common\toolKit;


use think\Db;

/**
 * Class MenuKit
 * @package app\common\toolKit
 */
class MenuKit
{
    public static function get($parentId = 0)
    {
        $menus = Db::name('menu')->where(['parent_id' => $parentId])->select();
        foreach ($menus as &$menu) {
            if (!empty(trim($menu['route'])) && !is_null($menu['route'])) {
                if (!empty(trim($menu['param'])) && !is_null($menu['param'])) {
                    $p = json_decode($menu['param'], true);
                    $menu['route'] = url($menu['route'], $p);
                    if (isset($p['uv'])){
                        $menu['uv'] = true;
                    }
                } else {
                    $menu['route'] = url($menu['route']);
                }
            }
        }
        return $menus;
    }
}