console.php 3.0 KB

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