ArticleController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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,$mer_id) = UtilService::getMore([
  23. ['page',1],
  24. ['limit',10],
  25. ['mer_id',0]
  26. ],$request, true);
  27. $list = Article::cidByArticleList($cid,$page,$limit,$mer_id,"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. }