<?php
 namespace App\Http\Controllers\Main; use App\Http\Controllers\BaseController; use App\Util\NoteUtil; use TechOnline\Laravel\Dao\ModelUtil; use TechSoft\Laravel\Banner\BannerUtil; use TechSoft\Laravel\Member\MemberUtil; use TechSoft\Laravel\Member\Traits\MemberAccountWebControllerTrait; use TechSoft\Laravel\MemberFollow\MemberFollowUtil; class IndexController extends BaseController { use MemberAccountWebControllerTrait; public function index() { if ($this->isMobile()) { $banners = BannerUtil::listByPositionWithCache('mHome'); } else { $banners = BannerUtil::listByPositionWithCache('pcHome'); } $paginateData = NoteUtil::paginateNotes(1, 20, ['where' => ['isRecommend' => true,], 'order' => ['id', 'desc']]); $recommendNotes = $paginateData['records']; $paginateData = NoteUtil::paginateNotes(1, 20, ['order' => ['commentCount', 'desc']]); $commentNotes = $paginateData['records']; $paginateData = NoteUtil::paginateNotes(1, 20, ['order' => ['viewCount', 'desc']]); $hotNotes = $paginateData['records']; $paginateData = NoteUtil::paginateNotes(1, 20, ['order' => ['id', 'desc']]); $latestNotes = $paginateData['records']; MemberUtil::mergeMemberUsers($recommendNotes); MemberUtil::mergeMemberUsers($commentNotes); MemberUtil::mergeMemberUsers($hotNotes); MemberUtil::mergeMemberUsers($latestNotes); $hotTopics = ModelUtil::model('topic')->orderBy('followerCount', 'desc')->limit(10)->get()->toArray(); $hotMemberUsers = ModelUtil::model('member_user')->orderBy('noteCount', 'desc')->limit(10)->get()->toArray(); $latestMemberUsers = ModelUtil::model('member_user')->orderBy('id', 'desc')->limit(10)->get()->toArray(); MemberFollowUtil::mergeIsFollowed($hotMemberUsers, $this->memberUserId()); MemberFollowUtil::mergeIsFollowed($latestMemberUsers, $this->memberUserId()); return $this->_view('index', [ 'banners' => $banners, 'hotTopics' => $hotTopics, 'recommendNotes' => $recommendNotes, 'commentNotes' => $commentNotes, 'latestNotes' => $latestNotes, 'hotNotes' => $hotNotes, 'hotMemberUsers' => $hotMemberUsers, 'latestMemberUsers' => $latestMemberUsers, ]); } }