HelpController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $total = DB::table('news')->where('category_id', $categoryInfo->id)->count();
  72. return view('home/http/newslist', ['category' => $category, 'list' => $list, 'total' => $total]);
  73. }
  74. public function detail($mid = '')
  75. {
  76. if (empty($mid)) {
  77. abort(404);
  78. }
  79. // 获取所有的资讯分类
  80. $category = DB::table('news_category')->get();
  81. $info = DB::table('news')->where('mid', $mid)->first();
  82. return view('home/http/newsdetail', ['info' => $info, 'category' => $category]);
  83. }
  84. private function getNewsCategory()
  85. {
  86. return DB::table('news_category')->select(['id', 'mid', 'name', 'product_id'])->get();
  87. }
  88. private function getNewsList($categoryId)
  89. {
  90. return DB::table('news')->where('category_id', $categoryId)->offset(0)->limit(6)->get();
  91. }
  92. private function getNews()
  93. {
  94. $size = 15;
  95. $page = Request::input('page', 1);
  96. $cid = Request::input('cid');
  97. // 获取资讯分类
  98. $category = DB::table('news_category')->get();
  99. // 获取资讯列表
  100. $find = DB::table('news')
  101. ->offset($size * ($page - 1))
  102. ->limit($size);
  103. if ($cid) {
  104. $info = DB::table('news_category')->select('id')->where('mid', $cid)->first();
  105. if ($info) {
  106. $find->where('category_id', $info->id);
  107. }
  108. }
  109. $list = $find->get();
  110. return view('home/http/newslist', ['category' => $category, 'list' => $list]);
  111. }
  112. }