HeadNav.php 3.8 KB

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