TopUpService.php 640B

12345678910111213141516171819202122
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Database\Eloquent\Collection as EloquentCollection;
  4. class TopUpService extends CurrencyFormatService
  5. {
  6. public 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) => $collect->getRawOriginal('amount')),
  13. ]])
  14. ->sortByDesc('amount')
  15. ->take($take)
  16. ->flatten(1);
  17. }
  18. }