Files
2020-08-06 15:26:41 +08:00

84 lines
2.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}