ArticleController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\publics;
  12. use app\services\article\ArticleServices;
  13. /**
  14. * 文章类
  15. * Class ArticleController
  16. * @package app\api\controller\publics
  17. */
  18. class ArticleController
  19. {
  20. protected $services;
  21. public function __construct(ArticleServices $services)
  22. {
  23. $this->services = $services;
  24. }
  25. /**
  26. * 文章列表
  27. * @param $cid
  28. * @return mixed
  29. */
  30. public function lst($cid)
  31. {
  32. if ($cid == 0) {
  33. $where = ['is_hot' => 1];
  34. } else {
  35. $where = ['cid' => $cid];
  36. }
  37. [$page, $limit] = $this->services->getPageValue();
  38. $list = $this->services->cidByArticleList($where, $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
  39. return app('json')->success($list);
  40. }
  41. /**
  42. * 文章详情
  43. * @param $id
  44. * @return mixed
  45. */
  46. public function details($id)
  47. {
  48. $info = $this->services->getInfo($id);
  49. return app('json')->success($info);
  50. }
  51. /**
  52. * 获取热门文章
  53. * @return mixed
  54. */
  55. public function hot()
  56. {
  57. [$page, $limit] = $this->services->getPageValue();
  58. $list = $this->services->cidByArticleList(['is_hot' => 1], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
  59. return app('json')->success($list);
  60. }
  61. /**
  62. * @return mixed
  63. */
  64. public function new()
  65. {
  66. [$page, $limit] = $this->services->getPageValue();
  67. $list = $this->services->cidByArticleList([], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
  68. return app('json')->success($list);
  69. }
  70. /**
  71. * 获取顶部banner文章
  72. * @return mixed
  73. */
  74. public function banner()
  75. {
  76. [$page, $limit] = $this->services->getPageValue();
  77. $list = $this->services->cidByArticleList(['is_banner' => 1], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
  78. return app('json')->success($list);
  79. }
  80. }