PolicyController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Http\Controllers\Mobile\Content;
  3. use App\Http\Controllers\Mobile\MobileBaseController;
  4. use App\Models\Policy;
  5. use App\Models\PolicyCategory;
  6. use App\Services\Content\ArticleService;
  7. use App\Services\Content\ArticleCategoryService;
  8. use App\Services\Content\AdService;
  9. use App\Services\Content\NavigationService;
  10. use App\Services\Content\PolicyService;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\Cache;
  13. use Illuminate\Support\Collection;
  14. class PolicyController extends MobileBaseController
  15. {
  16. protected $articleService;
  17. protected $articleCategoryService;
  18. protected $adService;
  19. protected $navigationService;
  20. protected $policycategoryService;
  21. /**
  22. * ArticleController constructor.
  23. * @param $articleService
  24. * @param $articleCategoryService
  25. */
  26. public function __construct(ArticleService $articleService, ArticleCategoryService $articleCategoryService, AdService $adService, NavigationService $navigationService,PolicyService $policycategoryService)
  27. {
  28. $this->articleService = $articleService;
  29. $this->articleCategoryService = $articleCategoryService;
  30. $this->adService = $adService;
  31. $this->navigationService = $navigationService;
  32. $this->policycategoryService = $policycategoryService;
  33. }
  34. public function index(Request $request, $id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  35. {
  36. return redirect(route('mobile.policy.list',['id'=>72]));
  37. $size = 5;
  38. $key = $request->input('key');
  39. $rst = $this->policycategoryService->policy_list($key, $id, '10');
  40. $categorys_root = $this->policycategoryService->getChildCategorys(0);//一级分类
  41. $categorys = $this->policycategoryService->getChildCategorys(1);//一级分类
  42. if ($request->ajax()) {
  43. if ($rst->lastPage() < $rst->currentPage()) {
  44. return response()->json(['status'=>0]);
  45. }
  46. return response()->json(['status'=>1,'data'=>view('mobile.app.content.policy.ajax_policy_list', ['articles'=>$rst])->render()]);
  47. }
  48. $mobile_dropload = false;
  49. if ($rst->total() > $size) {
  50. $mobile_dropload = true;
  51. }
  52. $return_data = array(
  53. 'articles' => $rst,
  54. 'categorys' => $categorys,
  55. 'categorys_root' => $categorys_root,
  56. 'type_id' => 9,
  57. 'roottype_id' => 1,
  58. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  59. 'wap_title' => '人才政策',
  60. 'mobile_dropload' => $mobile_dropload
  61. );
  62. return view('mobile.app.content.policy.index', $return_data);
  63. }
  64. public function list(Request $request, $id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  65. {
  66. $size = 5;
  67. $key = $request->input('key')?$request->input('key'):'';
  68. $category=PolicyCategory::where(array('id'=>$id))->first();
  69. $lists = $this->policycategoryService->policy_list($key, $id, '10');
  70. $categorys_root = $this->policycategoryService->getChildCategorys(0);//一级分类
  71. $search_id=$category->parent_id!=0?$category->parent_id:$id;
  72. $categorys = $this->policycategoryService->getChildCategorys($search_id);
  73. $mobile_dropload = false;
  74. if ($lists->total() > $size) {
  75. $mobile_dropload = true;
  76. }
  77. $now_cate = '';
  78. $article_cate = array();
  79. foreach ($categorys as $k => $v) {
  80. if ($v->id == $id) {
  81. $now_cate = $v->categoryname;
  82. $article_cate = $v;
  83. }
  84. }
  85. $this->putSeoData('article_cate', $article_cate);
  86. $return_data = array(
  87. 'articles'=>$lists,
  88. 'categorys'=>$categorys,
  89. 'categorys_root'=>$categorys_root,
  90. 'key'=>$key,
  91. 'type_id'=>$id,
  92. 'roottype_id' => $search_id,
  93. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  94. 'mobile_dropload' => $mobile_dropload,
  95. 'wap_title' => '人才政策',
  96. //'top_nav'=>$topNav,
  97. 'now_cate'=>$now_cate
  98. );
  99. if ($request->ajax()) {
  100. if ($lists->lastPage() < $lists->currentPage()) {
  101. return response()->json(['status'=>0]);
  102. }
  103. return response()->json(['status'=>1,'data'=>view('mobile.app.content.policy.ajax_policy_list', ['articles'=>$lists])->render()]);
  104. }
  105. return view('mobile.app.content.policy.index', $return_data);
  106. }
  107. public function show($id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  108. {
  109. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  110. $article_info =Policy::where(array('id'=>$id))->first();
  111. if (!$article_info) {
  112. $back_url = \Illuminate\Support\Facades\URL::previous();
  113. return $this->showMessage('资讯不存在', $back_url, true, '上一页', '3');
  114. }
  115. $this->putSeoData('article', $article_info);
  116. $return_data = array(
  117. 'categorys' => $categorys,
  118. 'type_id' => $id,
  119. 'info' => $article_info,
  120. 'wap_title' => $article_info->title,
  121. 'parent_id' => $parent_id
  122. );
  123. return view('mobile.app.content.policy.show', $return_data);
  124. }
  125. public function click($id)
  126. {
  127. $rst = $this->policycategoryService->incrementData(array('id'=>$id), 1, 'click');
  128. $data = array('status'=>0);
  129. if ($rst) {
  130. $data = array('status'=>1);
  131. }
  132. return response()->json($data);
  133. }
  134. }