SocialProof1Push.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Notifications\Push\Cliente\SocialProof;
  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 SocialProof1Push extends BasePushNotification
  9. {
  10. public function label(): string { return 'cliente_social_proof_1'; }
  11. public function title(): string { return 'Clientes como você'; }
  12. public function body(): string { return 'Já estão usando o Diária para facilitar a rotina.'; }
  13. public function target(): PushNotificationTargetEnum { return PushNotificationTargetEnum::CLIENTE; }
  14. public function category(): PushNotificationCategoryEnum { return PushNotificationCategoryEnum::SOCIAL_PROOF; }
  15. public function notificationCooldownDays(): int { return 28; }
  16. public function categoryCooldownDays(): int { return 14; }
  17. /**
  18. * Elegível se:
  19. * - Nunca teve agendamento com status finished
  20. * - OU último agendamento finished 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('status', 'finished'))
  28. ->orWhereDoesntHave('client.schedules', fn ($q) => $q->where('status', 'finished')
  29. ->where('updated_at', '>=', now()->subDays(30)));
  30. })
  31. ->get();
  32. }
  33. }