* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace App\Http\Controllers\Admin\Base; use App\Http\Controllers\Controller; use App\Repositories\Enums\ResponseCodeEnum; use App\Repositories\Models\Base\Department; use Illuminate\Support\Facades\Cache; use Jiannei\Response\Laravel\Support\Facades\Response; class CommonController extends Controller { /** * 枚举类型 * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource * Author: Mead */ public function enums() { $data = trans('enums'); $enums = []; foreach ($data as $key => $val) { $k = last(str2arr($key, '\\')); $enums[$k] = $val; } return Response::success($enums); } /** * 清空缓存 * @return mixed * Author: Mead */ public function clear() { $admin = login_admin(); if (!$admin || !$admin->isSuperAdmin()) { abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '您暂无权限操作'); } Cache::flush(); return Response::noContent(); } /** * 部门列表 * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource */ public function departmentTree() { $departments = Department::query()->orderByDesc('sort')->select(['id', 'name', 'parent_id', 'sort', 'status'])->get()->append('parent_name')->toArray(); return Response::success(toTree($departments)); } }