SendSms.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class SendSms extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'send:sms';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = 'Send SMS';
  18. /**
  19. * Execute the console command.
  20. *
  21. * @return int
  22. */
  23. public function handle()
  24. {
  25. $expire_date = date("Y-m-d", strtotime("+1 month"));
  26. $expire_date_it = date("d/m/Y", strtotime("+1 month"));
  27. $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
  28. foreach ($certificates as $certificate) {
  29. $phone = $certificate->member->phone;
  30. $message = 'Ciao ' . $certificate->member->first_name . ', ci risulta che il tuo certificato medico scade il ' . $expire_date_it . '. Per continuare ad allenarti senza problemi, ricordati di rinnovarlo in tempo. Ti aspettiamo in campo! Centro Sportivo La Madonnella';
  31. $params = array(
  32. 'to' => '+39' . $phone,
  33. 'from' => env('SMS_FROM', 'Test'),
  34. 'message' => $message,
  35. 'format' => 'json',
  36. );
  37. sms_send($params);
  38. }
  39. $expire_date = date("Y-m-d", strtotime("+15 days"));
  40. $expire_date_it = date("d/m/Y", strtotime("+15 days"));
  41. $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
  42. foreach ($certificates as $certificate) {
  43. $phone = $certificate->member->phone;
  44. $message = 'Ciao ' . $certificate->member->first_name . ', ci risulta che il tuo certificato medico scade il ' . $expire_date_it . '. Per continuare ad allenarti senza problemi, ricordati di rinnovarlo in tempo. Ti aspettiamo in campo! Centro Sportivo La Madonnella';
  45. $params = array(
  46. 'to' => '+39' . $phone,
  47. 'from' => env('SMS_FROM', 'Test'),
  48. 'message' => $message,
  49. 'format' => 'json',
  50. );
  51. sms_send($params);
  52. }
  53. return Command::SUCCESS;
  54. }
  55. }