ArticleController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace App\Http\Controllers\Mobile\Content;
  3. use App\Http\Controllers\Mobile\MobileBaseController;
  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 MobileBaseController
  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 = '59', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  30. {
  31. $size = 5;
  32. $key = $request->input('key');
  33. $rst = $this->articleService->list($key, $id, $size);
  34. $categorys = $this->articleCategoryService->getChildCategorys($id, $num);
  35. if ($request->ajax()) {
  36. if ($rst->lastPage() < $rst->currentPage()) {
  37. return response()->json(['status' => 0]);
  38. }
  39. return response()->json(['status' => 1, 'data' => view('mobile.app.content.article.ajax_article_list', ['articles' => $rst])->render()]);
  40. }
  41. $mobile_dropload = false;
  42. if ($rst->total() > $size) {
  43. $mobile_dropload = true;
  44. }
  45. $return_data = [
  46. 'articles' => $rst,
  47. 'categorys' => $categorys,
  48. 'type_id' => '',
  49. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  50. 'wap_title' => '职场资讯',
  51. 'mobile_dropload' => $mobile_dropload,
  52. 'key' => $key,
  53. ];
  54. return view('mobile.app.content.article.index', $return_data);
  55. }
  56. public function list(Request $request, $id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  57. {
  58. $size = 5;
  59. $key = $request->input('key');
  60. $lists = $this->articleService->list($key, $id, $size);
  61. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  62. $mobile_dropload = false;
  63. if ($lists->total() > $size) {
  64. $mobile_dropload = true;
  65. }
  66. $now_cate = '';
  67. $article_cate = [];
  68. foreach ($categorys as $k => $v) {
  69. if ($v->id == $id) {
  70. $now_cate = $v->category_name;
  71. $article_cate = $v;
  72. }
  73. }
  74. $this->putSeoData('article_cate', $article_cate);
  75. $return_data = [
  76. 'articles' => $lists,
  77. 'categorys' => $categorys,
  78. 'key' => $key,
  79. 'type_id' => $id,
  80. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  81. 'mobile_dropload' => $mobile_dropload,
  82. 'wap_title' => '职场资讯',
  83. //'top_nav'=>$topNav,
  84. 'now_cate' => $now_cate,
  85. ];
  86. if ($request->ajax()) {
  87. if ($lists->lastPage() < $lists->currentPage()) {
  88. return response()->json(['status' => 0]);
  89. }
  90. return response()->json(['status' => 1, 'data' => view('mobile.app.content.article.ajax_article_list', ['articles' => $lists])->render()]);
  91. }
  92. return view('mobile.app.content.article.index', $return_data);
  93. }
  94. public function show($id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  95. {
  96. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  97. $article_info = $this->articleService->getArticleInfo($id);
  98. if (!$article_info) {
  99. $back_url = \Illuminate\Support\Facades\URL::previous();
  100. return $this->showMessage('资讯不存在', $back_url, true, '上一页', '3');
  101. }
  102. $this->putSeoData('article', $article_info);
  103. $return_data = [
  104. 'categorys' => $categorys,
  105. 'type_id' => $id,
  106. 'info' => $article_info,
  107. 'wap_title' => $article_info->title,
  108. 'parent_id' => $parent_id,
  109. 'share_title' => $article_info->title,
  110. 'share_desc' => $article_info->seo_description,
  111. 'share_image_url' => $article_info->small_img ? upload_asset($article_info->small_img) : '',
  112. ];
  113. return view('mobile.app.content.article.show', $return_data);
  114. }
  115. public function click($id)
  116. {
  117. $rst = $this->articleService->incrementData(['id' => $id], 1, 'click');
  118. $data = ['status' => 0];
  119. if ($rst) {
  120. $data = ['status' => 1];
  121. }
  122. return response()->json($data);
  123. }
  124. }