RecycleBinController.php
4.4 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 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 app\admin\model\RecycleBinModel;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class RecycleBinController extends AdminBaseController
{
/**
* 回收站
* @adminMenu(
* 'name' => '回收站',
* 'parent' => '',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站',
* 'param' => ''
* )
*/
public function index()
{
$content = hook_one('admin_recycle_bin_index_view');
if (!empty($content)) {
return $content;
}
$recycleBinModel = new RecycleBinModel();
$list = $recycleBinModel->order('create_time desc')->paginate(10);
// 获取分页显示
$page = $list->render();
$this->assign('page', $page);
$this->assign('list', $list);
return $this->fetch();
}
/**
* 回收站还原
* @adminMenu(
* 'name' => '回收站还原',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站还原',
* 'param' => ''
* )
*/
public function restore()
{
$id = $this->request->param('id', 0, 'intval');
$result = Db::name('recycleBin')->where('id', $id)->find();
$tableName = explode('#', $result['table_name']);
$tableName = $tableName[0];
//还原资源
if ($result) {
$res = Db::name($tableName)
->where('id', $result['object_id'])
->update(['delete_time' => '0']);
if ($tableName == 'portal_post') {
Db::name('portal_category_post')->where('post_id', $result['object_id'])->update(['status' => 1]);
Db::name('portal_tag_post')->where('post_id', $result['object_id'])->update(['status' => 1]);
}
if ($res) {
$re = Db::name('recycleBin')->where('id', $id)->delete();
if ($re) {
$this->success("还原成功!");
}
}
}
}
/**
* 回收站彻底删除
* @adminMenu(
* 'name' => '回收站彻底删除',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站彻底删除',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id');
$result = Db::name('recycleBin')->where('id', $id)->find();
//删除资源
if ($result) {
//页面没有单独的表.
if ($result['table_name'] === 'portal_post#page') {
$re = Db::name('portal_post')->where('id', $result['object_id'])->delete();
//消除路由
$routeModel = new RouteModel();
$routeModel->setRoute('', 'portal/Page/index', ['id' => $result['object_id']], 2, 5000);
$routeModel->getRoutes(true);
} else {
$re = Db::name($result['table_name'])->where('id', $result['object_id'])->delete();
}
if ($re) {
$res = Db::name('recycleBin')->where('id', $id)->delete();
if ($result['table_name'] === 'portal_post') {
Db::name('portal_category_post')->where('post_id', $result['object_id'])->delete();
Db::name('portal_tag_post')->where('post_id', $result['object_id'])->delete();
}
if ($res) {
$this->success("删除成功!");
}
}
}
}
}