File.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller;
  16. use think\admin\Controller;
  17. use think\admin\helper\QueryHelper;
  18. use think\admin\model\SystemFile;
  19. use think\admin\service\AdminService;
  20. use think\admin\Storage;
  21. /**
  22. * 系统文件管理
  23. * Class File
  24. * @package app\admin\controller
  25. */
  26. class File extends Controller
  27. {
  28. /**
  29. * 系统文件管理
  30. * @auth true
  31. * @menu true
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\DbException
  34. * @throws \think\db\exception\ModelNotFoundException
  35. */
  36. public function index()
  37. {
  38. $this->types = Storage::types();
  39. SystemFile::mQuery()->layTable(function () {
  40. $this->title = '系统文件管理';
  41. $this->xexts = SystemFile::mk()->distinct()->column('xext');
  42. }, function (QueryHelper $query) {
  43. $query->like('name,hash,xext')->equal('type')->dateBetween('create_at');
  44. $query->where(['issafe' => 0, 'status' => 2, 'uuid' => AdminService::getUserId()]);
  45. });
  46. }
  47. /**
  48. * 数据列表处理
  49. * @param array $data
  50. * @return void
  51. */
  52. protected function _page_filter(array &$data)
  53. {
  54. foreach ($data as &$vo) {
  55. $vo['ctype'] = $this->types[$vo['type']] ?? $vo['type'];
  56. }
  57. }
  58. /**
  59. * 删除系统文件
  60. * @auth true
  61. * @return void
  62. */
  63. public function remove()
  64. {
  65. SystemFile::mDelete();
  66. }
  67. /**
  68. * 清理重复文件
  69. * @auth true
  70. * @return void
  71. */
  72. public function distinct()
  73. {
  74. $map = ['uuid' => AdminService::getUserId()];
  75. $db1 = SystemFile::mk()->fieldRaw('max(id) id')->where($map)->group('type,xkey');
  76. $db2 = $this->app->db->table($db1->buildSql())->alias('dt')->field('id');
  77. SystemFile::mk()->whereRaw("id not in {$db2->buildSql()}")->delete();
  78. SystemFile::mk()->where($map)->where(['status' => 1])->delete();
  79. $this->success('清理重复文件成功!');
  80. }
  81. }