123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App\Http\Home;
- use App\Services\Eav\MaterialService;
- use App\Services\Elastic\Facades\ES;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- use Illuminate\Support\Facades\Schema;
- class HelpController extends HttpBaseController
- {
- public function __construct()
- {
- parent::__construct();
- }
- public function index()
- {
- $data = [];
- $categoryList = $this->getNewsCategory();
- foreach ($categoryList as $row) {
- $categoryId = $row->id;
- unset($row->id);
- $data[] = [
- 'category' => $row,
- 'news' => $this->getNewsList($categoryId)
- ];
- }
- return view('home/http/help', ['data' => $data]);
- }
- public function category($cid = '')
- {
- $size = 15;
- $page = Request::input('page', 1);
- $page = $page <= 1 ? 1 : ($page > 20 ? 20 : $page);
- if (empty($cid)) {
- abort(404);
- }
- // 获取所有的资讯分类
- $category = DB::table('web_news_category')->get();
- $categoryInfo = DB::table('web_news_category')->select('id')->where('mid', $cid)->first();
- if (empty($categoryInfo)) {
- abort(404);
- }
- // 获取资讯列表
- $find = DB::table('web_news')
- ->where('category_id', $categoryInfo->id)
- ->offset($size * ($page - 1))
- ->limit($size);
- $list = $find->get();
- return view('home/http/newslist', ['category' => $category, 'list' => $list]);
- }
- public function detail($mid = '')
- {
- if (empty($mid)) {
- abort(404);
- }
- // 获取所有的资讯分类
- $category = DB::table('web_news_category')->get();
- $info = DB::table('web_news')->where('mid', $mid)->first();
- return view('home/http/newsdetail', ['info' => $info, 'category' => $category]);
- }
- private function getNewsCategory()
- {
- return DB::table('web_news_category')->select(['id', 'mid', 'name', 'logo'])->get();
- }
- private function getNewsList($categoryId)
- {
- return DB::table('web_news')->where('category_id', $categoryId)->offset(0)->limit(6)->get();
- }
- private function getNews()
- {
- $size = 15;
- $page = Request::input('page', 1);
- $cid = Request::input('cid');
- // 获取资讯分类
- $category = DB::table('news_category')->get();
- // 获取资讯列表
- $find = DB::table('news')
- ->offset($size * ($page - 1))
- ->limit($size);
- if ($cid) {
- $info = DB::table('news_category')->select('id')->where('mid', $cid)->first();
- if ($info) {
- $find->where('category_id', $info->id);
- }
- }
- $list = $find->get();
- return view('home/http/newslist', ['category' => $category, 'list' => $list]);
- }
- }
|