HeadNav.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. // $product = array(
  60. // 'product_isjump' => 0,
  61. // 'product_status' => 0,
  62. // 'product_type' => '',
  63. // 'product_usetime' => '',
  64. // );
  65. // $onlygs = array(
  66. // 'member_id' => 0,
  67. // 'member_name' =>"请选择所属公司",
  68. // );
  69. // $pic_list = model('pic')->getPicList(array('pic_id' => 0));
  70. // $allgs = model('member')->allcompany('');
  71. // $this->assign('allgs',$allgs);//所有开启的公司
  72. // $this->assign('product', $product);
  73. // $this->assign('onlygs',$onlygs);
  74. // $this->assign('product_pic_type', ['pic_type' => 'product']);
  75. // $this->assign('pic_list', $pic_list);
  76. $headnav = array('status'=>1);
  77. $this->assign('headnav', $headnav);
  78. $this->setAdminCurItem('add');
  79. return $this->fetch('form');
  80. }
  81. }
  82. /**
  83. * 修改头部导航
  84. * @return mixed
  85. */
  86. public function edit()
  87. {
  88. $allpower = $this->qxhans();
  89. $this->assign('allpower',$allpower);
  90. $id = input('param.id');
  91. if ($id <= 0) {
  92. $this->error('系统错误');
  93. }
  94. $condition['id'] = $id;
  95. if (request()->isPost()) {
  96. $data = array(
  97. 'nav_name' => input('post.nav_name'),
  98. 'nav_sort' => input('post.nav_sort'),
  99. 'nav_update_time' => time(),
  100. 'status' => input('post.status'),
  101. );
  102. $result = model('HeadNav')->editHeadNav(['id' => $id], $data);
  103. if ($result >= 0) {
  104. $this->success(lang('edit_succ'), 'HeadNav/index');
  105. } else {
  106. $this->error(lang('edit_fail'));
  107. }
  108. } else {
  109. $headnav = model('HeadNav')->getOneHeadNav(['id' => $id]);
  110. $this->assign('headnav', $headnav);
  111. $this->setAdminCurItem('edit');
  112. return $this->fetch('form');
  113. }
  114. }
  115. /**
  116. * 删除头部导航
  117. * @return mixed
  118. */
  119. function del()
  120. {
  121. $id = intval(input('param.id'));
  122. if ($id) {
  123. $condition['id'] = $id;
  124. $result = model('HeadNav')->delHeadNav($condition);
  125. if ($result) {
  126. ds_json_encode(10000, lang('del_succ'));
  127. } else {
  128. ds_json_encode(10001, lang('del_fail'));
  129. }
  130. } else {
  131. ds_json_encode(10001, lang('param_error'));
  132. }
  133. }
  134. }