Article.php 2.6 KB

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