PostController.php
5.0 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?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('删除失败');
}
}
}