ArticleController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\api\controller\publics;
  3. use app\models\article\Article;
  4. use app\models\article\ArticleCategory;
  5. use app\Request;
  6. use crmeb\services\UtilService;
  7. /**
  8. * 文章类
  9. * Class ArticleController
  10. * @package app\api\controller\publics
  11. */
  12. class ArticleController
  13. {
  14. /**
  15. * 文章列表
  16. * @param Request $request
  17. * @param $cid
  18. * @return mixed
  19. */
  20. public function lst(Request $request, $cid)
  21. {
  22. list($page, $limit) = UtilService::getMore([
  23. ['page', 1],
  24. ['limit', 10],
  25. ], $request, true);
  26. $list = Article::cidByArticleList($cid, $page, $limit, "id,title,share_images,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  27. if (is_object($list)) $list = $list->toArray();
  28. foreach ($list as &$v) {
  29. $v['share_images'] = explode(',', $v['share_images']);
  30. }
  31. return app('json')->successful($list);
  32. }
  33. /**
  34. * 文章详情
  35. * @param $id
  36. * @return mixed
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @throws \think\exception\DbException
  40. */
  41. public function details($id)
  42. {
  43. $content = Article::getArticleOne($id);
  44. if (!$content) return app('json')->fail('此文章已经不存在!');
  45. $content["visit"] = $content["visit"] + 1;
  46. $content["cart_name"] = ArticleCategory::getArticleCategoryField($content['cid']);
  47. $content['add_time'] = date('m月d日', $content['add_time']);
  48. Article::edit(['visit' => $content["visit"]], $id);//增加浏览次数
  49. return app('json')->successful($content);
  50. }
  51. /**
  52. * 文章 热门
  53. * @return mixed
  54. */
  55. public function hot()
  56. {
  57. $list = Article::getArticleListHot("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  58. if (is_object($list)) $list = $list->toArray();
  59. return app('json')->successful($list);
  60. }
  61. /**
  62. * 文章 banner
  63. * @return mixed
  64. */
  65. public function banner()
  66. {
  67. $list = Article::getArticleListBanner("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  68. if (is_object($list)) $list = $list->toArray();
  69. return app('json')->successful($list);
  70. }
  71. }