ArticleController.php 6.8 KB

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