| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\admin\controller;
- use think\Lang;
- class HeadNav extends AdminControl
- {
- public function _initialize()
- {
- parent::_initialize();
- Lang::load(APP_PATH . 'admin/lang/' . config('default_lang') . '/product.lang.php');
- }
- /**
- * 网站首页头部导航栏
- */
- public function index(){
- $model_headnav = Model('HeadNav');
- $headnav_keywords = input('post.product_keywords');
- $headnav_type = input('post.product_type');
- $condition = array();
- if($headnav_keywords){
- $condition['product_keywords'] = $headnav_keywords;
- }
- if($headnav_type){
- $condition['product_type'] = $headnav_type;
- }
- $headnav_list = $model_headnav->getHeadNav($condition,'*',10);
- for($i=0;$i<count($headnav_list);$i++){
- $headnav_list[$i]['nav_add_time'] = date("Y-m-d h:i:s",$headnav_list[$i]['nav_add_time']);
- $headnav_list[$i]['nav_update_time'] = date("Y-m-d h:i:s",$headnav_list[$i]['nav_update_time']);
- }
- $allpower = $this->qxhans();
- $this->assign('allpower',$allpower);
- $this->assign('headnav_list', $headnav_list);
- //$this->assign('show_page', $headnav_list->page_info->render());
- $this->setAdminCurItem('index');
- return $this->fetch();
- }
- /**
- * 添加头部导航
- * @return mixed
- */
- public function addHeadNav()
- {
- $allpower = $this->qxhans();
- $this->assign('allpower',$allpower);
- if (request()->isPost()) {
- $data = array(
- 'nav_name' => input('post.nav_name'),
- 'nav_sort' => input('post.nav_sort'),
- 'nav_add_time' => time(),
- 'nav_update_time' => time(),
- 'status' => input('post.status'),
- );
- $result = model('HeadNav')->addHeadNav($data);
- if ($result){
- $this->success(lang('add_succ'), url('HeadNav/index'));
- }
- $this->error(lang('add_fail'));
- } else {
- $headnav = array('status'=>1);
- $this->assign('headnav', $headnav);
- $this->setAdminCurItem('add');
- return $this->fetch('form');
- }
- }
- /**
- * 修改头部导航
- * @return mixed
- */
- public function edit()
- {
- $allpower = $this->qxhans();
- $this->assign('allpower',$allpower);
- $id = input('param.id');
- if ($id <= 0) {
- $this->error('系统错误');
- }
- $condition['id'] = $id;
- if (request()->isPost()) {
- $data = array(
- 'nav_name' => input('post.nav_name'),
- 'nav_sort' => input('post.nav_sort'),
- 'nav_update_time' => time(),
- 'status' => input('post.status'),
- );
- $result = model('HeadNav')->editHeadNav(['id' => $id], $data);
- if ($result >= 0) {
- $this->success(lang('edit_succ'), 'HeadNav/index');
- } else {
- $this->error(lang('edit_fail'));
- }
- } else {
- $headnav = model('HeadNav')->getOneHeadNav(['id' => $id]);
- $this->assign('headnav', $headnav);
- $this->setAdminCurItem('edit');
- return $this->fetch('form');
- }
- }
- /**
- * 删除头部导航
- * @return mixed
- */
- function del()
- {
- $id = intval(input('param.id'));
- if ($id) {
- $condition['id'] = $id;
- $result = model('HeadNav')->delHeadNav($condition);
- if ($result) {
- ds_json_encode(10000, lang('del_succ'));
- } else {
- ds_json_encode(10001, lang('del_fail'));
- }
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- }
- }
|