You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.0 KiB
PHTML
137 lines
3.0 KiB
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
namespace Admin\Controller;
|
||
|
|
||
|
class PersonalMenusController extends ThinkController{
|
||
|
|
||
|
public function lists()
|
||
|
{
|
||
|
$sdkMenus = M('tool','tab_')->where(['name' => 'personal_menu'])->find();
|
||
|
$config = json_decode($sdkMenus['config'],true);
|
||
|
if(!empty($config))
|
||
|
{
|
||
|
foreach($config as $k => $v)
|
||
|
{
|
||
|
$config[$k]['icon'] = is_https()?'https://':'http://' . $_SERVER['SERVER_NAME'] . $v['icon'];
|
||
|
}
|
||
|
}
|
||
|
$this->assign('list',$config);
|
||
|
$this->meta_title = '个人中心列表';
|
||
|
$this->display('lists');
|
||
|
}
|
||
|
|
||
|
public function add()
|
||
|
{
|
||
|
$sdkMenus = M('tool','tab_')->where(['name' => 'personal_menu'])->find();
|
||
|
$config = json_decode($sdkMenus['config'],true);
|
||
|
if(!empty($config))
|
||
|
{
|
||
|
$config1 = $config;
|
||
|
$id = array_pop($config1);
|
||
|
$id = $id['id'] + 1;
|
||
|
}else
|
||
|
{
|
||
|
$config = [];
|
||
|
$id = 1;
|
||
|
}
|
||
|
|
||
|
if(IS_POST)
|
||
|
{
|
||
|
$post = I('post.');
|
||
|
$post['id'] = $id;
|
||
|
array_push($config,$post);
|
||
|
$sdkMenus['config'] = json_encode($config);
|
||
|
if(empty($sdkMenus['name']))
|
||
|
{
|
||
|
$sdkMenus['name'] = 'personal_menu';
|
||
|
$sdkMenus['title'] = '个人中心列表';
|
||
|
$sdkMenus['status'] = 1;
|
||
|
$sdkMenus['create_time'] = time();
|
||
|
M('tool','tab_')->data($sdkMenus)->add();
|
||
|
}else
|
||
|
{
|
||
|
M('tool','tab_')->where(['name' => 'personal_menu'])->data($sdkMenus)->save();
|
||
|
}
|
||
|
$this->success('新增成功', U('lists'));
|
||
|
}
|
||
|
|
||
|
$data['sort'] = $id;
|
||
|
$this->meta_title = '个人中心列表';
|
||
|
$this->assign('type','add');
|
||
|
$this->assign('data',$data);
|
||
|
$this->display('add');
|
||
|
}
|
||
|
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$sdkMenus = M('tool','tab_')->where(['name' => 'personal_menu'])->find();
|
||
|
$config = json_decode($sdkMenus['config'],true);
|
||
|
if(IS_POST)
|
||
|
{
|
||
|
foreach($config as $k => $v)
|
||
|
{
|
||
|
if($v['id'] == $id)
|
||
|
{
|
||
|
$post = I('post.');
|
||
|
foreach($post as $key => $val)
|
||
|
{
|
||
|
if($key == 'icon')
|
||
|
{
|
||
|
$config[$k][$key] = strstr($val,'/Upload');
|
||
|
}else
|
||
|
{
|
||
|
$config[$k][$key] = $val;
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
$sdkMenus['config'] = json_encode($config);
|
||
|
M('tool','tab_')->where(['name' => 'personal_menu'])->data($sdkMenus)->save();
|
||
|
$this->success('修改成功', U('lists'));
|
||
|
}
|
||
|
$data = [];
|
||
|
foreach($config as $k => $v)
|
||
|
{
|
||
|
if($v['id'] == $id)
|
||
|
{
|
||
|
$v['icon'] = is_https()?'https://':'http://' . $_SERVER['SERVER_NAME'] . $v['icon'];
|
||
|
$data = $v;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
if(empty($data))
|
||
|
{
|
||
|
$this->error('菜单不存在','lists');
|
||
|
}
|
||
|
$this->meta_title = '个人中心列表';
|
||
|
$this->assign('type','edit');
|
||
|
$this->assign('data',$data);
|
||
|
$this->display('add');
|
||
|
}
|
||
|
|
||
|
|
||
|
public function del($id)
|
||
|
{
|
||
|
if(!is_array($id))
|
||
|
{
|
||
|
$data[] = $id;
|
||
|
}else
|
||
|
{
|
||
|
$data = $id;
|
||
|
}
|
||
|
$sdkMenus = M('tool','tab_')->where(['name' => 'personal_menu'])->find();
|
||
|
$config = json_decode($sdkMenus['config'],true);
|
||
|
foreach($config as $k => $v)
|
||
|
{
|
||
|
if(in_array($v['id'], $data))
|
||
|
{
|
||
|
unset($config[$k]);
|
||
|
}
|
||
|
}
|
||
|
$sdkMenus['config'] = json_encode($config);
|
||
|
M('tool','tab_')->where(['name' => 'personal_menu'])->data($sdkMenus)->save();
|
||
|
$this->success('删除成功', U('lists'));
|
||
|
}
|
||
|
|
||
|
}
|