PolicyController.php 6.6 KB

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