123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Http\Controllers\Goodnight;
- use App\Http\Controllers\Miniprogram\Auth;
- use App\Http\Resources\Goodnight\RankCollection;
- use App\Models\Goodnight\ThumbModel;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class RankController extends Controller
- {
- //
- public function total(Request $request)
- {
- $page = $request->input('page', 1);
- $per_page = $request->input('per_page', 100);
- $builder = \Cache::get("goodnight:rank:total", collect());
- $total = $builder->count();
- $last_page = ceil($total / $per_page);
- $voices = $builder->slice(($page - 1) * $per_page, $per_page)->values();
- foreach ($voices as $voice) {
- try {
- $uid = Auth::auth();
- // 自己对这张卡片的操作
- $self = array(
- 'like' => false,
- 'is_self' => false
- );
- if ($voice->uid == $uid) {
- $self['is_self'] = true;
- }
- if (
- ThumbModel::where([
- ['voice_id', $voice->id],
- ['uid', $uid]
- ])->exists()
- ) {
- $self['like'] = true;
- }
- $voice->self = $self;
- } catch (\Exception $e) {
- }
- }
- return (new RankCollection($voices))
- ->additional([
- 'meta' => [
- 'current_page' => $page,
- 'per_page' => $per_page,
- 'last_page' => $last_page,
- 'total' => $total,
- ]
- ]);
- }
- public function daily(Request $request)
- {
- $page = $request->input('page', 1);
- $per_page = $request->input('per_page', 100);
- $builder = \Cache::get("goodnight:rank:daily:" . date("Y-m-d"), collect());
- $total = $builder->count();
- $last_page = ceil($total / $per_page);
- $voices = $builder->slice(($page - 1) * $per_page, $per_page)->values();
- foreach ($voices as $voice) {
- try {
- $uid = Auth::auth();
- // 自己对这张卡片的操作
- $self = array(
- 'like' => false,
- 'is_self' => false
- );
- if ($voice->uid == $uid) {
- $self['is_self'] = true;
- }
- if (
- ThumbModel::where([
- ['voice_id', $voice->id],
- ['uid', $uid]
- ])->exists()
- ) {
- $self['like'] = true;
- }
- $voice->self = $self;
- } catch (\Exception $e) {
- }
- }
- return (new RankCollection($voices))
- ->additional([
- 'meta' => [
- 'current_page' => $page,
- 'per_page' => $per_page,
- 'last_page' => $last_page,
- 'total' => $total,
- ]
- ]);
- }
- public function topic(Request $request)
- {
- $page = $request->input('page', 1);
- $per_page = $request->input('per_page', 100);
- $builder = \Cache::get("goodnight:rank:topic", collect());
- $total = $builder->count();
- $last_page = ceil($total / $per_page);
- $voices = $builder->slice(($page - 1) * $per_page, $per_page)->values();
- foreach ($voices as $voice) {
- try {
- $uid = Auth::auth();
- // 自己对这张卡片的操作
- $self = array(
- 'like' => false,
- 'is_self' => false
- );
- if ($voice->uid == $uid) {
- $self['is_self'] = true;
- }
- if (
- ThumbModel::where([
- ['voice_id', $voice->id],
- ['uid', $uid]
- ])->exists()
- ) {
- $self['like'] = true;
- }
- $voice->self = $self;
- } catch (\Exception $e) {
- }
- }
- return (new RankCollection($voices))
- ->additional([
- 'meta' => [
- 'current_page' => $page,
- 'per_page' => $per_page,
- 'last_page' => $last_page,
- 'total' => $total,
- ]
- ]);
- }
- }
|