SysMenu.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018-2020 rights reserved.
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // | Date: 2020-08-31 20:43
  10. // +----------------------------------------------------------------------
  11. namespace app\system\controller;
  12. use app\BaseController;
  13. use app\model\system\AdminMenu;
  14. use app\Request;
  15. use library\services\UtilService;
  16. use library\utils\Dtree;
  17. class SysMenu extends BaseController
  18. {
  19. /**
  20. * 基本设置
  21. */
  22. public function list()
  23. {
  24. $menuMenu = new AdminMenu();
  25. $menus = $menuMenu->getArMenu();
  26. return app('json')->success($menus);
  27. }
  28. /**
  29. * 系统分类显示 | 关闭
  30. */
  31. public function status(Request $request)
  32. {
  33. [$id, $is_show] = UtilService::getMore([
  34. ['id', '0', 'empty', '参数错误'],
  35. ['is_show', '0'],
  36. ], $request, true);
  37. $bool = (new AdminMenu())->setStatus($id, $is_show);
  38. if ($bool) {
  39. return app('json')->success('操作成功');
  40. } else {
  41. return app('json')->fail('提交失败');
  42. }
  43. }
  44. /**
  45. * 获取树级分类
  46. */
  47. public function treeList()
  48. {
  49. $menuAr = (new AdminMenu())->order("seq", "desc")->select()->toArray();
  50. $data = sort_list_tier($menuAr, '顶级', 'pid', 'id');
  51. return app('json')->success($data);
  52. }
  53. /**
  54. * 获取详情栏目数据
  55. */
  56. public function info(Request $request)
  57. {
  58. [$id] = UtilService::getMore([
  59. ['id', 0, 'empty', '参数错误'],
  60. ], $request, true);
  61. $data = (new AdminMenu())->field("title,id,icon,path,is_show,pid,code,seq")->find(compact('id'))->toArray();
  62. return app('json')->success($data);
  63. }
  64. /**
  65. * 保存数据
  66. */
  67. public function save(Request $request)
  68. {
  69. $post = UtilService::getMore([
  70. ['title', ''],
  71. ['pid', '0'],
  72. ['seq', '0'],
  73. ['path', ''],
  74. ['icon', ''],
  75. ['is_show', '0'],
  76. ['code', ''],
  77. ['id', '0'],
  78. ], $request);
  79. (new AdminMenu())->saveMenu($post);
  80. return app('json')->success("数据保存成功");
  81. }
  82. /**
  83. * 栏目删除
  84. * @param Request $request
  85. * @return mixed
  86. */
  87. public function del(Request $request)
  88. {
  89. [$id] = UtilService::getMore([
  90. ['id', 0, 'empty', '参数错误'],
  91. ], $request, true);
  92. $bool = (new AdminMenu())->delMenu($id);
  93. return app('json')->success("栏目删除成功");
  94. }
  95. }