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.

167 lines
3.9 KiB
PHTML

5 years ago
<?php
namespace Admin\Controller;
class SdkMenuController extends ThinkController{
5 years ago
public $but_type = [
'0' => 'h5页面',
'1' => '原生',
'2' => '外部链接',
];
public $menu_version = [
'0' => '双平台',
'1' => '安卓',
'2' => 'ios',
];
5 years ago
public function lists()
{
5 years ago
$menu_name = I('get.menu_name','sdk_menu');
$sdkMenus = M('tool','tab_')->where(['name' => $menu_name])->find();
5 years ago
$config = json_decode($sdkMenus['config'],true);
5 years ago
if(!empty($config))
5 years ago
{
5 years ago
foreach($config as $k => $v)
{
5 years ago
$config[$k]['icon'] = is_https()?'https://':'http://' . $_SERVER['HTTP_HOST'] . $v['icon'];
5 years ago
$config[$k]['type'] = $this->but_type[$v['type']];
$config[$k]['menu_version'] = $this->menu_version[$v['menu_version']];
5 years ago
}
5 years ago
}
$this->assign('list',$config);
5 years ago
$this->assign('menu_name',$menu_name);
$this->assign('menu_list',$this->getMenuList());
5 years ago
$this->meta_title = '悬浮球菜单';
5 years ago
$this->display('lists');
}
public function add()
{
5 years ago
$menu_name = I('get.menu_name','sdk_menu');
$sdkMenus = M('tool','tab_')->where(['name' => $menu_name])->find();
5 years ago
$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);
5 years ago
if(empty($sdkMenus['name']))
{
5 years ago
$sdkMenus['name'] = $menu_name;
5 years ago
$sdkMenus['title'] = '悬浮球菜单';
5 years ago
M('tool','tab_')->data($sdkMenus)->add();
}else
{
5 years ago
M('tool','tab_')->where(['name' => $menu_name])->data($sdkMenus)->save();
5 years ago
}
5 years ago
$this->success('新增成功', U('lists',['menu_name' => $menu_name]));
5 years ago
}
$data['sort'] = $id;
5 years ago
$this->meta_title = '悬浮球菜单';
5 years ago
$this->assign('type','add');
$this->assign('data',$data);
5 years ago
$this->assign('menu_name',$menu_name);
5 years ago
$this->assign('but_type',$this->but_type);
$this->assign('menu_version',$this->menu_version);
5 years ago
$this->display('add');
}
public function edit($id)
{
5 years ago
$menu_name = I('get.menu_name','sdk_menu');
$sdkMenus = M('tool','tab_')->where(['name' => $menu_name])->find();
5 years ago
$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);
5 years ago
M('tool','tab_')->where(['name' => $menu_name])->data($sdkMenus)->save();
$this->success('修改成功', U('lists',['menu_name' => $menu_name]));
5 years ago
}
$data = [];
foreach($config as $k => $v)
{
if($v['id'] == $id)
{
5 years ago
$v['icon'] = is_https()?'https://':'http://' . $_SERVER['HTTP_HOST'] . $v['icon'];
5 years ago
$data = $v;
break;
}
}
if(empty($data))
{
$this->error('菜单不存在','lists');
}
5 years ago
$this->meta_title = '悬浮球菜单';
5 years ago
$this->assign('type','edit');
$this->assign('data',$data);
5 years ago
$this->assign('menu_name',$menu_name);
5 years ago
$this->assign('but_type',$this->but_type);
$this->assign('menu_version',$this->menu_version);
5 years ago
$this->display('add');
}
public function del($id)
{
5 years ago
$menu_name = I('get.menu_name','sdk_menu');
5 years ago
if(!is_array($id))
{
$data[] = $id;
}else
{
$data = $id;
}
5 years ago
$sdkMenus = M('tool','tab_')->where(['name' => $menu_name])->find();
5 years ago
$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);
5 years ago
M('tool','tab_')->where(['name' => $menu_name])->data($sdkMenus)->save();
$this->success('删除成功', U('lists',['menu_name' => $menu_name]));
}
public function getMenuList()
{
$data = M('tool','tab_')->where(['type' => 5])->select();
return $data;
5 years ago
}
}