ArticleController.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1\publics;
  12. use app\Request;
  13. use app\services\article\ArticleServices;
  14. /**
  15. * 文章类
  16. * Class ArticleController
  17. * @package app\controller\api\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 Request $request
  29. * @param $cid
  30. * @return mixed
  31. */
  32. public function lst($cid)
  33. {
  34. [$page, $limit] = $this->services->getPageValue();
  35. $list = $this->services->cidByArticleList(['cid' => $cid], $page, $limit, "id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url");
  36. return app('json')->successful($list);
  37. }
  38. /**
  39. * 文章详情
  40. * @param $id
  41. * @return mixed
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. */
  46. public function details($id)
  47. {
  48. $info = $this->services->getInfo($id);
  49. return app('json')->successful($info);
  50. }
  51. /**
  52. * 获取热门文章
  53. * @return mixed
  54. * @throws \think\db\exception\DataNotFoundException
  55. * @throws \think\db\exception\DbException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. */
  58. public function hot()
  59. {
  60. [$page, $limit] = $this->services->getPageValue();
  61. $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");
  62. return app('json')->successful($list);
  63. }
  64. /**
  65. * 获取最新文章
  66. * @return mixed
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public function new()
  72. {
  73. [$page, $limit] = $this->services->getPageValue();
  74. $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");
  75. return app('json')->successful($list);
  76. }
  77. /**
  78. * 获取顶部banner文章
  79. * @return mixed
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. public function banner()
  85. {
  86. [$page, $limit] = $this->services->getPageValue();
  87. $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");
  88. return app('json')->successful($list);
  89. }
  90. }