AdminAssetController.php
2.3 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\user\controller;
use think\Db;
use cmf\controller\AdminBaseController;
class AdminAssetController extends AdminBaseController
{
/**
* 资源管理列表
* @adminMenu(
* 'name' => '资源管理',
* 'parent' => '',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => 'file',
* 'remark' => '资源管理列表',
* 'param' => ''
* )
*/
public function index()
{
$join = [
['__USER__ u', 'a.user_id = u.id']
];
$result = Db::name('asset')->field('a.*,u.user_login,u.user_email,u.user_nickname')
->alias('a')->join($join)
->order('create_time', 'DESC')
->paginate(10);
$this->assign('assets', $result->items());
$this->assign('page', $result->render());
return $this->fetch();
}
/**
* 删除文件
* @adminMenu(
* 'name' => '删除文件',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除文件',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id');
$file_filePath = Db::name('asset')->where('id', $id)->value('file_path');
$file = 'upload/' . $file_filePath;
$res = true;
if (file_exists($file)) {
$res = unlink($file);
}
if ($res) {
Db::name('asset')->where('id', $id)->delete();
$this->success('删除成功');
} else {
$this->error('删除失败');
}
}
}