75 lines
1.5 KiB
PHP
75 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace app\common\model\page;
|
|
|
|
use think\Model;
|
|
use think\Cache;
|
|
/**
|
|
* 自定义导航
|
|
*/
|
|
class Navigation extends Model
|
|
{
|
|
|
|
|
|
// 表名
|
|
protected $name = 'page_navigation';
|
|
|
|
|
|
/**
|
|
* 获取底部导航数据
|
|
* @param $id
|
|
* @return void
|
|
*/
|
|
public function getNavigationData(){
|
|
|
|
$cacheData = Cache::get(\app\common\constant\cache\Keys::PAGE_NAVIGATION);
|
|
|
|
if($cacheData){
|
|
return $cacheData;
|
|
}
|
|
|
|
\think\Cache::rm(\app\common\constant\cache\Keys::PAGE_NAVIGATION);
|
|
|
|
$data = self::where([
|
|
'status'=>1,
|
|
'default_navigation'=>0
|
|
])->find();
|
|
|
|
if(!$data){
|
|
$data = self::where([
|
|
'default_navigation'=>1
|
|
])->find();
|
|
}
|
|
|
|
if(!$data){
|
|
return false;
|
|
}
|
|
|
|
$data = $data->toArray();
|
|
|
|
$data['config'] = json_decode($data['config'],true);
|
|
|
|
$data = $this->oldIndexToNew($data);
|
|
|
|
Cache::set(\app\common\constant\cache\Keys::PAGE_NAVIGATION,$data);
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
/**
|
|
* 旧路由地址换成新的
|
|
* @param $arr
|
|
* @return mixed
|
|
*/
|
|
public function oldIndexToNew($arr){
|
|
foreach ($arr as &$item){
|
|
if(is_array($item)){
|
|
$item = $this->oldIndexToNew($item);
|
|
}elseif(is_string($item)){
|
|
$item = str_replace("pages/public/diy/diy","pages/index/index",$item);
|
|
}
|
|
}
|
|
return $arr;
|
|
}
|
|
} |