194 lines
7.2 KiB
PHP
194 lines
7.2 KiB
PHP
<?php
|
|
/**
|
|
* Author: cfn <cfn@leapy.cn>
|
|
*/
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Annotation\Auth;
|
|
use App\Model\Menu as mModel;
|
|
use App\Model\Dept as dModel;
|
|
use App\Model\Role as rModel;
|
|
use App\Utils\Param;
|
|
use Hyperf\HttpServer\Annotation\Controller;
|
|
use Hyperf\HttpServer\Annotation\DeleteMapping;
|
|
use Hyperf\HttpServer\Annotation\GetMapping;
|
|
use Hyperf\HttpServer\Annotation\PostMapping;
|
|
use Hyperf\HttpServer\Annotation\PutMapping;
|
|
use App\Request\Menu as mRequest;
|
|
use App\Request\Role as rRequest;
|
|
use App\Request\Dept as dRequest;
|
|
|
|
#[Controller(prefix: "admin")]
|
|
class System extends Base
|
|
{
|
|
#[GetMapping(path: "menu/list")]
|
|
#[Auth(needAuth: false, auth: "menu:list")]
|
|
public function menuList()
|
|
{
|
|
return $this->success("菜单列表", mModel::getMenus(1));
|
|
}
|
|
|
|
#[GetMapping(path: "menu/option")]
|
|
#[Auth(needAuth: false, auth: "menu:option")]
|
|
public function menuOption()
|
|
{
|
|
// 菜单类型
|
|
return $this->success("菜单列表", mModel::getMenus(1));
|
|
}
|
|
|
|
#[PostMapping(path: "menu/add")]
|
|
#[Auth(needAuth: false, auth: "menu:add")]
|
|
public function menuAdd()
|
|
{
|
|
$data = Param::only(['pid' => 0, 'title' => '', 'account_type' => 1, 'type' => 0, 'method', 'flag', 'name',
|
|
'path', 'icon', 'rank', 'hidden', 'remark'
|
|
], $this->request->post());
|
|
$request = $this->container->get(mRequest::class);
|
|
$request->scene('add')->validateResolved();
|
|
$id = mModel::add($data);
|
|
return $id ? $this->success("操作成功", ['menu_id' => $id]) : $this->error("操作失败");
|
|
}
|
|
|
|
#[PutMapping(path: "menu/edit")]
|
|
#[Auth(needAuth: false, auth: "menu:edit")]
|
|
public function menuEdit()
|
|
{
|
|
$data = Param::only(['pid' => 0, 'title' => '', 'account_type' => 1, 'type' => 0, 'method', 'flag', 'name',
|
|
'path', 'icon', 'rank', 'hidden', 'remark', 'menu_id' => 0
|
|
], $this->request->post());
|
|
$request = $this->container->get(mRequest::class);
|
|
$request->scene('edit')->validateResolved();
|
|
$res = mModel::edit($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
#[DeleteMapping(path: "menu/del")]
|
|
#[Auth(needAuth: false, auth: "menu:del")]
|
|
public function menuDel()
|
|
{
|
|
$menu_id = $this->request->input("menu_id", "");
|
|
if (!$menu_id) return $this->error("请选择要删除的菜单");
|
|
$res = mModel::del($menu_id);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
#[PostMapping(path: "menu/quick")]
|
|
#[Auth(needAuth: false, auth: "menu:quick")]
|
|
public function menuQuickAdd()
|
|
{
|
|
$data = Param::only(['pid' => 0, 'title' => '', 'flag', 'name', 'path', 'icon', 'account_type' => 1], $this->request->post());
|
|
$request = $this->container->get(mRequest::class);
|
|
$request->scene('quick')->validateResolved();
|
|
$res = mModel::quickAdd($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
#[GetMapping(path: "dept/index")]
|
|
#[Auth(auth: "dept:index")]
|
|
public function deptIndex(): ResponseInterface
|
|
{
|
|
// 获取当前账号归属
|
|
$account = $this->request->getAttribute("account");
|
|
$dept_name = $this->request->input("dept_name", "");
|
|
return $this->success("菜单列表", Dept::depts($account['belong_id'], $account['account_type'], $dept_name));
|
|
}
|
|
|
|
#[GetMapping(path: "dept/option")]
|
|
#[Auth(needAuth: false)]
|
|
public function deptOption(): ResponseInterface
|
|
{
|
|
// 获取当前账号归属
|
|
$account = $this->request->getAttribute("account");
|
|
return $this->success("菜单列表", Dept::options($account['belong_id'], $account['account_type']));
|
|
}
|
|
|
|
#[PostMapping(path: "dept/add")]
|
|
#[Auth(auth: "dept:add")]
|
|
public function deptAdd()
|
|
{
|
|
$request = $this->container->get(DeptRequest::class);
|
|
$request->scene('add')->validateResolved();
|
|
$data = Com::only(['dept_name' => '', 'parent_id' => 0, 'rank', 'remark', 'status' => 1], $this->request->post());
|
|
$account = $this->request->getAttribute("account");
|
|
$data['belong_id'] = $account['belong_id'];
|
|
$data['belong'] = $account['account_type'];
|
|
$res = dModel::add($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
#[PutMapping(path: "dept/edit")]
|
|
#[Auth(auth: "dept:edit")]
|
|
public function deptEdit()
|
|
{
|
|
$request = $this->container->get(DeptRequest::class);
|
|
$request->scene('edit')->validateResolved();
|
|
$data = Com::only(['dept_id' => '', 'dept_name' => '', 'parent_id' => 0, 'rank', 'remark', 'status' => 1], $this->request->post());
|
|
$res = dModel::edit($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
#[DeleteMapping(path: "dept/del")]
|
|
#[Auth(auth: "dept:del")]
|
|
public function deptDel()
|
|
{
|
|
$dept_id = $this->request->input("dept_id", "");
|
|
if (!$dept_id) return $this->error("请选择要删除的菜单");
|
|
$res = dModel::del($dept_id);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
// 角色列表
|
|
#[GetMapping(path: "role/list")]
|
|
#[Auth(auth: "role:list")]
|
|
public function roleList()
|
|
{
|
|
$role_name = $this->request->input("role_name", "");
|
|
return $this->success("菜单列表", rModel::list($this->account['belong_id'], $this->account['account_type'], $role_name));
|
|
}
|
|
|
|
// 角色选择
|
|
#[GetMapping(path: "role/option")]
|
|
#[Auth(needAuth: false)]
|
|
public function roleOption()
|
|
{
|
|
return $this->success("菜单列表", rModel::options($this->account['belong_id'], $this->account['account_type']));
|
|
}
|
|
|
|
// 添加角色
|
|
#[PostMapping(path: "role/add")]
|
|
#[Auth(auth: "role:add")]
|
|
public function roleAdd()
|
|
{
|
|
$request = $this->container->get(rRequest::class);
|
|
$request->scene('add')->validateResolved();
|
|
$data = Param::only(['role_name' => '', 'menus' => [], 'remark', 'status' => 1, 'rank', "checked_menus"]);
|
|
$data['belong_id'] = $this->account['belong_id'];
|
|
$data['account_type'] = $this->account['account_type'];
|
|
$res = rModel::add($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
// 修改角色
|
|
#[PutMapping(path: "role/edit")]
|
|
#[Auth(auth: "role:edit")]
|
|
public function roleEdit()
|
|
{
|
|
$request = $this->container->get(rRequest::class);
|
|
$request->scene('edit')->validateResolved();
|
|
$data = Param::only(['role_id' => '', 'role_name' => '', 'menus' => [], 'remark', 'status' => 1, 'rank', "checked_menus"]);
|
|
$res = rModel::edit($data);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
|
|
// 删除角色
|
|
#[DeleteMapping(path: "role/del")]
|
|
#[Auth(auth: "role:del")]
|
|
public function roleDel()
|
|
{
|
|
$ids = $this->request->input("ids", "");
|
|
if (!$ids) return $this->error("请选择要删除的角色");
|
|
$res = rModel::del($ids);
|
|
return $res ? $this->success("操作成功") : $this->error("操作失败");
|
|
}
|
|
} |