113 lines
2.9 KiB
PHP
113 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\System;
|
|
|
|
use App\Http\Controllers\BaseController;
|
|
use App\Http\Requests\Admin\System\SystemRoleRequest;
|
|
use App\Services\System\SystemRoleService;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
/**
|
|
* 系统角色控制器
|
|
*/
|
|
class SystemRoleController extends BaseController
|
|
{
|
|
public function __construct(
|
|
private SystemRoleService $systemRoleService
|
|
) {}
|
|
|
|
/**
|
|
* 获取系统角色列表
|
|
*/
|
|
public function list(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemRoleService->getList($params);
|
|
|
|
return $this->SuccessPage($result->items(), $result->total());
|
|
}
|
|
|
|
/**
|
|
* 获取简单列表
|
|
*/
|
|
public function simpleList(): JsonResponse
|
|
{
|
|
$result = $this->systemRoleService->getSimpleList();
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取系统角色详情
|
|
*/
|
|
public function detail(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemRoleService->detail($params['id']);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 创建系统角色
|
|
*/
|
|
public function create(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$data = $request->validated();
|
|
$result = $this->systemRoleService->create($data);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 更新系统角色
|
|
*/
|
|
public function update(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$result = $this->systemRoleService->update($params['id'], $params);
|
|
return $this->Success($result);
|
|
}
|
|
|
|
/**
|
|
* 删除系统角色
|
|
*/
|
|
public function delete(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->systemRoleService->delete($params['id']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 批量删除系统角色
|
|
*/
|
|
public function batchDelete(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->systemRoleService->batchDelete($params['ids']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 批量更新状态
|
|
*/
|
|
public function batchUpdateStatus(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$this->systemRoleService->batchUpdateStatus($params['ids'], $params['status']);
|
|
return $this->Success();
|
|
}
|
|
|
|
/**
|
|
* 检查角色编码是否存在
|
|
*/
|
|
public function checkCode(SystemRoleRequest $request): JsonResponse
|
|
{
|
|
$params = $request->validated();
|
|
$exists = $this->systemRoleService->checkCodeExists(
|
|
$params['code'],
|
|
$params['id'] ?? null
|
|
);
|
|
|
|
return $this->Success(['exists' => $exists]);
|
|
}
|
|
}
|