Article.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\content\Category;
  4. use app\common\model\content\Article as ArticleModel;
  5. /**
  6. * 地址
  7. */
  8. class Article extends Base
  9. {
  10. protected $noNeedLogin = ['getCategoryList', 'getArticleList', 'getArticleInfo'];
  11. /**
  12. * 分类列表
  13. */
  14. public function getCategoryList()
  15. {
  16. $parentId = $this->request->param('parent_id', 0, 'intval');
  17. $page = $this->request->param('page', 1, 'intval');
  18. $pageSize = $this->request->param('page_size', 10, 'intval');
  19. $list = Category::getCategoryList($parentId, $page, $pageSize);
  20. // 处理图像的
  21. $list->each(function ($item) {
  22. $item['image'] = $item['image'] ? cdnurl($item['image']) : '';
  23. });
  24. $this->success('', $list);
  25. }
  26. /**
  27. * 文章列表
  28. */
  29. public function getArticleList()
  30. {
  31. $categoryId = $this->request->param('category_id', 0, 'intval');
  32. $page = $this->request->param('page', 1, 'intval');
  33. $pageSize = $this->request->param('page_size', 10, 'intval');
  34. $list = ArticleModel::getArticleList($categoryId, $page, $pageSize);
  35. $list->each(function ($item) {
  36. // 处理图像的
  37. $item['image'] = $item['image'] ? cdnurl($item['image']) : '';
  38. });
  39. $this->success('获取成功', $list);
  40. }
  41. //文章详情
  42. public function getArticleInfo()
  43. {
  44. $id = $this->request->param('id', 0, 'intval');
  45. // 验证id是否为空
  46. if (empty($id)) {
  47. $this->error('id不能为空');
  48. }
  49. $info = ArticleModel::getArticleInfo($id);
  50. //判断是否为空
  51. if (!empty($info)) {
  52. $info['image'] = $info['image'] ? cdnurl($info['image']) : '';
  53. }
  54. $this->success('获取成功', $info);
  55. }
  56. }