Group.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\files;
  10. use app\store\controller\Controller;
  11. use app\store\model\UploadGroup as GroupModel;
  12. /**
  13. * 文件分组
  14. * Class Group
  15. * @package app\store\controller\content
  16. */
  17. class Group extends Controller
  18. {
  19. /**
  20. * 文件分组列表
  21. * @return mixed
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. */
  26. public function index()
  27. {
  28. $model = new GroupModel;
  29. $list = $model->getList();
  30. return $this->fetch('index', compact('list'));
  31. }
  32. /**
  33. * 添加文件分组
  34. * @return array|mixed
  35. */
  36. public function add()
  37. {
  38. $model = new GroupModel;
  39. if (!$this->request->isAjax()) {
  40. return $this->fetch('add');
  41. }
  42. // 新增记录
  43. if ($model->add($this->postData('group'))) {
  44. return $this->renderSuccess('添加成功', url('content.files.group/index'));
  45. }
  46. return $this->renderError($model->getError() ?: '添加失败');
  47. }
  48. /**
  49. * 编辑文件分组
  50. * @param $group_id
  51. * @return array|mixed
  52. * @throws \think\exception\DbException
  53. */
  54. public function edit($group_id)
  55. {
  56. // 分组详情
  57. $model = GroupModel::detail($group_id);
  58. if (!$this->request->isAjax()) {
  59. return $this->fetch('edit', compact('model'));
  60. }
  61. // 更新记录
  62. if ($model->edit($this->postData('group'))) {
  63. return $this->renderSuccess('更新成功', url('content.files.group/index'));
  64. }
  65. return $this->renderError($model->getError() ?: '更新失败');
  66. }
  67. /**
  68. * 删除文件分组
  69. * @param $group_id
  70. * @return array
  71. * @throws \think\exception\DbException
  72. */
  73. public function delete($group_id)
  74. {
  75. $model = GroupModel::detail($group_id);
  76. if (!$model->remove()) {
  77. return $this->renderError($model->getError() ?: '删除失败');
  78. }
  79. return $this->renderSuccess('删除成功');
  80. }
  81. }