Files.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\store\controller\content;
  10. use app\store\controller\Controller;
  11. use app\store\model\UploadFile as UploadFileModel;
  12. /**
  13. * 文件库管理
  14. * Class Files
  15. * @package app\store\controller
  16. */
  17. class Files extends Controller
  18. {
  19. /**
  20. * 文件列表
  21. * @return mixed
  22. * @throws \think\exception\DbException
  23. */
  24. public function index()
  25. {
  26. $model = new UploadFileModel;
  27. $list = $model->getList(-1, '', 0);
  28. return $this->fetch('index', compact('list'));
  29. }
  30. /**
  31. * 回收站列表
  32. * @return mixed
  33. * @throws \think\exception\DbException
  34. */
  35. public function recycle()
  36. {
  37. $model = new UploadFileModel;
  38. $list = $model->getList(-1, '', 1);
  39. return $this->fetch('recycle', compact('list'));
  40. }
  41. /**
  42. * 移入回收站
  43. * @param $file_id
  44. * @return array
  45. * @throws \think\exception\DbException
  46. */
  47. public function recovery($file_id)
  48. {
  49. // 文章详情
  50. $model = UploadFileModel::detail($file_id);
  51. if (!$model->setRecycle(true)) {
  52. return $this->renderError($model->getError() ?: '操作失败');
  53. }
  54. return $this->renderSuccess('操作成功');
  55. }
  56. /**
  57. * 移出回收站
  58. * @param $file_id
  59. * @return array
  60. * @throws \think\exception\DbException
  61. */
  62. public function restore($file_id)
  63. {
  64. // 商品详情
  65. $model = UploadFileModel::detail($file_id);
  66. if (!$model->setRecycle(false)) {
  67. return $this->renderError('操作失败');
  68. }
  69. return $this->renderSuccess('操作成功');
  70. }
  71. /**
  72. * 删除文件
  73. * @param $file_id
  74. * @return array|bool
  75. * @throws \think\Exception
  76. * @throws \think\exception\DbException
  77. */
  78. public function delete($file_id)
  79. {
  80. // 商品详情
  81. $model = UploadFileModel::detail($file_id);
  82. if (!$model->setDelete()) {
  83. return $this->renderError($model->getError() ?: '操作失败');
  84. }
  85. return $this->renderSuccess('操作成功');
  86. }
  87. }