Category.php 2.5 KB

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