HelpController.php 3.2 KB

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