Files
ntonpower/app/index/model/Navigator.php
2026-10-14 14:00:29 +08:00

84 lines
2.7 KiB
PHP

<?php
namespace app\index\model;
use think\helper\Str;
/**
* @mixin \think\Model
*/
class Navigator extends BaseModel
{
protected $schema = [
'id' => 'int',
'platform_id' => 'int',
'site_id' => 'int',
'language_id' => 'int',
'pid' => 'int',
'name' => 'string',
'desc' => 'string',
'icon' => 'string',
'link' => 'string',
'sort' => 'int',
'status' => 'int',
'is_top' => 'int',
'is_foot' => 'int',
'create_time' => 'int',
'update_time' => 'int'
];
/**
* 获取首页导航菜单
* @param $language_id
* @param $platform_id
* @param $controller
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getNavInfo($language_id,$platform_id,$controller):array
{
$result = $this->where(function($query) use ($language_id,$platform_id) {
$query->where('is_top',0)->where('status',0)->where('platform_id',$platform_id);
})->order('sort','desc')->select()->toArray();
if (!empty($result)) {
foreach ($result as $key => $item) {
if (isset($controller) && $controller != '') {
$url = explode('/',$item['url']);
if (count($url) <= 2 && $controller == 'Index') {
$result[$key]['is_show'] = true;
} else {
if (count($url) > 2) {
if ($url[2] == Str::snake($controller)) {
$result[$key]['is_show'] = true;
} else {
$result[$key]['is_show'] = false;
}
} else {
$result[$key]['is_show'] = false;
}
}
}
}
}
return $result;
}
/**
* 获取首页导航菜单
* @param $language_id
* @param $platform_id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getFootNavInfo($language_id,$platform_id):array
{
return $this->where(function($query) use ($language_id,$platform_id) {
$query->where('is_foot',0)->where('status',0)->where('platform_id',$platform_id);
})->order('sort','desc')->select()->toArray();
}
}