CommonController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Models\Base\Department;
  13. use Illuminate\Support\Facades\Cache;
  14. use Jiannei\Response\Laravel\Support\Facades\Response;
  15. class CommonController extends Controller
  16. {
  17. /**
  18. * 枚举类型
  19. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource
  20. * Author: Mead
  21. */
  22. public function enums()
  23. {
  24. $data = trans('enums');
  25. $enums = [];
  26. foreach ($data as $key => $val) {
  27. $k = last(str2arr($key, '\\'));
  28. $enums[$k] = $val;
  29. }
  30. return Response::success($enums);
  31. }
  32. /**
  33. * 清空缓存
  34. * @return mixed
  35. * Author: Mead
  36. */
  37. public function clear()
  38. {
  39. Cache::flush();
  40. return Response::noContent();
  41. }
  42. /**
  43. * 部门列表
  44. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\Resource
  45. */
  46. public function departmentTree()
  47. {
  48. $departments = Department::query()->orderByDesc('sort')->select(['id', 'name', 'parent_id', 'sort', 'status'])->get()->append('parent_name')->toArray();
  49. return Response::success(toTree($departments));
  50. }
  51. }