PostController.php 5.0 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;


class PostController extends AdminBaseController
{
    public  $table_name = 'portal_post';
    public function index()
    {
        $param = $this->request->param();

        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['post_title'] = ['like', "%$keyword%"];
        }

        $where['delete_time']=0;
        $where['post_type']=1;
        $list = DB::name($this->table_name)->where($where)->paginate(15);
        //echo DB::name($this->table_name)->getLastSql();

        $this->assign("list", $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }
  public function index2()
    {
        $param = $this->request->param();

        $keyword = empty($param['keyword']) ? '' : $param['keyword'];
        if (!empty($keyword)) {
            $where['post_title'] = ['like', "%$keyword%"];
        }

        $where['delete_time']=0;
        $where['post_type']= array('neq',1);
        $list = DB::name($this->table_name)->where($where)->paginate(15);
        //echo DB::name($this->table_name)->getLastSql();

        $this->assign("list", $list->items());
        $this->assign('page', $list->render());

        return $this->fetch();
    }

    public function add(){

        return $this->fetch();
    }

    public function add_do(){
        $data   = $this->request->param();
        if(!$data){
            $this->error('保存失败');
        }
        $datain['post_title'] = $data['post']['post_title'];
        $datain['post_excerpt'] = $data['post']['post_excerpt'];
        $datain['post_content'] = $data['post']['post_content'];
        $datain['post_keywords'] = $data['post']['post_keywords'];
        $datain['thumbnail'] = $data['post']['thumbnail'];
        $datain['banner'] = $data['post']['banner'];
        $datain['create_time'] = time();
        $datain['post_type'] = '1';


        $res = DB::name('portal_post')->insert($datain);
        if ($res) {
            $this->success('添加成功!', url('index'));
        }else{
            $this->error('添加失败!');
        }

        return $this->fetch();
    }
    public function edit_do(){
        $data   = $this->request->param();
        if(!$data){
            $this->error('保存失败');
        }
        $datain['id'] = $data['post']['id'];
        $datain['post_title'] = $data['post']['post_title'];
        $datain['post_keywords'] = $data['post']['post_keywords'];
        $datain['post_excerpt'] = $data['post']['post_excerpt'];
        $datain['post_content'] = $data['post']['post_content'];
        $datain['create_time'] = time();
        $datain['thumbnail'] = $data['post']['thumbnail'];
        $datain['banner'] = $data['post']['banner'];


        $res = DB::name('portal_post')->update($datain);
        if ($res) {
            $this->success('更新成功!', url('index'));
        }else{
            $this->error('添加失败!');
        }

        return $this->fetch();
    }
    public function edit_do1(){
        $data   = $this->request->param();
        if(!$data){
            $this->error('保存失败');
        }
        $datain['id'] = $data['post']['id'];
        $datain['post_title'] = $data['post']['post_title'];
        $datain['post_content'] = $data['post']['post_content'];
        $datain['post_keywords'] = $data['post']['post_keywords'];
        $datain['create_time'] = time();


        $res = DB::name('portal_post')->update($datain);
        if ($res) {
            $this->success('更新成功!', url('index2'));
        }else{
            $this->error('添加失败!');
        }

        return $this->fetch();
    }

    public function edit(){
        $id   = $this->request->param('id');
        $info = DB::name('portal_post')->where(['id'=>$id])->find();
        $this->assign('info', $info);
        return $this->fetch();
    }

    public function edit2(){
        $id   = $this->request->param('id');
        $info = DB::name('portal_post')->where(['id'=>$id])->find();
        $this->assign('info', $info);
        return $this->fetch();
    }

    //删
    public function delete()
    {
        $id                     = $this->request->param('id');

        $result = DB::name('portal_post')->where(['id'=>$id])->delete();
        if ($result) {
            $this->success('删除成功!');
        } else {
            $this->error('删除失败');
        }
    }

}