NavController.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use app\admin\model\NavModel;
  14. use think\Db;
  15. /**
  16. * Class NavController 导航类别管理控制器
  17. * @package app\admin\controller
  18. */
  19. class NavController extends AdminBaseController
  20. {
  21. /**
  22. * 导航管理
  23. * @adminMenu(
  24. * 'name' => '导航管理',
  25. * 'parent' => 'admin/Setting/default',
  26. * 'display'=> true,
  27. * 'hasView'=> true,
  28. * 'order' => 30,
  29. * 'icon' => '',
  30. * 'remark' => '导航管理',
  31. * 'param' => ''
  32. * )
  33. */
  34. public function index()
  35. {
  36. $content = hook_one('admin_nav_index_view');
  37. if (!empty($content)) {
  38. return $content;
  39. }
  40. $navModel = new NavModel();
  41. $navs = $navModel->select();
  42. $this->assign('navs', $navs);
  43. return $this->fetch();
  44. }
  45. /**
  46. * 添加导航
  47. * @adminMenu(
  48. * 'name' => '添加导航',
  49. * 'parent' => 'index',
  50. * 'display'=> false,
  51. * 'hasView'=> true,
  52. * 'order' => 10000,
  53. * 'icon' => '',
  54. * 'remark' => '添加导航',
  55. * 'param' => ''
  56. * )
  57. */
  58. public function add()
  59. {
  60. return $this->fetch();
  61. }
  62. /**
  63. * 添加导航提交保存
  64. * @adminMenu(
  65. * 'name' => '添加导航提交保存',
  66. * 'parent' => 'index',
  67. * 'display'=> false,
  68. * 'hasView'=> false,
  69. * 'order' => 10000,
  70. * 'icon' => '',
  71. * 'remark' => '添加导航提交保存',
  72. * 'param' => ''
  73. * )
  74. */
  75. public function addPost()
  76. {
  77. $navModel = new NavModel();
  78. $arrData = $this->request->post();
  79. if (empty($arrData["is_main"])) {
  80. $arrData["is_main"] = 0;
  81. } else {
  82. $navModel->where("is_main", 1)->update(["is_main" => 0]);
  83. }
  84. $navModel->allowField(true)->insert($arrData);
  85. $this->success(lang("EDIT_SUCCESS"), url("nav/index"));
  86. }
  87. /**
  88. * 编辑导航
  89. * @adminMenu(
  90. * 'name' => '编辑导航',
  91. * 'parent' => 'index',
  92. * 'display'=> false,
  93. * 'hasView'=> true,
  94. * 'order' => 10000,
  95. * 'icon' => '',
  96. * 'remark' => '编辑导航',
  97. * 'param' => ''
  98. * )
  99. */
  100. public function edit()
  101. {
  102. $navModel = new NavModel();
  103. $intId = $this->request->param("id", 0, 'intval');
  104. $objNavCat = $navModel->where("id", $intId)->find();
  105. $arrNavCat = $objNavCat ? $objNavCat->toArray() : [];
  106. $this->assign($arrNavCat);
  107. return $this->fetch();
  108. }
  109. /**
  110. * 编辑导航提交保存
  111. * @adminMenu(
  112. * 'name' => '编辑导航提交保存',
  113. * 'parent' => 'index',
  114. * 'display'=> false,
  115. * 'hasView'=> false,
  116. * 'order' => 10000,
  117. * 'icon' => '',
  118. * 'remark' => '编辑导航提交保存',
  119. * 'param' => ''
  120. * )
  121. */
  122. public function editPost()
  123. {
  124. $navModel = new NavModel();
  125. $arrData = $this->request->post();
  126. if (empty($arrData["is_main"])) {
  127. $arrData["is_main"] = 0;
  128. } else {
  129. $navModel->where("is_main", 1)->update(["is_main" => 0]);
  130. }
  131. $navModel->allowField(true)->where("id", intval($arrData["id"]))->update($arrData);
  132. $this->success(lang("EDIT_SUCCESS"), url("nav/index"));
  133. }
  134. /**
  135. * 删除导航
  136. * @adminMenu(
  137. * 'name' => '删除导航',
  138. * 'parent' => 'index',
  139. * 'display'=> false,
  140. * 'hasView'=> false,
  141. * 'order' => 10000,
  142. * 'icon' => '',
  143. * 'remark' => '删除导航',
  144. * 'param' => ''
  145. * )
  146. */
  147. public function delete()
  148. {
  149. $navModel = new NavModel();
  150. $intId = $this->request->param("id", 0, "intval");
  151. if (empty($intId)) {
  152. $this->error(lang("NO_ID"));
  153. }
  154. $navModel->where("id", $intId)->delete();
  155. $this->success(lang("DELETE_SUCCESS"), url("nav/index"));
  156. }
  157. }