Files
lgp-admin-plus-api/app/Http/Controllers/Api/DepartmentController.php
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

48 lines
1.4 KiB
PHP
Raw 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
namespace App\Http\Controllers\Api;
use App\BaseApp\BaseController;
use App\Service\DepartmentService;
use Exception;
use Illuminate\Http\JsonResponse;
class DepartmentController extends BaseController
{
public function __construct()
{
parent::__construct();
$this->service = DepartmentService::getInstance();
// insertField / updateField 既是必填校验清单,也是入库字段白名单,漏写的字段不会被收进 params
$this->insertField = ['name'];
$this->updateField = ['id', 'name'];
// 这几个允许缺省pid 缺省为顶级status 缺省为正常
$this->notRequest = ['pid', 'desc', 'status', 'color'];
}
/**
* 部门树下拉(表单选上级部门用)
* @Method GET
*/
public function treeOption(): JsonResponse
{
$isSelect = filter_var(request()->get('is_select', false), FILTER_VALIDATE_BOOLEAN);
return jok($this->service->getTreeOption($isSelect), '列表获取成功');
}
/**
* 停用 / 启用部门
* @Method POST
* @throws Exception
*/
public function status(): JsonResponse
{
$id = request()->post('id');
$status = request()->post('status');
if (empty($id) || !in_array((string) $status, ['0', '1'], true)) {
return jerr('参数错误');
}
return jok($this->service->status($id, $status), '操作成功');
}
}