Group.php 2.1 KB

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