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