public function showHomePage() { if (!Config::get('constants.installed')) { return Redirect::to('install'); } $needRandomAlbumNum = 9; $randomAlbums = array(); $randomAlbumsOffsetArray = null; $albumCount = AmaotoAlbum::count(); if ($albumCount) { $albumOffsetRange = range(0, $albumCount - 1); if ($albumCount > $needRandomAlbumNum) { $randomAlbumsOffsetArray = array_rand($albumOffsetRange, $needRandomAlbumNum); } else { $randomAlbumsOffsetArray = array_rand($albumOffsetRange, $albumCount); } shuffle($randomAlbumsOffsetArray); foreach ($randomAlbumsOffsetArray as $offset) { $randomAlbums[] = AmaotoAlbum::offset($offset)->first(); } } $needRandomMusicNum = 8; $randomMusics = array(); $randomMusicsOffsetArray = null; $musicCount = AmaotoMusic::count(); if ($musicCount) { $musicOffsetRange = range(0, $musicCount - 1); if ($musicCount > $needRandomMusicNum) { $randomMusicsOffsetArray = array_rand($musicOffsetRange, $needRandomMusicNum); } else { $randomMusicsOffsetArray = array_rand($musicOffsetRange, $musicCount); } shuffle($randomMusicsOffsetArray); foreach ($randomMusicsOffsetArray as $offset) { $randomMusics[] = AmaotoMusic::offset($offset)->first(); } } return View::make('home/home-page', array('albumCount' => $albumCount, 'musicCount' => $musicCount, 'randomAlbums' => $randomAlbums, 'randomMusics' => $randomMusics)); }
public function getMusicsCount() { try { $musicsCount = AmaotoMusic::count(); return Response::json(array('type' => 'success', 'message' => '获取成功', 'data' => array('count' => $musicsCount))); } catch (NotExistException $e) { return Response::json(array('type' => 'warning', 'message' => $e->getMessage())); } catch (Exception $e) { return Response::json(array('type' => 'error', 'message' => $e->getMessage())); } }