HelpController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. dd($categoryList);
  21. foreach ($categoryList as $row) {
  22. $categoryId = $row->id;
  23. unset($row->id);
  24. $data[] = [
  25. 'category' => $row,
  26. 'news' => $this->getNewsList($categoryId)
  27. ];
  28. }
  29. return view('home/http/help', ['data' => $data]);
  30. }
  31. public function category($cid = '')
  32. {
  33. $size = 15;
  34. $page = Request::input('page', 1);
  35. $page = $page <= 1 ? 1 : ($page > 20 ? 20 : $page);
  36. if (empty($cid)) {
  37. abort(404);
  38. }
  39. // 获取所有的资讯分类
  40. $category = DB::table('web_news_category')->get();
  41. $categoryInfo = DB::table('web_news_category')->select('id')->where('mid', $cid)->first();
  42. if (empty($categoryInfo)) {
  43. abort(404);
  44. }
  45. // 获取资讯列表
  46. $find = DB::table('web_news')
  47. ->where('category_id', $categoryInfo->id)
  48. ->offset($size * ($page - 1))
  49. ->limit($size);
  50. $list = $find->get();
  51. return view('home/http/newslist', ['category' => $category, 'list' => $list]);
  52. }
  53. public function detail($mid = '')
  54. {
  55. if (empty($mid)) {
  56. abort(404);
  57. }
  58. // 获取所有的资讯分类
  59. $category = DB::table('web_news_category')->get();
  60. $info = DB::table('web_news')->where('mid', $mid)->first();
  61. return view('home/http/newsdetail', ['info' => $info, 'category' => $category]);
  62. }
  63. private function getNewsCategory()
  64. {
  65. return DB::table('web_news_category')->select(['id', 'mid', 'name', 'logo'])->get();
  66. }
  67. private function getNewsList($categoryId)
  68. {
  69. return DB::table('web_news')->where('category_id', $categoryId)->offset(0)->limit(6)->get();
  70. }
  71. private function getNews()
  72. {
  73. $size = 15;
  74. $page = Request::input('page', 1);
  75. $cid = Request::input('cid');
  76. // 获取资讯分类
  77. $category = DB::table('news_category')->get();
  78. // 获取资讯列表
  79. $find = DB::table('news')
  80. ->offset($size * ($page - 1))
  81. ->limit($size);
  82. if ($cid) {
  83. $info = DB::table('news_category')->select('id')->where('mid', $cid)->first();
  84. if ($info) {
  85. $find->where('category_id', $info->id);
  86. }
  87. }
  88. $list = $find->get();
  89. return view('home/http/newslist', ['category' => $category, 'list' => $list]);
  90. }
  91. }