123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-04-30
- // +—————————————————————————————————————————————————————————————————————
- 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()
- {
- $content = hook_one('user_admin_asset_index_view');
- if (!empty($content)) {
- return $content;
- }
- $join = [
- ['__USER__ u', 'a.user_id = u.id']
- ];
- $result = Db::name('asset')->field('a.*,u.user_login,u.user_email,u.user_nicename')
- ->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('删除失败');
- }
- }
- }
|