ArticleController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\Request;
  13. use app\services\article\ArticleServices;
  14. /**
  15. * 文章类
  16. * Class ArticleController
  17. * @package app\api\controller\publics
  18. */
  19. class ArticleController
  20. {
  21. protected $services;
  22. public function __construct(ArticleServices $services)
  23. {
  24. $this->services = $services;
  25. }
  26. /**
  27. * 文章列表
  28. * @param $cid
  29. * @return mixed
  30. */
  31. public function lst($cid)
  32. {
  33. if ($cid == 0) {
  34. $where = ['is_hot' => 1];
  35. } else {
  36. $where = ['cid' => $cid];
  37. }
  38. [$page, $limit] = $this->services->getPageValue();
  39. $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");
  40. return app('json')->success($list);
  41. }
  42. /**
  43. * 文章详情
  44. * @param $id
  45. * @return mixed
  46. */
  47. public function details($id)
  48. {
  49. $info = $this->services->getInfo($id);
  50. return app('json')->success($info);
  51. }
  52. /**
  53. * 获取热门文章
  54. * @return mixed
  55. */
  56. public function hot()
  57. {
  58. [$page, $limit] = $this->services->getPageValue();
  59. $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");
  60. return app('json')->success($list);
  61. }
  62. /**
  63. * @return mixed
  64. */
  65. public function new()
  66. {
  67. [$page, $limit] = $this->services->getPageValue();
  68. $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");
  69. return app('json')->success($list);
  70. }
  71. /**
  72. * 获取顶部banner文章
  73. * @return mixed
  74. */
  75. public function banner()
  76. {
  77. [$page, $limit] = $this->services->getPageValue();
  78. $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");
  79. return app('json')->success($list);
  80. }
  81. }