HeadNav.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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_url' => input('post.nav_url'),
  50. 'nav_sort' => input('post.nav_sort'),
  51. 'nav_add_time' => time(),
  52. 'nav_update_time' => time(),
  53. 'status' => '0',
  54. );
  55. }else{
  56. $data = array(
  57. 'nav_name' => input('post.nav_name'),
  58. 'nav_url' => input('post.nav_url'),
  59. 'nav_sort' => input('post.nav_sort'),
  60. 'nav_add_time' => time(),
  61. 'nav_update_time' => time(),
  62. 'status' => input('post.status'),
  63. );
  64. }
  65. $result = model('HeadNav')->addHeadNav($data);
  66. if ($result){
  67. $this->success(lang('add_succ'), url('HeadNav/index'));
  68. }
  69. $this->error(lang('add_fail'));
  70. } else {
  71. $headnav = array('status'=>1);
  72. $this->assign('headnav', $headnav);
  73. $this->setAdminCurItem('add');
  74. return $this->fetch('form');
  75. }
  76. }
  77. /**
  78. * 修改头部导航
  79. * @return mixed
  80. */
  81. public function edit()
  82. {
  83. $allpower = $this->qxhans();
  84. $this->assign('allpower',$allpower);
  85. $id = input('param.id');
  86. if ($id <= 0) {
  87. $this->error('系统错误');
  88. }
  89. $condition['id'] = $id;
  90. if (request()->isPost()) {
  91. $data = array(
  92. 'nav_name' => input('post.nav_name'),
  93. 'nav_url' => input('post.nav_url'),
  94. 'nav_sort' => input('post.nav_sort'),
  95. 'nav_update_time' => time(),
  96. 'status' => input('post.status'),
  97. );
  98. $result = model('HeadNav')->editHeadNav(['id' => $id], $data);
  99. if ($result >= 0) {
  100. $this->success(lang('edit_succ'), 'HeadNav/index');
  101. } else {
  102. $this->error(lang('edit_fail'));
  103. }
  104. } else {
  105. $headnav = model('HeadNav')->getOneHeadNav(['id' => $id]);
  106. $this->assign('headnav', $headnav);
  107. $this->setAdminCurItem('edit');
  108. return $this->fetch('form');
  109. }
  110. }
  111. /**
  112. * 删除头部导航
  113. * @return mixed
  114. */
  115. function del()
  116. {
  117. $id = intval(input('param.id'));
  118. if ($id) {
  119. $condition['id'] = $id;
  120. $result = model('HeadNav')->delHeadNav($condition);
  121. if ($result) {
  122. ds_json_encode(10000, lang('del_succ'));
  123. } else {
  124. ds_json_encode(10001, lang('del_fail'));
  125. }
  126. } else {
  127. ds_json_encode(10001, lang('param_error'));
  128. }
  129. }
  130. }