2019-12-09 09:58:52 +08:00
|
|
|
<?php
|
2019-12-11 21:00:14 +08:00
|
|
|
namespace catchAdmin\permissions\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\Request;
|
|
|
|
use catcher\base\CatchController;
|
2019-12-12 18:52:11 +08:00
|
|
|
use catcher\CatchAdmin;
|
2019-12-11 21:00:14 +08:00
|
|
|
use catcher\CatchForm;
|
|
|
|
use catcher\CatchResponse;
|
|
|
|
use catcher\exceptions\FailedException;
|
|
|
|
use catcher\Tree;
|
2019-12-12 18:52:33 +08:00
|
|
|
use catchAdmin\permissions\model\Permissions as Permissions;
|
2019-12-11 21:00:14 +08:00
|
|
|
|
2019-12-12 18:52:11 +08:00
|
|
|
class Permission extends CatchController
|
2019-12-11 21:00:14 +08:00
|
|
|
{
|
|
|
|
protected $permissions;
|
|
|
|
|
2019-12-12 18:52:33 +08:00
|
|
|
public function __construct(Permissions $permissions)
|
2019-12-11 21:00:14 +08:00
|
|
|
{
|
|
|
|
$this->permissions = $permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @param Request $request
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
2019-12-26 09:03:09 +08:00
|
|
|
public function index(Request $request)
|
2019-12-11 21:00:14 +08:00
|
|
|
{
|
|
|
|
return CatchResponse::success(Tree::done($this->permissions->getList($request->param())));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @throws \Exception
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function create()
|
2019-12-26 09:03:09 +08:00
|
|
|
{}
|
2019-12-11 21:00:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @param Request $request
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
|
|
|
public function save(Request $request)
|
|
|
|
{
|
|
|
|
return CatchResponse::success($this->permissions->storeBy($request->param()));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function read()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @param $id
|
|
|
|
* @throws \Exception
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
2019-12-26 09:03:09 +08:00
|
|
|
{}
|
2019-12-11 21:00:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @param $id
|
|
|
|
* @param Request $request
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
|
|
|
public function update($id, Request $request)
|
|
|
|
{
|
|
|
|
return CatchResponse::success($this->permissions->updateBy($id, $request->param()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @time 2019年12月11日
|
|
|
|
* @param $id
|
|
|
|
* @throws FailedException
|
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
|
* @throws \think\db\exception\DbException
|
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
* @return \think\response\Json
|
|
|
|
*/
|
|
|
|
public function delete($id)
|
|
|
|
{
|
|
|
|
if ($this->permissions->where('parent_id', $id)->find()) {
|
|
|
|
throw new FailedException('存在子菜单,无法删除');
|
|
|
|
}
|
|
|
|
|
2019-12-12 09:13:29 +08:00
|
|
|
$this->permissions->findBy($id)->roles()->detach();
|
|
|
|
|
2019-12-11 21:00:14 +08:00
|
|
|
return CatchResponse::success($this->permissions->deleteBy($id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|