Group.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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\files;
  13. use think\response\Json;
  14. use app\store\controller\Controller;
  15. use app\store\model\UploadGroup as GroupModel;
  16. /**
  17. * 文件分组
  18. * Class Group
  19. * @package app\store\controller\content
  20. */
  21. class Group extends Controller
  22. {
  23. /**
  24. * 文件分组列表
  25. * @return Json
  26. * @throws \think\db\exception\DataNotFoundException
  27. * @throws \think\db\exception\DbException
  28. * @throws \think\db\exception\ModelNotFoundException
  29. */
  30. public function list(): Json
  31. {
  32. $model = new GroupModel;
  33. $list = $model->getList();
  34. return $this->renderSuccess(compact('list'));
  35. }
  36. /**
  37. * 添加文件分组
  38. * @return Json
  39. */
  40. public function add(): Json
  41. {
  42. // 新增记录
  43. $model = new GroupModel;
  44. if ($model->add($this->postForm())) {
  45. return $this->renderSuccess('添加成功');
  46. }
  47. return $this->renderError($model->getError() ?: '添加失败');
  48. }
  49. /**
  50. * 编辑文件分组
  51. * @param int $groupId
  52. * @return Json
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function edit(int $groupId): Json
  58. {
  59. // 分组详情
  60. $model = GroupModel::detail($groupId);
  61. // 更新记录
  62. if ($model->edit($this->postForm())) {
  63. return $this->renderSuccess('更新成功');
  64. }
  65. return $this->renderError($model->getError() ?: '更新失败');
  66. }
  67. /**
  68. * 删除文件分组
  69. * @param int $groupId
  70. * @return Json
  71. */
  72. public function delete(int $groupId): Json
  73. {
  74. $model = GroupModel::detail($groupId);
  75. if (!$model->remove()) {
  76. return $this->renderError($model->getError() ?: '删除失败');
  77. }
  78. return $this->renderSuccess('删除成功');
  79. }
  80. }