123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * 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));
- }
- }
|