CoaController.php 2.8 KB
<?php
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\AdminMenuModel;

class CoaController extends AdminBaseController{

  //说明文献显示
  public function index(){

    $data = Db::name('portal_category') -> select();
    $shuju = $this -> wuxian($data);
    foreach ($shuju as $key => $value) {
      $arr = explode('-', $value['path']);
      if(count($arr) == 4){
        $list[] = $value;
      }
    }
    $this -> assign('list',$list);
    return $this -> fetch();


  }

  public function wuxian($data,$pid=12){

    static $arr = [];
    foreach ($data as $key => $value) {
      if($value['parent_id'] == $pid){
        $arr[] = $value;
        $this -> wuxian($data,$value['id']);
      }
    }
    return $arr;

  }

  //点击编辑显示列表
  public function list(){
    $data   = $this->request->param();
    $this -> assign('data',$data);

    $shuju = Db::name('docu_coa') -> where('post_id',$data['id']) -> select();
    $this -> assign('shuju',$shuju);

    return $this -> fetch();


  }

  //显示添加页
  public function add(){
    $data   = $this->request->param();
    $this -> assign('data',$data);
    return $this -> fetch();


  }

  //添加数据
  public function wzadd(){

    $data   = $this->request->param();

    $shuju['title'] = $data['post']['post_title'];
    $shuju['content'] = $data['post']['post_content'];
    $shuju['fenlei'] = $data['post']['post_leibie'];
    $shuju['time'] = time();
    $shuju['post_id'] = $data['post']['post_id'];
    $data2 = Db::name('docu_coa') -> insert($shuju);
    if($data2){
        $this -> success('添加成功',url('Coa/list',array('id'=>$shuju['post_id'])));
    }else{
        $this -> error('添加失败');
    }

  }


  //编辑数据
  public function edit(){

    $data   = $this->request->param();
    if($this->request->isPost()){

      $shuju1['title'] = $data['post']['post_title'];
      $shuju1['content'] = $data['post']['post_content'];
      $shuju1['fenlei'] = $data['post']['post_leibie'];
      $shuju1['post_id'] = $data['post']['post_id'];

      $res = Db::name('docu_coa') -> where('id',$data['post']['id']) -> update($shuju1);

     /* if($res){

      }else{
        $this -> error('修改失败');
      }*/
      $this -> success('修改成功',url('Coa/list',array('id'=>$shuju1['post_id'])));
    }else{

        $this -> assign('data',$data);
        $shuju = Db::name('docu_coa') -> where('id',$data['id']) -> find();
        $shuju['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($shuju['content']));
        $this -> assign('shuju',$shuju);
        return $this-> fetch();
    }



  }


  //删除数据
  public function del(){

    $id = input('post.id');
    $data = Db::name('docu_coa') -> delete($id);
    if($data){
      return true;
    }else{
      return false;
    }


  }





}











 ?>