ArticleController.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. namespace App\Http\Controllers\Web\Content;
  3. use App\Http\Controllers\Web\WebBaseController;
  4. use App\Services\Content\ArticleService;
  5. use App\Services\Content\ArticleCategoryService;
  6. use App\Services\Content\AdService;
  7. use App\Services\Content\NavigationService;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Cache;
  10. use Illuminate\Support\Collection;
  11. class ArticleController extends WebBaseController
  12. {
  13. protected $articleService;
  14. protected $articleCategoryService;
  15. protected $adService;
  16. protected $navigationService;
  17. /**
  18. * ArticleController constructor.
  19. * @param $articleService
  20. * @param $articleCategoryService
  21. */
  22. public function __construct(ArticleService $articleService, ArticleCategoryService $articleCategoryService, AdService $adService, NavigationService $navigationService)
  23. {
  24. $this->articleService = $articleService;
  25. $this->articleCategoryService = $articleCategoryService;
  26. $this->adService = $adService;
  27. $this->navigationService = $navigationService;
  28. }
  29. public function index(Request $request, $id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  30. {
  31. $key = $request->input('key');
  32. $categorys = $this->articleCategoryService->getChildCategorys($id, $num);
  33. $search_id = '';
  34. if ($categorys) {
  35. $search_id = $categorys[0]->id;
  36. $search_where = array();
  37. $search_where['id'] = $search_id;
  38. if ($id != '1') {
  39. $search_where['parent_id'] = $id;
  40. }
  41. if ($num != '8') {
  42. $search_where['num'] = $num;
  43. }
  44. if ($focus != '3') {
  45. $search_where['focus'] = $focus;
  46. }
  47. if ($recommend != '4') {
  48. $search_where['recommend'] = $recommend;
  49. }
  50. if ($other_num != '5') {
  51. $search_where['other_num'] = $other_num;
  52. }
  53. return redirect()->route('news.list', $search_where);
  54. } else {
  55. $rst = $this->articleService->list($key, '', 10);
  56. }
  57. $focus_articles = $this->articleService->getPropertyArticles($focus, $other_num); //热门资讯
  58. $recommend_articles = $this->articleService->getPropertyArticles($recommend, $other_num); //推荐资讯
  59. //顶部广告位
  60. $ad_data = array(
  61. 'theme' => 'default',
  62. 'org' => 'Home',
  63. 'alias' => 'AIX_news_index_top',
  64. 'num' => '1'
  65. );
  66. $top_ads = $this->adService->getAds($ad_data);
  67. $return_data = array(
  68. 'articles' => $rst,
  69. 'categorys' => $categorys,
  70. 'focus_articles' => $focus_articles,
  71. 'recommend_articles' => $recommend_articles,
  72. 'key' => $key,
  73. 'top_ads' => $top_ads
  74. );
  75. return view('app.content.article.index', $return_data);
  76. }
  77. public function list(Request $request, $id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  78. {
  79. $key = $request->input('key');
  80. $lists = $this->articleService->list($key, $id, '10');
  81. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  82. $focus_articles = $this->articleService->getPropertyArticles($focus, $other_num); //热门资讯
  83. $recommend_articles = $this->articleService->getPropertyArticles($recommend, $other_num); //推荐资讯
  84. //获取后台职场资讯名称
  85. $where = array(
  86. 'alias'=>'AIX_top',
  87. 'pagealias' => 'AIX_news',
  88. 'display'=>'1'
  89. );
  90. $topNav = $this->navigationService->getTopNav($where);
  91. $now_cate = '';
  92. $article_cate = array();
  93. foreach ($categorys as $k => $v) {
  94. if ($v->id == $id) {
  95. $now_cate = $v->category_name;
  96. $article_cate = $v;
  97. }
  98. }
  99. $this->putSeoData('article_cate', $article_cate);
  100. $return_data = array(
  101. 'articles'=>$lists,
  102. 'categorys'=>$categorys,
  103. 'focus_articles'=>$focus_articles,
  104. 'recommend_articles'=>$recommend_articles,
  105. 'key'=>$key,
  106. 'type_id'=>$id,
  107. 'top_nav'=>$topNav,
  108. 'now_cate'=>$now_cate
  109. );
  110. return view('app.content.article.list', $return_data);
  111. }
  112. public function show($id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  113. {
  114. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  115. $focus_articles = $this->articleService->getPropertyArticles($focus, $other_num); //热门资讯
  116. $recommend_articles = $this->articleService->getPropertyArticles($recommend, $other_num); //推荐资讯
  117. $article_info = $this->articleService->getArticleInfo($id);
  118. if (!$article_info) {
  119. $back_url = \Illuminate\Support\Facades\URL::previous();
  120. return $this->showMessage('资讯不存在', $back_url, true, '上一页', '3');
  121. }
  122. $this->putSeoData('article', $article_info);
  123. $return_data = array(
  124. 'categorys'=>$categorys,
  125. 'focus_articles'=>$focus_articles,
  126. 'recommend_articles'=>$recommend_articles,
  127. 'type_id'=>$id,
  128. 'info'=>$article_info,
  129. 'parent_id'=>$parent_id
  130. );
  131. return view('app.content.article.show', $return_data);
  132. }
  133. public function click($id)
  134. {
  135. $rst = $this->articleService->incrementData(array('id'=>$id), 1, 'click');
  136. $data = array('status'=>0);
  137. if ($rst) {
  138. $data = array('status'=>1);
  139. }
  140. return response()->json($data);
  141. }
  142. }