Files
mier-php/application/anchor/model/SystemMenu.php
2025-08-11 10:22:05 +08:00

64 lines
1.5 KiB
PHP

<?php
namespace app\anchor\model;
use think\Db;
use think\Model;
class SystemMenu extends Model
{
// 获取初始化数据
public function getSystemInit($aid = 0)
{
$homeInfo = [
'title' => '首页',
'href' => '',
];
$logoInfo = [
'title' => '系统 管理',
'image' => 'images/logo.png',
];
$menuInfo = $this->getMenuList($aid);
$systemInit = [
'homeInfo' => $homeInfo,
'logoInfo' => $logoInfo,
'menuInfo' => $menuInfo,
];
return $systemInit;
}
// 获取菜单列表
private function getMenuList($aid)
{
$menuList = Db::name('system_menu_anchor')
->field('id,pid,title,icon,href,target')
->where('status', 1)
->where('type', 'in', [1, 2])
->order('sort', 'desc')
->select();
$menuList = $this->buildMenuChild(0, $menuList);
return $menuList;
}
//递归获取子菜单
private function buildMenuChild($pid, $menuList)
{
$treeList = [];
foreach ($menuList as &$v) {
if ($pid == $v['pid']) {
$node = $v;
$child = $this->buildMenuChild($v['id'], $menuList);
if (!empty($child)) {
$node['child'] = $child;
}
// todo 后续此处加上用户的权限判断
$treeList[] = $node;
}
}
return $treeList;
}
}