84 lines
2.3 KiB
PHP
84 lines
2.3 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
|
||
namespace app\system\controller;
|
||
|
||
use app\common\model\Permission as PermissionModel;
|
||
use app\common\service\Permission as PermissionService;
|
||
use think\Db;
|
||
use tools\Tree;
|
||
|
||
class Permission extends _Init
|
||
{
|
||
public function index()
|
||
{
|
||
$map = [];
|
||
$Model = new PermissionModel();
|
||
$this->list = $Model->where($map)->order('create_time desc')->paginate(15);
|
||
return $this->fetch();
|
||
}
|
||
|
||
public function create()
|
||
{
|
||
if (IS_POST) {
|
||
$data = $this->request->post();
|
||
$result = PermissionService::create($data);
|
||
if ($result === true) {
|
||
return $this->success();
|
||
} else {
|
||
return $this->error($result);
|
||
}
|
||
} else {
|
||
$this->up_menus = self::_treeShow();
|
||
return view();
|
||
}
|
||
}
|
||
|
||
public function update($id)
|
||
{
|
||
if (IS_POST) {
|
||
$data = $this->request->post();
|
||
|
||
$result = PermissionService::update($data);
|
||
if ($result === true) {
|
||
return $this->success();
|
||
} else {
|
||
return $this->error($result);
|
||
}
|
||
} else {
|
||
$this->info = PermissionModel::get($id);
|
||
$this->up_menus = self::_treeShow();
|
||
return $this->fetch('create');
|
||
}
|
||
}
|
||
|
||
public function delete($id)
|
||
{
|
||
$result = PermissionService::delete($id);
|
||
if ($result === true) {
|
||
return $this->success();
|
||
} else {
|
||
return $this->error($result);
|
||
}
|
||
}
|
||
|
||
private function _treeShow($id = 0)
|
||
{
|
||
$map = [];
|
||
if ($id) {
|
||
$map['id'] = ['neq', $id];
|
||
}
|
||
|
||
$menus = Db::name('Permission')->where($map)->order('create_time desc')->select();
|
||
$menus = Tree::toFormatTree($menus);
|
||
$menus = array_merge([0 => ['id' => 0, 'title_show' => '顶级菜单']], $menus);
|
||
return $menus;
|
||
}
|
||
}
|