CommonController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the Jiannei/lumen-api-starter.
  4. *
  5. * (c) Jiannei <longjian.huang@foxmail.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace App\Http\Controllers\Admin\Base;
  11. use App\Http\Controllers\Controller;
  12. use App\Repositories\Enums\ResponseCodeEnum;
  13. use App\Repositories\Models\Base\Department;
  14. use Illuminate\Support\Facades\Cache;
  15. use Jiannei\Response\Laravel\Support\Facades\Response;
  16. class CommonController extends Controller
  17. {
  18. /**
  19. * 枚举类型
  20. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource
  21. * Author: Mead
  22. */
  23. public function enums()
  24. {
  25. $data = trans('enums');
  26. $enums = [];
  27. foreach ($data as $key => $val) {
  28. $k = last(str2arr($key, '\\'));
  29. $enums[$k] = $val;
  30. }
  31. return Response::success($enums);
  32. }
  33. /**
  34. * 清空缓存
  35. * @return mixed
  36. * Author: Mead
  37. */
  38. public function clear()
  39. {
  40. $admin = login_admin();
  41. if (!$admin || !$admin->isSuperAdmin()) {
  42. abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '您暂无权限操作');
  43. }
  44. Cache::flush();
  45. return Response::noContent();
  46. }
  47. /**
  48. * 部门列表
  49. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource
  50. */
  51. public function departmentTree()
  52. {
  53. $departments = Department::query()->orderByDesc('sort')->select(['id', 'name', 'parent_id', 'sort', 'status'])->get()->append('parent_name')->toArray();
  54. return Response::success(toTree($departments));
  55. }
  56. }