PolicyController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. $size = 5;
  37. $key = $request->input('key');
  38. $rst = $this->policycategoryService->policy_list($key, $id, '10');
  39. $categorys_root = $this->policycategoryService->getChildCategorys(0);//一级分类
  40. $categorys = $this->policycategoryService->getChildCategorys(1);//一级分类
  41. if ($request->ajax()) {
  42. if ($rst->lastPage() < $rst->currentPage()) {
  43. return response()->json(['status'=>0]);
  44. }
  45. return response()->json(['status'=>1,'data'=>view('mobile.app.content.policy.ajax_policy_list', ['articles'=>$rst])->render()]);
  46. }
  47. $mobile_dropload = false;
  48. if ($rst->total() > $size) {
  49. $mobile_dropload = true;
  50. }
  51. $return_data = array(
  52. 'articles' => $rst,
  53. 'categorys' => $categorys,
  54. 'categorys_root' => $categorys_root,
  55. 'type_id' => 9,
  56. 'roottype_id' => 1,
  57. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  58. 'wap_title' => '人才政策',
  59. 'mobile_dropload' => $mobile_dropload
  60. );
  61. return view('mobile.app.content.policy.index', $return_data);
  62. }
  63. public function list(Request $request, $id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  64. {
  65. $size = 5;
  66. $key = $request->input('key')?$request->input('key'):'';
  67. $category=PolicyCategory::where(array('id'=>$id))->first();
  68. $lists = $this->policycategoryService->policy_list($key, $id, '10');
  69. $categorys_root = $this->policycategoryService->getChildCategorys(0);//一级分类
  70. $search_id=$category->parent_id!=0?$category->parent_id:$id;
  71. $categorys = $this->policycategoryService->getChildCategorys($search_id);
  72. $mobile_dropload = false;
  73. if ($lists->total() > $size) {
  74. $mobile_dropload = true;
  75. }
  76. $now_cate = '';
  77. $article_cate = array();
  78. foreach ($categorys as $k => $v) {
  79. if ($v->id == $id) {
  80. $now_cate = $v->categoryname;
  81. $article_cate = $v;
  82. }
  83. }
  84. $this->putSeoData('article_cate', $article_cate);
  85. $return_data = array(
  86. 'articles'=>$lists,
  87. 'categorys'=>$categorys,
  88. 'categorys_root'=>$categorys_root,
  89. 'key'=>$key,
  90. 'type_id'=>$id,
  91. 'roottype_id' => $search_id,
  92. 'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
  93. 'mobile_dropload' => $mobile_dropload,
  94. 'wap_title' => '人才政策',
  95. //'top_nav'=>$topNav,
  96. 'now_cate'=>$now_cate
  97. );
  98. if ($request->ajax()) {
  99. if ($lists->lastPage() < $lists->currentPage()) {
  100. return response()->json(['status'=>0]);
  101. }
  102. return response()->json(['status'=>1,'data'=>view('mobile.app.content.policy.ajax_policy_list', ['articles'=>$lists])->render()]);
  103. }
  104. return view('mobile.app.content.policy.index', $return_data);
  105. }
  106. public function show($id, $parent_id = '1', $num = '8', $focus = '3', $recommend = '4', $other_num = '5')
  107. {
  108. $categorys = $this->articleCategoryService->getChildCategorys($parent_id, $num);
  109. $article_info =Policy::where(array('id'=>$id))->first();
  110. if (!$article_info) {
  111. $back_url = \Illuminate\Support\Facades\URL::previous();
  112. return $this->showMessage('资讯不存在', $back_url, true, '上一页', '3');
  113. }
  114. $this->putSeoData('article', $article_info);
  115. $return_data = array(
  116. 'categorys' => $categorys,
  117. 'type_id' => $id,
  118. 'info' => $article_info,
  119. 'wap_title' => $article_info->title,
  120. 'parent_id' => $parent_id
  121. );
  122. return view('mobile.app.content.policy.show', $return_data);
  123. }
  124. public function click($id)
  125. {
  126. $rst = $this->policycategoryService->incrementData(array('id'=>$id), 1, 'click');
  127. $data = array('status'=>0);
  128. if ($rst) {
  129. $data = array('status'=>1);
  130. }
  131. return response()->json($data);
  132. }
  133. }