Topic.php
3.29 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
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* 专题管理
* Date: 2015-09-09
*/
namespace app\admin\controller;
use think\Page;
class Topic extends Base {
public function index(){
return $this->fetch('',getAdmStoId());
}
public function topic(){
$act = I('GET.act','add');
$this->assign('act',$act);
$topic_id = I('GET.topic_id');
$topic_info = array();
if($topic_id){
$topic_info = D('topic')->where('topic_id='.$topic_id)->find();
$this->assign('info',$topic_info);
}
$this->assign("URL_upload", U('Admin/Ueditor/imageUp',array('savepath'=>'topic')));
$this->assign("URL_fileUp", U('Admin/Ueditor/fileUp',array('savepath'=>'topic')));
$this->assign("URL_scrawlUp", U('Admin/Ueditor/scrawlUp',array('savepath'=>'topic')));
$this->assign("URL_getRemoteImage", U('Admin/Ueditor/getRemoteImage',array('savepath'=>'topic')));
$this->assign("URL_imageManager", U('Admin/Ueditor/imageManager',array('savepath'=>'topic')));
$this->assign("URL_imageUp", U('Admin/Ueditor/imageUp',array('savepath'=>'topic')));
$this->assign("URL_getMovie", U('Admin/Ueditor/getMovie',array('savepath'=>'topic')));
$this->assign("URL_Home", "");
return $this->fetch('',getAdmStoId());
}
public function topicList(){
$Ad = M('topic');
$p = $this->request->param('p');
$res = $Ad->where('1=1')->order('ctime')->page($p.',10')->select();
if($res){
foreach ($res as $val){
$val['topic_state'] = $val['topic_state']>1 ? '已发布' : '未发布';
$val['ctime'] = date('Y-m-d H:i',$val['ctime']);
$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 topicHandle(){
$data = I('post.');
$data['topic_content'] = $_POST['topic_content']; // 这个内容不做转义
if($data['act'] == 'add'){
$data['ctime'] = time();
$r = D('topic')->add($data);
}
if($data['act'] == 'edit'){
$r = D('topic')->where('topic_id='.$data['topic_id'])->save($data);
}
if($data['act'] == 'del'){
$r = D('topic')->where('topic_id='.$data['topic_id'])->delete();
if($r) exit(json_encode(1));
}
if($r){
$this->success("操作成功",U('Admin/Topic/topicList'));
}else{
$this->error("操作失败",U('Admin/Topic/topicList'));
}
}
}