console.php 3.1 KB

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