102 lines
2.0 KiB
PHP
102 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace plugin\cms;
|
|
|
|
use app\admin\model\cms\Category;
|
|
use app\admin\model\cms\Tags;
|
|
use app\common\library\Auth;
|
|
use app\PluginController;
|
|
use think\db\exception\DataNotFoundException;
|
|
use think\db\exception\DbException;
|
|
use think\db\exception\ModelNotFoundException;
|
|
|
|
/**
|
|
* CMS内容管理系统插件
|
|
*/
|
|
class Cms extends PluginController
|
|
{
|
|
/**
|
|
* 插件安装方法
|
|
* @return bool
|
|
*/
|
|
public function install()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* 插件卸载方法
|
|
* @return bool
|
|
*/
|
|
public function uninstall()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件启用方法
|
|
* @return bool
|
|
*/
|
|
public function enabled()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 插件禁用方法
|
|
* @return bool
|
|
*/
|
|
public function disabled()
|
|
{
|
|
|
|
return true;
|
|
}
|
|
|
|
public function appInit()
|
|
{ }
|
|
|
|
/**
|
|
* 获取栏目权限
|
|
* @param array $params
|
|
* @return array
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
public function cmsCategoryPermissions(array $params): array
|
|
{
|
|
$where = [];
|
|
$nodes = $params['nodes'] ?? '';
|
|
$field = $params['field'] ?? '*';
|
|
|
|
if (!empty($nodes)) {
|
|
$where[] = ['id', 'in', $nodes];
|
|
}
|
|
|
|
return Category::where($where)->field($field)->where('status',1)->select()->toArray();
|
|
}
|
|
|
|
/**
|
|
* CMS热搜关键词
|
|
* @param array $params
|
|
* @return array
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
public function cmsHotSearch(array $params): array
|
|
{
|
|
$data = [];
|
|
$list = Tags::where('status',1)->order('index desc')->limit(10)->select()->toArray();
|
|
foreach ($list as $index => $item) {
|
|
$data[] = [
|
|
'name' => $item['name'],
|
|
'value'=> $item['index'],
|
|
];
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|