CoaController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?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;
}
}
}
?>