xiaoai/php_server/app/adminapi/controller/auth/RoleController.php

112 lines
2.6 KiB
PHP

<?php
namespace app\adminapi\controller\auth;
use app\adminapi\{
logic\auth\RoleLogic,
lists\auth\RoleLists,
validate\auth\RoleValidate,
controller\BaseAdminController
};
/**
* 角色控制器
* Class RoleController
* @package app\adminapi\controller\auth
*/
class RoleController extends BaseAdminController
{
/**
* @notes 查看角色列表
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 11:49
*/
public function lists()
{
return $this->dataLists(new RoleLists());
}
/**
* @notes 添加权限
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 11:49
*/
public function add()
{
$params = (new RoleValidate())->post()->goCheck('add');
$res = RoleLogic::add($params);
if (true === $res) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(RoleLogic::getError());
}
/**
* @notes 编辑角色
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 14:18
*/
public function edit()
{
$params = (new RoleValidate())->post()->goCheck('edit');
$res = RoleLogic::edit($params);
if (true === $res) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(RoleLogic::getError());
}
/**
* @notes 删除角色
* @return \think\response\Json
* @author 段誉
* @date 2021/12/29 14:18
*/
public function delete()
{
$params = (new RoleValidate())->post()->goCheck('del');
RoleLogic::delete($params['id']);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 查看角色详情
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2021/12/29 14:18
*/
public function detail()
{
$params = (new RoleValidate())->goCheck('detail');
$detail = RoleLogic::detail($params['id']);
return $this->data($detail);
}
/**
* @notes 获取角色数据
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/10/13 10:39
*/
public function all()
{
$result = RoleLogic::getAllData();
return $this->data($result);
}
}