IndexController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: pl125 <xskjs888@163.com>
  8. // +----------------------------------------------------------------------
  9. namespace api\portal\controller;
  10. use api\portal\model\PortalPostModel;
  11. use cmf\controller\RestBaseController;
  12. use api\portal\model\PortalTagModel;
  13. class IndexController extends RestBaseController
  14. {
  15. protected $tagModel;
  16. /**
  17. * 获取标签列表
  18. */
  19. public function index()
  20. {
  21. $this->success('请求成功!', "DD");
  22. }
  23. /**
  24. * 获取热门标签列表
  25. */
  26. public function hotTags()
  27. {
  28. $params = $this->request->get();
  29. $params['where']['recommended'] = 1;
  30. $data = $this->tagModel->getDatas($params);
  31. if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
  32. $response = $data;
  33. } else {
  34. $response = ['list' => $data,];
  35. }
  36. $this->success('请求成功!', $response);
  37. }
  38. /**
  39. * 获取标签文章列表
  40. * @param int $id
  41. */
  42. public function articles($id)
  43. {
  44. if (intval($id) === 0) {
  45. $this->error('无效的标签id!');
  46. } else {
  47. $params = $this->request->param();
  48. $postModel = new PortalPostModel();
  49. unset($params['id']);
  50. $articles = $postModel->paramsFilter($params)->alias('post')
  51. ->join('__PORTAL_TAG_POST__ tag_post', 'post.id = tag_post.post_id')
  52. ->where(['tag_post.tag_id' => $id])->select();
  53. if (!empty($params['relation'])) {
  54. $allowedRelations = $postModel->allowedRelations($params['relation']);
  55. if (!empty($allowedRelations)) {
  56. if (count($articles) > 0) {
  57. $articles->load($allowedRelations);
  58. $articles->append($allowedRelations);
  59. }
  60. }
  61. }
  62. $this->success('请求成功!', ['articles' => $articles]);
  63. }
  64. }
  65. }