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,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. if ($content['video_link']==''){
  46. $content['id_video']=0;
  47. }else{
  48. $content['id_video']=1;
  49. }
  50. Article::edit(['visit'=>$content["visit"]],$id);//增加浏览次数
  51. return app('json')->successful($content);
  52. }
  53. /**
  54. * 文章 热门
  55. * @return mixed
  56. */
  57. public function hot()
  58. {
  59. $list = Article::getArticleListHot("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  60. if(is_object($list)) $list = $list->toArray();
  61. return app('json')->successful($list);
  62. }
  63. /**
  64. * 文章 banner
  65. * @return mixed
  66. */
  67. public function banner()
  68. {
  69. $list = Article::getArticleListBanner("id,title,image_input,visit,from_unixtime(add_time,'%Y-%m-%d %H:%i') as add_time,synopsis,url") ?? [];
  70. if(is_object($list)) $list = $list->toArray();
  71. return app('json')->successful($list);
  72. }
  73. }