Article.php
13.7 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* Date: 2015-09-09
*/
namespace app\admin\controller;
use think\Page;
use app\admin\logic\ArticleCatLogic;
use think\Db;
use qcloudcos\Conf;
use qcloudcos\Myqcloudcos;
class Article extends Base {
private $article_system_id = array(1, 2, 3, 4, 5);//系统默认的文章分类id,不可删除
private $article_main_system_id = array(1, 2);//系统保留分类,不允许在该分类添加文章
private $article_top_system_id = array(1);//系统分类,不允许在该分类添加新的分类
private $article_able_id = array(1);//系统预定义文章id,不能删除。此文章用于商品详情售后服务
public function _initialize()
{
parent::_initialize();
$this->assign('article_top_system_id', $this->article_top_system_id);
$this->assign('article_system_id', $this->article_system_id);
$this->assign('article_main_system_id', $this->article_main_system_id);
$this->assign('article_able_id',$this->article_able_id);
}
public function categoryList(){
$ArticleCat = new ArticleCatLogic();
$cat_list = $ArticleCat->article_cat_list(0, 0, false);
$type_arr = array('系统默认','系统帮助','系统公告');
$this->assign('type_arr',$type_arr);
$this->assign('cat_list',$cat_list);
$this->assign('store_id',getAdmStoId());
// upload_ylp_log('文章分类');
return $this->fetch('categoryList',getAdmStoId());
}
public function category(){
$ArticleCat = new ArticleCatLogic();
$act = I('get.act','add');
$this->assign('act',$act);
$cat_id = I('get.cat_id/d');
$cat_info = array();
if($cat_id){
$cat_info = D('article_cat')->where('cat_id',$cat_id)->find();
$this->assign('cat_info',$cat_info);
}
else {
$m = Db::query("select max(sort_order)odr from __PREFIX__article_cat where store_id=" . getAdmStoId());
$md = (int)$m[0]["odr"];
$md++;
$cat_info["sort_order"] = $md;
$this->assign('cat_info',$cat_info);
}
$p_id = I('get.parent_id/d');
if(empty($p_id)) $p_id=$cat_info['parent_id'];
$cats = $ArticleCat->article_cat_list(0,$p_id,true);
$this->assign('cat_select',$cats);
return $this->fetch('',getAdmStoId());
}
public function articleList(){
$Article = M('Article');
$pagenum=20;//每页显示多少条
if ((int)I('pagenum/s')>0)
{
$pagenum=I('pagenum/s');
}
$list = array();
$p = input('p/d', 1);
$size = input('size/d', $pagenum);
$where = array();
/*--添加门店ID--*/
$where["store_id"]=getAdmStoId();
$keywords = trim(I('keywords'));
$keywords && $where['title'] = array('like', '%' . $keywords . '%');
$cat_id = I('cat_id/d',0);
$cat_id && $where['cat_id'] = $cat_id;
$res = $Article->where($where)->order('add_time desc')->page("$p,$size")->select();
$count = $Article->where($where)->count();// 查询满足要求的总记录数
$pager = new Page($count,$size);// 实例化分页类 传入总记录数和每页显示的记录数
$page = $pager->show();//分页显示输出
$ArticleCat = new ArticleCatLogic();
$cats = $ArticleCat->article_cat_list(0,0,false);
if($res){
foreach ($res as $val){
$val['category'] = $cats[$val['cat_id']]['cat_name'];
$val['add_time'] = date('Y-m-d H:i:s',$val['add_time']);
$list[] = $val;
}
}
$this->assign('cats',$cats);
$this->assign('cat_id',$cat_id);
$this->assign('list',$list);// 赋值数据集
$this->assign('page',$page);// 赋值分页输出
$this->assign('pager',$pager);
$this->assign('store_id',getAdmStoId());
$this->assign('pagenum',$pagenum);
$this->assign('oldurl',urlencode(curPageURL()));
// upload_ylp_log('文章列表');
return $this->fetch('articleList',getAdmStoId());
}
public function article(){
$ArticleCat = new ArticleCatLogic();
$act = I('get.act','add');
$oldurl = I('oldurl/s');
$info = array();
$info['publish_time'] = time();
$info['add_time'] =time();
$article_id = I('get.article_id/d');
if($article_id){
$info = D('article')->where('article_id', $article_id)->find();
}
$cats = $ArticleCat->article_cat_list(0,$info['cat_id']); //第一个分类
$cats2 = $ArticleCat->article_cat_list(0,$info['cat_id2']); //第二个分类
$this->assign('cat_select',$cats);
$this->assign('cat_select2',$cats2);
$this->assign('act',$act);
$this->assign('info',$info);
$this->assign('erpid',getERPId());
$this->assign('oldurl', $oldurl);
$this->initEditor();
return $this->fetch('',getAdmStoId());
}
/**
* 初始化编辑器链接
* @param $post_id post_id
*/
private function initEditor()
{
$this->assign("URL_upload", U('Admin/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_fileUp", U('Admin/Ueditor/fileUp',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_imageManager", U('Admin/Ueditor/imageManager',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_imageUp", U('Admin/Ueditor/imageUp',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_getMovie", U('Admin/Ueditor/getMovie',array('savepath'=>'article','savepath1'=>getERPId())));
$this->assign("URL_Home", "");
}
/*--添加分类--*/
public function categoryHandle(){
ClearALLCache();
delFile(TEMP_PATH."/".getAdmStoId());
$data = I('post.');
if($data['act'] == 'add'){
// upload_ylp_log('增加文章分类');
$data["store_id"]=getAdmStoId();
$d = D('article_cat')->add($data);
}
if($data['act'] == 'edit')
{
// upload_ylp_log('编辑文章分类');
if ($data['cat_id'] == $data['parent_id'])
{
$this->error("所选分类的上级分类不能是当前分类",U('Admin/Article/category',array('cat_id'=>$data['cat_id'])));
}
$ArticleCat = new ArticleCatLogic();
$children = array_keys($ArticleCat->article_cat_list($data['cat_id'], 0, false)); // 获得当前分类的所有下级分类
if (in_array($data['parent_id'], $children))
{
$this->error("所选分类的上级分类不能是当前分类的子分类",U('Admin/Article/category',array('cat_id'=>$data['cat_id'])));
}
unset($data['act']);
$q=D('article_cat')->where("cat_id",$data['cat_id'])->where($data)->find();
if($q){
$this->error("未做修改",U('Admin/Article/categoryList'));
}
upload_ylp_log('A14分类编辑/确认提交');
$d = D('article_cat')->where("cat_id",$data['cat_id'])->save($data);
}
if($data['act'] == 'del'){
// upload_ylp_log('删除文章分类');
if(array_key_exists($data['cat_id'],$this->article_system_id)){
exit(json_encode('系统预定义的分类不能删除'));
}
$res = D('article_cat')->where('parent_id', $data['cat_id'])->select();
if ($res)
{
exit(json_encode('还有子分类,不能删除'));
}
$res = D('article')->where('cat_id', $data['cat_id'])->select();
if ($res)
{
exit(json_encode('非空的分类不允许删除'));
}
$r = D('article_cat')->where('cat_id', $data['cat_id'])->delete();
if($r) exit(json_encode(1));
}
if($d){
$this->success("操作成功",U('Admin/Article/categoryList'));
}else{
$this->error("操作失败",U('Admin/Article/categoryList'));
}
}
public function aticleHandle(){
ClearALLCache();
delFile(TEMP_PATH."/".getAdmStoId());
$oldurl = I('oldurl/s');
if($oldurl){
$oldurl = urldecode(urldecode($oldurl));
}
$data = I('post.');
unset($data['oldurl']);
$data['content'] = I('content'); // 文章内容单独过滤
$data['publish_time'] = strtotime($data['publish_time']);
$url = $this->request->server('HTTP_REFERER');
if($oldurl){
$referurl=$oldurl;
}
else {
$referurl = !empty($url) ? $url : U('Admin/Article/articleList');
}
//$data['content'] = htmlspecialchars(stripslashes($_POST['content']));
/*--添加新文章--*/
if($data['act'] == 'add'){
upload_ylp_log('A13新增文章/确认提交');
if(array_key_exists($data['cat_id'],$this->article_main_system_id)){
$this->error("不能在系统保留分类下添加文章,操作失败",$referurl);
}
$data['click'] = mt_rand(1000,1300);
$data['add_time'] = time();
$data['store_id'] = getAdmStoId();
$r = D('article')->add($data);
}
if($data['act'] == 'edit'){
// upload_ylp_log('编辑文章');
unset($data['act']);
$q=M('article')->where('article_id', $data['article_id'])->where($data)->find();
if($q){
$this->success("操作成功",$referurl);
// $this->error("未做修改",$referurl);
exit;
}
$r = M('article')->where('article_id', $data['article_id'])->save($data);
}
if($data['act'] == 'del') {
// upload_ylp_log('删除文章');
$d = D('article')->where('article_id', $data['article_id'])->find();
if ($d) {
if (array_key_exists($data['article_id'], $this->article_able_id)) {
exit(json_encode('系统预定义的文章不能删除'));
}
//删除腾讯云图片
vendor ('qcloudcos.myqcloudcos');
/*--删除缩略图--*/
$url=$d["thumb"];
if(!empty($url)){
Myqcloudcos::delFile('wxd',$url);
mdelFile(ROOT_PATH.$url);
}
$geteditorimg=explode(",", $d["editorimg"]);
foreach($geteditorimg as $k=>$v){
Myqcloudcos::delFile('wxd',$v);
}
$r = D('article')->where('article_id', $data['article_id'])->delete();
if ($r) exit(json_encode(1));
}else{
exit(json_encode(-1));
}
}
if($r){
$this->success("操作成功",$referurl);
}else{
$this->error("操作失败",$referurl);
}
}
public function link(){
$act = I('get.act','add');
$this->assign('act',$act);
$link_id = I('get.link_id/d');
$link_info = array();
if($link_id){
$link_info = D('friend_link')->where('link_id', $link_id)->find();
}
$this->assign('info',$link_info);
return $this->fetch('',getAdmStoId());
}
public function linkList(){
$Ad = M('friend_link');
$p = $this->request->param('p');
$res = $Ad->where('1=1')->order('orderby')->page($p.',10')->select();
if($res){
foreach ($res as $val){
$val['target'] = $val['target']>0 ? '开启' : '关闭';
$list[] = $val;
}
}
$this->assign('list',$list);// 赋值数据集
$count = $Ad->where('1=1')->count();// 查询满足要求的总记录数
$Page = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
$show = $Page->show();// 分页显示输出
$this->assign('pager',$Page);// 赋值分页输出
$this->assign('page',$show);// 赋值分页输出
return $this->fetch('',getAdmStoId());
}
public function linkHandle(){
ClearALLCache();
delFile(TEMP_PATH."/".getAdmStoId());
$data = I('post.');
if($data['act'] == 'add'){
stream_context_set_default(array('http'=>array('timeout' =>2)));
// send_http_status('311');
$r = D('friend_link')->insert($data);
}
if($data['act'] == 'edit'){
$r = D('friend_link')->where('link_id', $data['link_id'])->save($data);
}
if($data['act'] == 'del'){
$r = D('friend_link')->where('link_id', $data['link_id'])->delete();
if($r) exit(json_encode(1));
}
if($r){
$this->success("操作成功",U('Admin/Article/linkList'));
}else{
$this->error("操作失败",U('Admin/Article/linkList'));
}
}
}