Files.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\model\UploadFile as UploadFileModel;
  15. /**
  16. * 文件库管理
  17. * Class Files
  18. * @package app\store\controller
  19. */
  20. class Files extends Controller
  21. {
  22. /**
  23. * 文件列表
  24. * @return Json
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function list(): Json
  28. {
  29. $model = new UploadFileModel;
  30. $list = $model->getList($this->request->param());
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 编辑文件
  35. * @param int $fileId
  36. * @return Json
  37. */
  38. public function edit(int $fileId): Json
  39. {
  40. // 文件详情
  41. $model = UploadFileModel::detail($fileId);
  42. // 更新记录
  43. if ($model->edit($this->postForm())) {
  44. return $this->renderSuccess('更新成功');
  45. }
  46. return $this->renderError($model->getError() ?: '更新失败');
  47. }
  48. /**
  49. * 删除文件(批量)
  50. * @param array $fileIds 文件id集
  51. * @return Json
  52. * @throws \think\Exception
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function delete(array $fileIds): Json
  58. {
  59. $model = new UploadFileModel;
  60. if (!$model->setDelete($fileIds)) {
  61. return $this->renderError($model->getError() ?: '操作失败');
  62. }
  63. return $this->renderSuccess('操作成功');
  64. }
  65. /**
  66. * 移动文件到指定分组(批量)
  67. * @param int $groupId
  68. * @param array $fileIds
  69. * @return Json
  70. */
  71. public function moveGroup(int $groupId, array $fileIds): Json
  72. {
  73. $model = new UploadFileModel;
  74. if (!$model->moveGroup($groupId, $fileIds)) {
  75. return $this->renderError($model->getError() ?: '操作失败');
  76. }
  77. return $this->renderSuccess('操作成功');
  78. }
  79. }