SocialProof1Push.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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
  11. {
  12. return 'cliente_social_proof_1';
  13. }
  14. public function title(): string
  15. {
  16. return 'Clientes como você';
  17. }
  18. public function body(): string
  19. {
  20. return 'Já estão usando o Diária para facilitar a rotina.';
  21. }
  22. public function target(): PushNotificationTargetEnum
  23. {
  24. return PushNotificationTargetEnum::CLIENTE;
  25. }
  26. public function category(): PushNotificationCategoryEnum
  27. {
  28. return PushNotificationCategoryEnum::SOCIAL_PROOF;
  29. }
  30. public function notificationCooldownDays(): int
  31. {
  32. return 28;
  33. }
  34. public function categoryCooldownDays(): int
  35. {
  36. return 14;
  37. }
  38. /**
  39. * Elegível se:
  40. * - Nunca teve agendamento com status finished
  41. * - OU último agendamento finished foi há >30 dias
  42. */
  43. public function eligibleUsers(): Collection
  44. {
  45. return User::whereHas('client')
  46. ->where('registration_complete', true)
  47. ->where(function ($query) {
  48. $query->whereDoesntHave('client.schedules', fn ($q) => $q->where('status', 'finished'))
  49. ->orWhereDoesntHave('client.schedules', fn ($q) => $q->where('status', 'finished')
  50. ->where('updated_at', '>=', now()->subDays(30)));
  51. })
  52. ->get();
  53. }
  54. }