| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 | <?php// +—————————————————————————————————————————————————————————————————————// | Created by Yunbao// +—————————————————————————————————————————————————————————————————————// | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.// +—————————————————————————————————————————————————————————————————————// | Author: https://gitee.com/yunbaokeji// +—————————————————————————————————————————————————————————————————————// | Date: 2022-04-30// +—————————————————————————————————————————————————————————————————————namespace app\admin\controller;use cmf\controller\AdminBaseController;use think\Db;use think\db\Query;class AdminpageController extends AdminBaseController{		protected function initialize()    {        parent::initialize();        $adminId = cmf_get_current_admin_id(); //获取后台管理员id,可判断是否登录        if (!empty($adminId)) {            $this->assign('admin_id', $adminId);        }    }		// 后台页面列表    public function index(){				//页面		$posts=Db::name('posts')			->where(function (Query $query) {				$data = $this->request->param();								$query->where('post_type', 1);				                if ($data['id']!='') {                    $query->where('id', $data['id']);                }								if ($data['termid']!='') {                    $query->where('termid', $data['termid']);                }				                if (!empty($data['keyword'])) {                    $keyword = $data['keyword'];                    $query->where('post_title|post_keywords', 'like', "%$keyword%");                }			})			->order("orderno DESC")            ->paginate(20);					$posts->each(function($v,$k){			$userinfo=Db::name("user")				->field("user_nicename")				->where("id='$v[post_author]'")				->find();							if(!$userinfo){				$userinfo=array(					'user_nicename'=>'已删除',				);			}							$v['userinfo']= $userinfo;						return $v;		});					//分页-->筛选条件参数		$data = $this->request->param();		$posts->appends($data);		    	// 获取分页显示        $page = $posts->render();	        $this->assign('posts', $posts);        $this->assign('page', $page);        $configpub=getConfigPub();		$this->assign("site",$configpub['site']);			        return $this->fetch();    }		//页面添加	public function add(){				//页面分类        				return $this->fetch();	}		public function add_post(){			$data = input('post.post');			if($data['post_type']==''){				$this->error("请至少选择一个分类!");			}else if(empty($data['post_title'])){				$this->error('请输入标题!');			}			$data['post_author']=cmf_get_current_admin_id(); //获取后台管理员id            $data['post_content']=html_entity_decode($data['post_content']);                    $data['post_status']='1';            $data['post_type']='1';            $data['post_date']=time();            			$add=Db::name('posts')->insert($data);			if($add){				$this->success('添加成功!');			}else{				$this->error('添加失败!');			}	}		//页面分类编辑	public function edit(){		$id = input('param.id');		if($id){								$info=Db::name('posts')->where('id',$id)->find();            $info['post_content']=str_replace('../../','/upload/',$info['post_content']);			$this->assign('info',$info);		}else{			$this->error('数据传入失败!');		}				return $this->fetch();	}		public function edit_post(){		$data = input('post.post');		if($data['post_type']==''){			$this->error("请至少选择一个分类!");		}else if(empty($data['post_title'])){			$this->error('请输入标题!');		}				$data['post_content']=html_entity_decode($data['post_content']);		$data['post_type']='1';		$save=Db::name('posts')->where('id',$data['id'])->update($data);					if($save){			$this->success('保存成功!');		}else{			$this->error('保存失败!');		}	}			// 页面分类删除	public function del(){        $id = input('param.id');        if($id){            $result=Db::name('posts')->delete($id);							if($result){				$this->success('删除成功');			 }else{				$this->error('删除失败');			 }			        }else{				            $this->error('数据传入失败!');        }								  			    }				// 页面批量删除	public function deletes(){		$data = input();		foreach ($data['ids'] as $k => $r) {            Db::name('posts')->where(['id'=>$r])->delete();        }		$status = true;		if ($status) {			$this->success("操作成功!");		} else {			$this->error("操作失败!");		}	}		// 页面排序	public function listordersset(){		$ids=$this->request->param('listordersset');        foreach ($ids as $key => $r) {            $data['orderno'] = $r;            Db::name("posts")				->where(array('id' => $key))				->update($data);        }				        $status = true;        if ($status) {            $this->success("排序更新成功!");        } else {            $this->error("排序更新失败!");        }    }			}
 |