ArticleController.php 2.3 KB

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