HelpController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Http\Home;
  3. use App\Services\Eav\MaterialService;
  4. use App\Services\Elastic\Facades\ES;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Carbon;
  7. use Illuminate\Support\Facades\DB;
  8. use Illuminate\Support\Facades\Request;
  9. use Illuminate\Support\Facades\Schema;
  10. class HelpController extends HttpBaseController
  11. {
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. public function index()
  17. {
  18. $data = [];
  19. $categoryList = $this->getNewsCategory();
  20. foreach ($categoryList as $row) {
  21. $categoryId = $row->id;
  22. unset($row->id);
  23. $data[] = [
  24. 'category' => $row,
  25. 'news' => $this->getNewsList($categoryId)
  26. ];
  27. }
  28. return view('home/http/help', ['data' => $data]);
  29. }
  30. public function category($cid = '')
  31. {
  32. $size = 15;
  33. $page = Request::input('page', 1);
  34. $page = $page <= 1 ? 1 : ($page > 20 ? 20 : $page);
  35. if (empty($cid)) {
  36. abort(404);
  37. }
  38. // 获取所有的资讯分类
  39. $category = DB::table('web_news_category')->get();
  40. $categoryInfo = DB::table('web_news_category')->select('id')->where('mid', $cid)->first();
  41. if (empty($categoryInfo)) {
  42. abort(404);
  43. }
  44. // 获取资讯列表
  45. $find = DB::table('web_news')
  46. ->where('category_id', $categoryInfo->id)
  47. ->offset($size * ($page - 1))
  48. ->limit($size);
  49. $list = $find->get();
  50. return view('home/http/newslist', ['category' => $category, 'list' => $list]);
  51. }
  52. public function detail($mid = '')
  53. {
  54. if (empty($mid)) {
  55. abort(404);
  56. }
  57. // 获取所有的资讯分类
  58. $category = DB::table('web_news_category')->get();
  59. $info = DB::table('web_news')->where('mid', $mid)->first();
  60. return view('home/http/newsdetail', ['info' => $info, 'category' => $category]);
  61. }
  62. private function getNewsCategory()
  63. {
  64. return DB::table('web_news_category')->select(['id', 'mid', 'name', 'logo'])->get();
  65. }
  66. private function getNewsList($categoryId)
  67. {
  68. return DB::table('web_news')->where('category_id', $categoryId)->offset(0)->limit(6)->get();
  69. }
  70. private function getNews()
  71. {
  72. $size = 15;
  73. $page = Request::input('page', 1);
  74. $cid = Request::input('cid');
  75. // 获取资讯分类
  76. $category = DB::table('news_category')->get();
  77. // 获取资讯列表
  78. $find = DB::table('news')
  79. ->offset($size * ($page - 1))
  80. ->limit($size);
  81. if ($cid) {
  82. $info = DB::table('news_category')->select('id')->where('mid', $cid)->first();
  83. if ($info) {
  84. $find->where('category_id', $info->id);
  85. }
  86. }
  87. $list = $find->get();
  88. return view('home/http/newslist', ['category' => $category, 'list' => $list]);
  89. }
  90. }