HelpController.php 3.8 KB

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