SendSms.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. $new = \App\Models\MemberCertificate::where('expire_date', '>', $expire_date)->count();
  30. if ($new == 0)
  31. {
  32. $phone = $certificate->member->phone;
  33. $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';
  34. $params = array(
  35. 'to' => '+39' . $phone,
  36. 'from' => env('SMS_FROM', 'Test'),
  37. 'message' => $message,
  38. 'format' => 'json',
  39. );
  40. sms_send($params);
  41. }
  42. }
  43. $expire_date = date("Y-m-d", strtotime("+15 days"));
  44. $expire_date_it = date("d/m/Y", strtotime("+15 days"));
  45. $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
  46. foreach ($certificates as $certificate) {
  47. $new = \App\Models\MemberCertificate::where('expire_date', '>', $expire_date)->count();
  48. if ($new == 0)
  49. {
  50. $phone = $certificate->member->phone;
  51. $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';
  52. $params = array(
  53. 'to' => '+39' . $phone,
  54. 'from' => env('SMS_FROM', 'Test'),
  55. 'message' => $message,
  56. 'format' => 'json',
  57. );
  58. sms_send($params);
  59. }
  60. }
  61. return Command::SUCCESS;
  62. }
  63. }