Files.php 2.1 KB

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