121 lines
4.0 KiB
PHP
121 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace app\channel\controller;
|
|
use think\admin\Controller;
|
|
use app\channel\service\ProductCategory as categoryService;
|
|
use think\admin\extend\DataExtend;
|
|
use think\admin\model\SystemMenu;
|
|
use think\admin\service\AdminService;
|
|
use think\admin\service\MenuService;
|
|
use think\admin\service\NodeService;
|
|
use app\channel\model\ProductCategory as categoryModel;
|
|
class ProductCategory extends Controller
|
|
{
|
|
protected $table='product_category';
|
|
public function index(){
|
|
$this->title="产品分类";
|
|
$category_service= categoryService::instance();
|
|
$this->type = $this->get['type'] ?? 'index';
|
|
$this->_query($this->table)->layTable();
|
|
}
|
|
/**
|
|
* 列表数据处理
|
|
* @param array $data
|
|
*/
|
|
protected function _index_page_filter(array &$data)
|
|
{
|
|
|
|
$data = DataExtend::arr2tree($data);
|
|
// 回收站过滤有效菜单
|
|
if ($this->type === 'recycle') foreach ($data as $k1 => &$p1) {
|
|
if (!empty($p1['sub'])) foreach ($p1['sub'] as $k2 => &$p2) {
|
|
if (!empty($p2['sub'])) foreach ($p2['sub'] as $k3 => $p3) {
|
|
if ($p3['status'] > 0) unset($p2['sub'][$k3]);
|
|
}
|
|
if (empty($p2['sub']) && ($p2['url'] === '#' or $p2['status'] > 0)) unset($p1['sub'][$k2]);
|
|
}
|
|
if (empty($p1['sub']) && ($p1['url'] === '#' or $p1['status'] > 0)) unset($data[$k1]);
|
|
}
|
|
// 菜单数据树数据变平化
|
|
$data = DataExtend::arr2table($data);
|
|
foreach ($data as &$vo) {
|
|
if ($vo['url'] !== '#' && !preg_match('/^(https?:)?(\/\/|\\\\)/i', $vo['url'])) {
|
|
$vo['url'] = trim(url($vo['url']) . ($vo['params'] ? "?{$vo['params']}" : ''), '\\/');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加系统菜单
|
|
* @auth true
|
|
*/
|
|
public function add()
|
|
{
|
|
$this->_applyFormToken();
|
|
categoryModel::mForm('form');
|
|
}
|
|
|
|
/**
|
|
* 编辑系统菜单
|
|
* @auth true
|
|
*/
|
|
public function edit()
|
|
{
|
|
$this->_applyFormToken();
|
|
categoryModel::mForm('form');
|
|
}
|
|
|
|
/**
|
|
* 表单数据处理
|
|
* @param array $vo
|
|
* @throws \ReflectionException
|
|
*/
|
|
protected function _form_filter(array &$vo)
|
|
{
|
|
if ($this->request->isGet()) {
|
|
$debug = $this->app->isDebug();
|
|
/* 清理权限节点 */
|
|
$debug && AdminService::clear();
|
|
/* 读取系统功能节点 */
|
|
$this->auths = [];
|
|
$this->nodes = MenuService::getList($debug);
|
|
foreach (NodeService::getMethods($debug) as $node => $item) {
|
|
if ($item['isauth'] && substr_count($node, '/') >= 2) {
|
|
$this->auths[] = ['node' => $node, 'title' => $item['title']];
|
|
}
|
|
}
|
|
/* 选择自己上级菜单 */
|
|
$vo['pid'] = $vo['pid'] ?? input('pid', '0');
|
|
/* 列出可选上级菜单 */
|
|
$menus = $this->_query($this->table)->order('sort desc,id asc')->column('id,pid,icon,url,node,title,params', 'id');
|
|
$this->menus = DataExtend::arr2table(array_merge($menus, [['id' => '0', 'pid' => '-1', 'url' => '#', 'title' => '顶级分类']]));
|
|
|
|
if (isset($vo['id'])) foreach ($this->menus as $menu) if ($menu['id'] === $vo['id']) $vo = $menu;
|
|
foreach ($this->menus as $key => $menu) if ($menu['spt'] >= 3) unset($this->menus[$key]);
|
|
if (isset($vo['spt']) && isset($vo['spc']) && in_array($vo['spt'], [1, 2]) && $vo['spc'] > 0) {
|
|
foreach ($this->menus as $key => $menu) if ($vo['spt'] <= $menu['spt']) unset($this->menus[$key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改菜单状态
|
|
* @auth true
|
|
*/
|
|
public function state()
|
|
{
|
|
SystemMenu::mSave($this->_vali([
|
|
'status.in:0,1' => '状态值范围异常!',
|
|
'status.require' => '状态值不能为空!',
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* 删除系统菜单
|
|
* @auth true
|
|
*/
|
|
public function remove()
|
|
{
|
|
SystemMenu::mDelete();
|
|
}
|
|
} |