TopUpService.php 653B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Database\Eloquent\Collection as EloquentCollection;
  4. class TopUpService
  5. {
  6. public static function topStatistic(EloquentCollection $collections, int $take = 5)
  7. {
  8. return $collections
  9. ->transform(fn($collects) => [[
  10. 'label1' => $collects->first()->member->name,
  11. 'label2' => $collects->first()->member->phone,
  12. 'data' => $collects->sum(fn($collect) =>
  13. $collect->getRawOriginal('amount')
  14. )
  15. ]])
  16. ->sortByDesc('amount')
  17. ->take($take)
  18. ->flatten(1);
  19. }
  20. }