ArticleController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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,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. return app('json')->successful($list);
  29. }
  30. /**
  31. * 文章详情
  32. * @param $id
  33. * @return mixed
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. * @throws \think\exception\DbException
  37. */
  38. public function details($id)
  39. {
  40. $content = Article::getArticleOne($id);
  41. if(!$content) return app('json')->fail('此文章已经不存在!');
  42. $content["visit"] = $content["visit"] + 1;
  43. $content["cart_name"] = ArticleCategory::getArticleCategoryField($content['cid']);
  44. $content['add_time'] = date('m月d日',$content['add_time']);
  45. Article::edit(['visit'=>$content["visit"]],$id);//增加浏览次数
  46. return app('json')->successful($content);
  47. }
  48. /**
  49. * 文章 热门
  50. * @return mixed
  51. */
  52. public function hot()
  53. {
  54. $list = Article::getArticleListHot("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  55. if(is_object($list)) $list = $list->toArray();
  56. return app('json')->successful($list);
  57. }
  58. /**
  59. * 文章 banner
  60. * @return mixed
  61. */
  62. public function banner()
  63. {
  64. $list = Article::getArticleListBanner("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  65. if(is_object($list)) $list = $list->toArray();
  66. return app('json')->successful($list);
  67. }
  68. }