Navigation.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 控制器
  15. */
  16. class Navigation extends AdminControl {
  17. public function initialize() {
  18. parent::initialize();
  19. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/navigation.lang.php');
  20. }
  21. public function index() {
  22. $navigation_model = model('navigation');
  23. $condition = array();
  24. $nav_title = input('param.nav_title');
  25. if (!empty($nav_title)) {
  26. $condition[]=array('nav_title','like', "%" . $nav_title . "%");
  27. }
  28. $nav_location = input('param.nav_location');
  29. if (!empty($nav_location)) {
  30. $condition[]=array('nav_location','=',$nav_location);
  31. }
  32. $nav_list = $navigation_model->getNavigationList($condition, 10);
  33. View::assign('nav_list', $nav_list);
  34. View::assign('show_page', $navigation_model->page_info->render());
  35. $this->setAdminCurItem('index');
  36. return View::fetch();
  37. }
  38. public function add() {
  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. $navigation_model= model('navigation');
  67. $nav_id = input('param.nav_id');
  68. if (empty($nav_id)) {
  69. $this->error(lang('param_error'));
  70. }
  71. if (!request()->isPost()) {
  72. $condition = array();
  73. $condition[] = array('nav_id','=',$nav_id);
  74. $nav=$navigation_model->getOneNavigation($condition);
  75. View::assign('nav', $nav);
  76. return View::fetch('form');
  77. } else {
  78. $data['nav_title'] = input('post.nav_title');
  79. $data['nav_location'] = input('post.nav_location');
  80. $data['nav_url'] = input('post.nav_url');
  81. $data['nav_new_open'] = intval(input('post.nav_new_open'));
  82. $data['nav_sort'] = intval(input('post.nav_sort'));
  83. $navigation_validate = ds_validate('navigation');
  84. if (!$navigation_validate->scene('edit')->check($data)) {
  85. $this->error($navigation_validate->getError());
  86. }
  87. $condition = array();
  88. $condition[] = array('nav_id','=',$nav_id);
  89. $result = $navigation_model->eidtNavigation($data,$condition);
  90. if ($result>=0) {
  91. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  92. } else {
  93. $this->error(lang('error'));
  94. }
  95. }
  96. }
  97. public function drop() {
  98. $navigation_model= model('navigation');
  99. $nav_id = input('param.nav_id');
  100. $nav_id_array = ds_delete_param($nav_id);
  101. if($nav_id_array === FALSE){
  102. ds_json_encode('10001', lang('param_error'));
  103. }
  104. $condition = array(array('nav_id', 'in', $nav_id_array));
  105. $result =$navigation_model->delNavigation($condition);
  106. if ($result) {
  107. ds_json_encode('10000', lang('ds_common_del_succ'));
  108. } else {
  109. ds_json_encode('10001', lang('ds_common_del_fail'));
  110. }
  111. }
  112. /**
  113. * 获取卖家栏目列表,针对控制器下的栏目
  114. */
  115. protected function getAdminItemList() {
  116. $menu_array = array(
  117. array(
  118. 'name' => 'index',
  119. 'text' => lang('ds_manage'),
  120. 'url' => (string)url('Navigation/index')
  121. ),
  122. array(
  123. 'name' => 'add',
  124. 'text' => lang('ds_add'),
  125. 'url' => "javascript:dsLayerOpen('".(string)url('Navigation/add')."','".lang('ds_add')."')"
  126. ),
  127. );
  128. return $menu_array;
  129. }
  130. }