Navigation.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 控制器
  14. */
  15. class Navigation extends AdminControl
  16. {
  17. public function initialize()
  18. {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/navigation.lang.php');
  21. }
  22. public function index()
  23. {
  24. $navigation_model = model('navigation');
  25. $condition = array();
  26. $nav_title = input('param.nav_title');
  27. if (!empty($nav_title)) {
  28. $condition[] = array('nav_title', 'like', "%" . $nav_title . "%");
  29. }
  30. $nav_location = input('param.nav_location');
  31. if (!empty($nav_location)) {
  32. $condition[] = array('nav_location', '=', $nav_location);
  33. }
  34. $nav_list = $navigation_model->getNavigationList($condition, 10);
  35. View::assign('nav_list', $nav_list);
  36. View::assign('show_page', $navigation_model->page_info->render());
  37. $this->setAdminCurItem('index');
  38. return View::fetch();
  39. }
  40. public function add()
  41. {
  42. if (!(request()->isPost())) {
  43. $nav = [
  44. 'nav_location' => 'header',
  45. 'nav_new_open' => 0,
  46. ];
  47. View::assign('nav', $nav);
  48. return View::fetch('form');
  49. } else {
  50. $data['nav_title'] = input('post.nav_title');
  51. $data['nav_location'] = input('post.nav_location');
  52. $data['nav_url'] = input('post.nav_url');
  53. $data['nav_new_open'] = intval(input('post.nav_new_open'));
  54. $data['nav_sort'] = intval(input('post.nav_sort'));
  55. $navigation_validate = ds_validate('navigation');
  56. if (!$navigation_validate->scene('add')->check($data)) {
  57. $this->error($navigation_validate->getError());
  58. }
  59. $navigation_model = model('navigation');
  60. $result = $navigation_model->addNavigation($data);
  61. if ($result) {
  62. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  63. } else {
  64. $this->error(lang('error'));
  65. }
  66. }
  67. }
  68. public function edit()
  69. {
  70. $navigation_model = model('navigation');
  71. $nav_id = input('param.nav_id');
  72. if (empty($nav_id)) {
  73. $this->error(lang('param_error'));
  74. }
  75. if (!request()->isPost()) {
  76. $condition = array();
  77. $condition[] = array('nav_id', '=', $nav_id);
  78. $nav = $navigation_model->getOneNavigation($condition);
  79. View::assign('nav', $nav);
  80. return View::fetch('form');
  81. } else {
  82. $data['nav_title'] = input('post.nav_title');
  83. $data['nav_location'] = input('post.nav_location');
  84. $data['nav_url'] = input('post.nav_url');
  85. $data['nav_new_open'] = intval(input('post.nav_new_open'));
  86. $data['nav_sort'] = intval(input('post.nav_sort'));
  87. $navigation_validate = ds_validate('navigation');
  88. if (!$navigation_validate->scene('edit')->check($data)) {
  89. $this->error($navigation_validate->getError());
  90. }
  91. $condition = array();
  92. $condition[] = array('nav_id', '=', $nav_id);
  93. $result = $navigation_model->eidtNavigation($data, $condition);
  94. if ($result >= 0) {
  95. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  96. } else {
  97. $this->error(lang('error'));
  98. }
  99. }
  100. }
  101. public function drop()
  102. {
  103. $navigation_model = model('navigation');
  104. $nav_id = input('param.nav_id');
  105. $nav_id_array = ds_delete_param($nav_id);
  106. if ($nav_id_array === FALSE) {
  107. ds_json_encode('10001', lang('param_error'));
  108. }
  109. $condition = array(array('nav_id', 'in', $nav_id_array));
  110. $result = $navigation_model->delNavigation($condition);
  111. if ($result) {
  112. ds_json_encode('10000', lang('ds_common_del_succ'));
  113. } else {
  114. ds_json_encode('10001', lang('ds_common_del_fail'));
  115. }
  116. }
  117. /**
  118. * 获取卖家栏目列表,针对控制器下的栏目
  119. */
  120. protected function getAdminItemList()
  121. {
  122. $menu_array = array(
  123. array(
  124. 'name' => 'index',
  125. 'text' => lang('ds_manage'),
  126. 'url' => (string)url('Navigation/index')
  127. ),
  128. array(
  129. 'name' => 'add',
  130. 'text' => lang('ds_add'),
  131. 'url' => "javascript:dsLayerOpen('" . (string)url('Navigation/add') . "','" . lang('ds_add') . "')"
  132. ),
  133. );
  134. return $menu_array;
  135. }
  136. }