EducativoConversao1Push.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Notifications\Push\Cliente\EducativoConversao;
  3. use App\Enums\PushNotificationCategoryEnum;
  4. use App\Enums\PushNotificationTargetEnum;
  5. use App\Models\User;
  6. use App\Notifications\Push\BasePushNotification;
  7. use Illuminate\Database\Eloquent\Collection;
  8. class EducativoConversao1Push extends BasePushNotification
  9. {
  10. public function label(): string { return 'cliente_educ_conversao_1'; }
  11. public function title(): string { return 'Sob Medida funciona assim'; }
  12. public function body(): string { return 'Seu pedido é enviado para várias diaristas disponíveis.'; }
  13. public function target(): PushNotificationTargetEnum { return PushNotificationTargetEnum::CLIENTE; }
  14. public function category(): PushNotificationCategoryEnum { return PushNotificationCategoryEnum::EDUCATIVO_CONVERSAO; }
  15. public function notificationCooldownDays(): int { return 28; }
  16. public function categoryCooldownDays(): int { return 14; }
  17. /**
  18. * Elegível se:
  19. * - Nunca agendou via Sob Medida (schedule_type = custom)
  20. * - OU último agendamento Sob Medida foi há >30 dias
  21. */
  22. public function eligibleUsers(): Collection
  23. {
  24. return User::whereHas('client')
  25. ->where('registration_complete', true)
  26. ->where(function ($query) {
  27. $query->whereDoesntHave('client.schedules', fn ($q) => $q->where('schedule_type', 'custom'))
  28. ->orWhereDoesntHave('client.schedules', fn ($q) => $q->where('schedule_type', 'custom')
  29. ->where('created_at', '>=', now()->subDays(30)));
  30. })
  31. ->get();
  32. }
  33. }