Navigation.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Navigation extends AdminControl {
  18. public function initialize() {
  19. parent::initialize();
  20. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/navigation.lang.php');
  21. }
  22. public function index() {
  23. $navigation_model = model('navigation');
  24. $condition = array();
  25. $nav_title = input('param.nav_title');
  26. if (!empty($nav_title)) {
  27. $condition[]=array('nav_title','like', "%" . $nav_title . "%");
  28. }
  29. $nav_location = input('param.nav_location');
  30. if (!empty($nav_location)) {
  31. $condition[]=array('nav_location','=',$nav_location);
  32. }
  33. $nav_list = $navigation_model->getNavigationList($condition, 10);
  34. View::assign('nav_list', $nav_list);
  35. View::assign('show_page', $navigation_model->page_info->render());
  36. $this->setAdminCurItem('index');
  37. return View::fetch();
  38. }
  39. public function add() {
  40. if (!(request()->isPost())) {
  41. $nav = [
  42. 'nav_location' => 'header',
  43. 'nav_new_open' => 0,
  44. ];
  45. View::assign('nav', $nav);
  46. return View::fetch('form');
  47. } else {
  48. $data['nav_title'] = input('post.nav_title');
  49. $data['nav_location'] = input('post.nav_location');
  50. $data['nav_url'] = input('post.nav_url');
  51. $data['nav_new_open'] = intval(input('post.nav_new_open'));
  52. $data['nav_sort'] = intval(input('post.nav_sort'));
  53. $navigation_validate = ds_validate('navigation');
  54. if (!$navigation_validate->scene('add')->check($data)) {
  55. $this->error($navigation_validate->getError());
  56. }
  57. $navigation_model= model('navigation');
  58. $result=$navigation_model->addNavigation($data);
  59. if ($result) {
  60. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  61. } else {
  62. $this->error(lang('error'));
  63. }
  64. }
  65. }
  66. public function edit() {
  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. $navigation_model= model('navigation');
  100. $nav_id = input('param.nav_id');
  101. $nav_id_array = ds_delete_param($nav_id);
  102. if($nav_id_array === FALSE){
  103. ds_json_encode('10001', lang('param_error'));
  104. }
  105. $condition = array(array('nav_id', 'in', $nav_id_array));
  106. $result =$navigation_model->delNavigation($condition);
  107. if ($result) {
  108. ds_json_encode('10000', lang('ds_common_del_succ'));
  109. } else {
  110. ds_json_encode('10001', lang('ds_common_del_fail'));
  111. }
  112. }
  113. /**
  114. * 获取卖家栏目列表,针对控制器下的栏目
  115. */
  116. protected function getAdminItemList() {
  117. $menu_array = array(
  118. array(
  119. 'name' => 'index',
  120. 'text' => lang('ds_manage'),
  121. 'url' => (string)url('Navigation/index')
  122. ),
  123. array(
  124. 'name' => 'add',
  125. 'text' => lang('ds_add'),
  126. 'url' => "javascript:dsLayerOpen('".(string)url('Navigation/add')."','".lang('ds_add')."')"
  127. ),
  128. );
  129. return $menu_array;
  130. }
  131. }