AdminActiveController.php
4.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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use function Qiniu\thumbnail;
use think\Db;
class AdminActiveController extends AdminBaseController
{
public function index()
{
//接收搜索参数
$param = $this->request->param();
//添加搜索条件
$where=[];
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['name'] = ['like', "%$keyword%"];
}
$category=empty($param['category']) ? '' : $param['category'];
if (!empty($category)) {
$where['category_id'] = $category;
}
$data = Db::name('active')
->where($where)
->order('create_time','desc')
->paginate('15');
$data->appends($param);
$this->assign('page',$data->render());
$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
$this->assign('ca', isset($param['category']) ? $param['category'] : '');
$this->assign('list', $data);
return $this->fetch();
}
public function add()
{
return $this->fetch();
}
public function addPost()
{
$param = $this->request->param();
$param['active_time']=strtotime($param['active_time']);
$param['end_time']=strtotime($param['end_time']);
$param['create_time'] = time();
if (!empty($param['photo_names']) && !empty($param['photo_urls'])) {
$param['more']['photos'] = [];
foreach ($param['photo_urls'] as $key => $url) {
$photoUrl = cmf_asset_relative_url($url);
array_push($param['more']['photos'], ["url" => $photoUrl, "name" => $param['photo_names'][$key]]);
}
unset($param['photo_urls']);
unset($param['photo_names']);
$param['more']=json_encode($param['more']);
}
$re = Db::name('active')->insert($param);
if ($re) {
$this->success('添加成功', 'AdminActive/index');
} else {
$this->error('添加失败', 'AdminActive/index');
}
}
public function edit()
{
$id = $this->request->param('id');
$data = Db::name('active')->where('id', $id)->find();
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$data['more']=json_decode($data['more'],true);
$this->assign('list', $data);
return $this->fetch();
}
public function editPost()
{
$param = $this->request->param();
// print_r($param);
$param['active_time']=strtotime($param['active_time']);
$param['end_time']=strtotime($param['end_time']);
if (!empty($param['photo_names']) && !empty($param['photo_urls'])) {
$param['more']['photos'] = [];
foreach ($param['photo_urls'] as $key => $url) {
$photoUrl = cmf_asset_relative_url($url);
array_push($param['more']['photos'], ["url" => $photoUrl, "name" => $param['photo_names'][$key]]);
}
unset($param['photo_urls']);
unset($param['photo_names']);
$param['more']=json_encode($param['more']);
}
Db::name('active')->where('id', $param['id'])->update($param);
$this->success('编辑成功');
}
public function delete()
{
$id = $this->request->param('id');
Db::name('active')->where('id', $id)->delete();
$this->success('删除成功');
}
public function up(){
$id = $this->request->param('id');
Db::name('active')->where('id', $id)->update(['status'=>1]);
$this->success('上架成功');
}
public function down(){
$id = $this->request->param('id');
Db::name('active')->where('id', $id)->update(['status'=>0]);
$this->success('下架成功');
}
public function top(){
$id = $this->request->param('id');
Db::name('active')->where('id', $id)->update(['is_top'=>1]);
$this->success('置顶成功');
}
public function notTop(){
$id = $this->request->param('id');
Db::name('active')->where('id', $id)->update(['is_top'=>0]);
$this->success('取消置顶成功');
}
}