console.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. use App\Commands\CreateCrud;
  3. use App\Commands\RefreshPermissions;
  4. use App\Commands\TestWebsocketEvent;
  5. use App\Models\Provider;
  6. use App\Services\Pagarme\PagarmeTransferService;
  7. use App\Services\ProviderWithdrawalService;
  8. use Illuminate\Foundation\Inspiring;
  9. use Illuminate\Support\Facades\Artisan;
  10. Artisan::command('inspire', function () {
  11. $this->comment(Inspiring::quote());
  12. })->purpose('Display an inspiring quote');
  13. Artisan::command('create:crud {name} {--m|model} {--s|service} {--c|controller} {--r|request} {--e|resource} {--t|route} {--g|migration} {--all}', function () {
  14. $this->call(CreateCrud::class, [
  15. 'name' => $this->argument('name'),
  16. '--model' => $this->option('model'),
  17. '--service' => $this->option('service'),
  18. '--controller' => $this->option('controller'),
  19. '--request' => $this->option('request'),
  20. '--resource' => $this->option('resource'),
  21. '--route' => $this->option('route'),
  22. '--migration' => $this->option('migration'),
  23. '--all' => $this->option('all'),
  24. ]);
  25. })->purpose('Create CRUD operations with typed Models');
  26. Artisan::command('permissions:refresh', function () {
  27. $this->call(RefreshPermissions::class);
  28. })->purpose('Refresh all permissions and user type permissions');
  29. Artisan::command('websocket:test {room} {--event=test-event} {--data=}', function () {
  30. $this->call(TestWebsocketEvent::class, [
  31. 'room' => $this->argument('room'),
  32. '--event' => $this->option('event'),
  33. '--data' => $this->option('data'),
  34. ]);
  35. })->purpose('Test websocket broadcasting by emitting an event');
  36. //
  37. Artisan::command('pagarme:recipient-balance {recipient_id} {--skip-local}', function (
  38. PagarmeTransferService $pagarmeTransfer,
  39. ProviderWithdrawalService $withdrawals,
  40. ) {
  41. $recipientId = $this->argument('recipient_id');
  42. if (! $this->option('skip-local')) {
  43. $provider = Provider::query()
  44. ->where('recipient_id', $recipientId)
  45. ->first();
  46. if ($provider) {
  47. $this->info('Saldo calculado localmente:');
  48. $this->line(sprintf(' available: R$ %s', number_format($withdrawals->getAvailableBalance($provider), 2, ',', '.')));
  49. $this->line(sprintf(' pending: R$ %s', number_format($withdrawals->getPendingBalance($provider), 2, ',', '.')));
  50. $this->newLine();
  51. } else {
  52. $this->warn('Nenhum provider local encontrado para esse recipient_id.');
  53. $this->newLine();
  54. }
  55. }
  56. $this->info('Saldo retornado pelo Pagar.me:');
  57. $this->line(json_encode($pagarmeTransfer->getRecipientBalance($recipientId), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
  58. })->purpose('Consult Pagar.me recipient balance and compare it with local withdrawal balance');