Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.4 kB
0
Indexable
Never
public function getTippedFeeds(CoreUser $user, array $dateRange, $limit = 10, $offset = 0)
    {
        $result = collect([]);
        $tippedFeeds =  DailyUserFeedRewardSummary::where('target_id', $user->id)
            ->where('date_id', '>=', $dateRange['start'])
            ->where('date_id', '<=', $dateRange['end'])
            ->selectRaw('feed_id, SUM(amount) as yipps')
            ->groupBy('feed_id')
            ->orderByDesc('feed_id')
            ->limit($limit)
            ->offset($offset)
            ->get();

        $feedIds = $tippedFeeds->pluck('feed_id')->toArray();
        
        if ($feedIds ) {
            $feeds = collect(Feeds::get($feedIds));
            $result = $feeds->map(function ($data) use ($tippedFeeds){
                return [
                    'id' => $data['id'],
                    'cover_image' => $data['cover_image'],
                    'like_count' => $data['like_count'],
                    'comment_count' => $data['feed_comment_count'],
                    'created_at' => $data['created_at'],
                    'deleted_at' => $data['deleted_at'],
                    'yipps' => (float) $tippedFeeds->firstWhere('feed_id', $data['id'])->yipps,
                    'feed_type' => $data['feed_type'],
                    'feed_content' => $data['feed_content']
                ];
            });
        }

        return $result;
    }
Leave a Comment