first commit

This commit is contained in:
2020-08-06 15:26:41 +08:00
commit 8c0aa3edc1
1416 changed files with 238374 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\system\controller;
use app\common\model\Menu as MenuModel;
use app\common\service\Menu as MenuService;
use think\Db;
use think\Request;
use tools\Tree;
class Menu extends _Init
{
/**
* 菜单列表
* @param integer $pid 上级id
* @return [type] [description]
*/
public function index($pid = 0)
{
$this->list = MenuModel::where('status', 'egt', 0)->where('pid', $pid)->order('sort asc')->paginate();
$this->menu = MenuService::tree();
$this->info = MenuModel::get($pid);
return $this->fetch();
}
/**
* 添加菜单
* @param integer $pid 上级id
*/
public function add(Request $request, $pid = 0)
{
if (IS_POST) {
$data = $request->post();
$result = MenuService::add($data);
return $this->back($result);
} else {
$info['pid'] = $pid;
$this->info = $info;
$this->up_menus = self::_treeShow();
return $this->fetch();
}
}
/**
* 编辑菜单
* @param [type] $id 菜单id
* @return [type] [description]
*/
public function edit(Request $request, $id)
{
if (IS_POST) {
$data = $request->post();
$result = MenuService::edit($data);
return $this->back($result);
} else {
$this->info = MenuModel::get($id);
$this->up_menus = self::_treeShow($id);
return $this->fetch('add');
}
}
/**
* 删除菜单
* @param [type] $id 要删除的菜单id
* @return [type] [description]
*/
public function del($id)
{
$result = MenuService::del($id);
return $this->back($result);
}
/**
* 设置菜单状态
* @param [type] $id 要设置的菜单id
* @param [type] $status 要设置的状态 正常 和 禁用 true false
* @param [type] $type 要设置的字段 status
* @return [type] 返回操作的结果 成功 true 失败 返回失败的信息
*/
public function status($id, $status, $type)
{
$result = MenuService::status($id, $status, $type);
return $this->back($result);
}
private function _treeShow($id = 0)
{
$map = [];
if ($id) {
$map['id'] = ['neq', $id];
}
$menus = Db::name('Menu')->where($map)->order('sort asc')->select();
$menus = Tree::toFormatTree($menus);
$menus = array_merge([0 => ['id' => 0, 'title_show' => '顶级菜单']], $menus);
return $menus;
}
}