ArticleController.php 2.5 KB

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