AdminAssetController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\user\controller;
  12. use think\Db;
  13. use cmf\controller\AdminBaseController;
  14. class AdminAssetController extends AdminBaseController
  15. {
  16. /**
  17. * 资源管理列表
  18. * @adminMenu(
  19. * 'name' => '资源管理',
  20. * 'parent' => '',
  21. * 'display'=> false,
  22. * 'hasView'=> true,
  23. * 'order' => 10000,
  24. * 'icon' => 'file',
  25. * 'remark' => '资源管理列表',
  26. * 'param' => ''
  27. * )
  28. */
  29. public function index()
  30. {
  31. $content = hook_one('user_admin_asset_index_view');
  32. if (!empty($content)) {
  33. return $content;
  34. }
  35. $join = [
  36. ['__USER__ u', 'a.user_id = u.id']
  37. ];
  38. $result = Db::name('asset')->field('a.*,u.user_login,u.user_email,u.user_nicename')
  39. ->alias('a')->join($join)
  40. ->order('create_time', 'DESC')
  41. ->paginate(10);
  42. $this->assign('assets', $result->items());
  43. $this->assign('page', $result->render());
  44. return $this->fetch();
  45. }
  46. /**
  47. * 删除文件
  48. * @adminMenu(
  49. * 'name' => '删除文件',
  50. * 'parent' => 'index',
  51. * 'display'=> false,
  52. * 'hasView'=> false,
  53. * 'order' => 10000,
  54. * 'icon' => '',
  55. * 'remark' => '删除文件',
  56. * 'param' => ''
  57. * )
  58. */
  59. public function delete()
  60. {
  61. $id = $this->request->param('id');
  62. $file_filePath = Db::name('asset')->where('id', $id)->value('file_path');
  63. $file = 'upload/' . $file_filePath;
  64. $res = true;
  65. if (file_exists($file)) {
  66. $res = unlink($file);
  67. }
  68. if ($res) {
  69. Db::name('asset')->where('id', $id)->delete();
  70. $this->success('删除成功');
  71. } else {
  72. $this->error('删除失败');
  73. }
  74. }
  75. }