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 app\store\model\UploadFile as UploadFileModel;
  14. /**
  15. * 文件库管理
  16. * Class Files
  17. * @package app\store\controller
  18. */
  19. class Files extends Controller
  20. {
  21. /**
  22. * 文件列表
  23. * @return array
  24. * @throws \think\db\exception\DbException
  25. */
  26. public function list()
  27. {
  28. $model = new UploadFileModel;
  29. $list = $model->getList($this->request->param());
  30. return $this->renderSuccess(compact('list'));
  31. }
  32. /**
  33. * 编辑文件
  34. * @param int $fileId
  35. * @return array
  36. */
  37. public function edit(int $fileId)
  38. {
  39. // 文件详情
  40. $model = UploadFileModel::detail($fileId);
  41. // 更新记录
  42. if ($model->edit($this->postForm())) {
  43. return $this->renderSuccess('更新成功');
  44. }
  45. return $this->renderError($model->getError() ?: '更新失败');
  46. }
  47. /**
  48. * 删除文件(批量)
  49. * @param array $fileIds 文件id集
  50. * @return array
  51. * @throws \think\Exception
  52. * @throws \think\db\exception\DataNotFoundException
  53. * @throws \think\db\exception\DbException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. */
  56. public function delete(array $fileIds)
  57. {
  58. $model = new UploadFileModel;
  59. if (!$model->setDelete($fileIds)) {
  60. return $this->renderError($model->getError() ?: '操作失败');
  61. }
  62. return $this->renderSuccess('操作成功');
  63. }
  64. /**
  65. * 移动文件到指定分组(批量)
  66. * @param int $groupId
  67. * @param array $fileIds
  68. * @return array
  69. */
  70. public function moveGroup(int $groupId, array $fileIds)
  71. {
  72. $model = new UploadFileModel;
  73. if (!$model->moveGroup($groupId, $fileIds)) {
  74. return $this->renderError($model->getError() ?: '操作失败');
  75. }
  76. return $this->renderSuccess('操作成功');
  77. }
  78. }