ArticleController.php 4.6 KB

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