ZjNewsController.php
3.2 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
<?php
/**
* Created by PhpStorm.
* User: wz
* Date: 2018/9/20
* Time: 16:20
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class ZjNewsController extends AdminBaseController
{
/**
* 系统消息列表
*/
public function index(){
$all=Db::name('zj_news')->where('delete_time','0')->order('create_time','desc')->paginate('15');
$this->assign('page',$all->render());
$this->assign('all',$all->items());
return $this->fetch();
}
/**
* 添加系统消息
*/
public function add(){
return $this->fetch();
}
/**
* 添加系统消息提交
*/
public function addPost(){
if ($this->request->param()){
$arr=input('param.');
$arr['create_time']=time();
if($arr['is_sta']==1){
$num=Db::name('zj_news')->where(['is_sta'=>1,'delete_time'=>0])->count();
if ($num>=1){
$this->error('最多同时发布一条系统消息');
}
}
$add=Db::name('zj_news')->insert($arr);
if ($add){
$this->success('添加成功',url('index'));
}else{
$this->error('添加失败');
}
}
}
/**
* 编辑系统消息
*/
public function edit(){
if ($this->request->param()){
$id=input('param.id');
$one=Db::name('zj_news')->where('id',$id)->find();
$this->assign('one',$one);
return $this->fetch();
}
}
/**
* 编辑系统消息提交
*/
public function editPost(){
if ($this->request->param()){
$arr=input('param.');
if($arr['is_sta']==1){
$num=Db::name('zj_news')->where(['is_sta'=>1,'delete_time'=>0])->count();
if ($num>=1){
$this->error('最多同时发布一条系统消息');
}
}
$edit=Db::name('zj_news')->update($arr);
if ($edit){
$this->success('保存成功',url('index'));
}else{
$this->error('保存失败');
}
}
}
/**
* 系统消息发布状态
*/
public function sta(){
if ($this->request->param()){
$arr=input('param.');
if($arr['is_sta']==1){
$num=Db::name('zj_news')->where(['is_sta'=>1,'delete_time'=>0])->count();
if ($num>=1){
$this->error('最多同时发布一条系统消息');
}
}
$edit=Db::name('zj_news')->update($arr);
if ($edit){
$this->success('设置成功');
}else{
$this->edit('设置失败');
}
}
}
/**
* 系统消息删除
*/
public function delete(){
if ($this->request->param()){
$id=input('param.id');
$del=Db::name('zj_news')->update(['id'=>$id,'delete_time'=>time()]);
if ($del){
$this->success('删除成功');
}else{
$this->edit('删除失败');
}
}
}
}