HeadNav.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $this->setAdminCurItem('add');
  77. return $this->fetch('form');
  78. }
  79. }
  80. /**
  81. * 修改头部导航
  82. * @return mixed
  83. */
  84. public function edit()
  85. {
  86. $allpower = $this->qxhans();
  87. $this->assign('allpower',$allpower);
  88. $id = input('param.id');
  89. if ($id <= 0) {
  90. $this->error('系统错误');
  91. }
  92. $condition['id'] = $id;
  93. if (request()->isPost()) {
  94. $data = array(
  95. 'nav_name' => input('post.nav_name'),
  96. 'nav_sort' => input('post.nav_sort'),
  97. 'nav_update_time' => time(),
  98. 'status' => input('post.status'),
  99. );
  100. $result = model('HeadNav')->editHeadNav(['id' => $id], $data);
  101. if ($result >= 0) {
  102. $this->success(lang('edit_succ'), 'HeadNav/index');
  103. } else {
  104. $this->error(lang('edit_fail'));
  105. }
  106. } else {
  107. $headnav = model('HeadNav')->getOneHeadNav(['id' => $id]);
  108. $this->assign('headnav', $headnav);
  109. $this->setAdminCurItem('edit');
  110. return $this->fetch('form');
  111. }
  112. }
  113. /**
  114. * 删除头部导航
  115. * @return mixed
  116. */
  117. function del()
  118. {
  119. $id = intval(input('param.id'));
  120. if ($id) {
  121. $condition['id'] = $id;
  122. $result = model('HeadNav')->delHeadNav($condition);
  123. if ($result) {
  124. ds_json_encode(10000, lang('del_succ'));
  125. } else {
  126. ds_json_encode(10001, lang('del_fail'));
  127. }
  128. } else {
  129. ds_json_encode(10001, lang('param_error'));
  130. }
  131. }
  132. }