HeadNav.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Lang;
  4. class HeadNav extends AdminControl
  5. {
  6. public function _initialize()
  7. {
  8. parent::_initialize();
  9. Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/product.lang.php');
  10. }
  11. /**
  12. * 网站首页头部导航栏
  13. */
  14. public function index(){
  15. $model_headnav = Model('HeadNav');
  16. $headnav_keywords = input('post.product_keywords');
  17. $headnav_type = input('post.product_type');
  18. $condition = array();
  19. if($headnav_keywords){
  20. $condition['product_keywords'] = $headnav_keywords;
  21. }
  22. if($headnav_type){
  23. $condition['product_type'] = $headnav_type;
  24. }
  25. $headnav_list = $model_headnav->getHeadNav($condition,'*',10);
  26. for($i=0;$i<count($headnav_list);$i++){
  27. $headnav_list[$i]['nav_add_time'] = date("Y-m-d h:i:s",$headnav_list[$i]['nav_add_time']);
  28. $headnav_list[$i]['nav_update_time'] = date("Y-m-d h:i:s",$headnav_list[$i]['nav_update_time']);
  29. }
  30. $allpower = $this->qxhans();
  31. $this->assign('allpower',$allpower);
  32. $this->assign('headnav_list', $headnav_list);
  33. //$this->assign('show_page', $headnav_list->page_info->render());
  34. $this->setAdminCurItem('index');
  35. return $this->fetch();
  36. }
  37. /**
  38. * 添加头部导航
  39. * @return mixed
  40. */
  41. public function addHeadNav()
  42. {
  43. $allpower = $this->qxhans();
  44. $this->assign('allpower',$allpower);
  45. if (request()->isPost()) {
  46. if(input('post.status') == ""){
  47. $data = array(
  48. 'nav_name' => input('post.nav_name'),
  49. 'nav_sort' => input('post.nav_sort'),
  50. 'nav_add_time' => time(),
  51. 'nav_update_time' => time(),
  52. 'status' => '0',
  53. );
  54. }else{
  55. $data = array(
  56. 'nav_name' => input('post.nav_name'),
  57. 'nav_sort' => input('post.nav_sort'),
  58. 'nav_add_time' => time(),
  59. 'nav_update_time' => time(),
  60. 'status' => input('post.status'),
  61. );
  62. }
  63. $result = model('HeadNav')->addHeadNav($data);
  64. if ($result){
  65. $this->success(lang('add_succ'), url('HeadNav/index'));
  66. }
  67. $this->error(lang('add_fail'));
  68. } else {
  69. $headnav = array('status'=>1);
  70. $this->assign('headnav', $headnav);
  71. $this->setAdminCurItem('add');
  72. return $this->fetch('form');
  73. }
  74. }
  75. /**
  76. * 修改头部导航
  77. * @return mixed
  78. */
  79. public function edit()
  80. {
  81. $allpower = $this->qxhans();
  82. $this->assign('allpower',$allpower);
  83. $id = input('param.id');
  84. if ($id <= 0) {
  85. $this->error('系统错误');
  86. }
  87. $condition['id'] = $id;
  88. if (request()->isPost()) {
  89. $data = array(
  90. 'nav_name' => input('post.nav_name'),
  91. 'nav_sort' => input('post.nav_sort'),
  92. 'nav_update_time' => time(),
  93. 'status' => input('post.status'),
  94. );
  95. $result = model('HeadNav')->editHeadNav(['id' => $id], $data);
  96. if ($result >= 0) {
  97. $this->success(lang('edit_succ'), 'HeadNav/index');
  98. } else {
  99. $this->error(lang('edit_fail'));
  100. }
  101. } else {
  102. $headnav = model('HeadNav')->getOneHeadNav(['id' => $id]);
  103. $this->assign('headnav', $headnav);
  104. $this->setAdminCurItem('edit');
  105. return $this->fetch('form');
  106. }
  107. }
  108. /**
  109. * 删除头部导航
  110. * @return mixed
  111. */
  112. function del()
  113. {
  114. $id = intval(input('param.id'));
  115. if ($id) {
  116. $condition['id'] = $id;
  117. $result = model('HeadNav')->delHeadNav($condition);
  118. if ($result) {
  119. ds_json_encode(10000, lang('del_succ'));
  120. } else {
  121. ds_json_encode(10001, lang('del_fail'));
  122. }
  123. } else {
  124. ds_json_encode(10001, lang('param_error'));
  125. }
  126. }
  127. }