Luca Parisio 9 kuukautta sitten
vanhempi
commit
6fda005deb
2 muutettua tiedostoa jossa 81 lisäystä ja 17 poistoa
  1. 63 0
      app/Console/Commands/SendSms.php
  2. 18 17
      routes/web.php

+ 63 - 0
app/Console/Commands/SendSms.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class SendSms extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'send:sms';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Send SMS';
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+
+        $expire_date = date("Y-m-d", strtotime("+1 month"));
+        $expire_date_it = date("d/m/Y", strtotime("+1 month"));
+        $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
+        foreach ($certificates as $certificate) {
+            $phone = $certificate->member->phone;
+            $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';
+            $params = array(
+                'to'            => '+39' . $phone,
+                'from'          => env('SMS_FROM', 'Test'),
+                'message'       => $message,
+                'format'        => 'json',
+            );
+            sms_send($params);
+        }
+
+        $expire_date = date("Y-m-d", strtotime("+15 days"));
+        $expire_date_it = date("d/m/Y", strtotime("+15 days"));
+        $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
+        foreach ($certificates as $certificate) {
+            $phone = $certificate->member->phone;
+            $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';
+            $params = array(
+                'to'            => '+39' . $phone,
+                'from'          => env('SMS_FROM', 'Test'),
+                'message'       => $message,
+                'format'        => 'json',
+            );
+            sms_send($params);
+        }
+
+        return Command::SUCCESS;
+    }
+}

+ 18 - 17
routes/web.php

@@ -1542,35 +1542,36 @@ Route::get('/updateCourseCausal', function () {
     }
 });
 
-Route::get('/test_sms', function () {
+Route::get('/send_sms', function () {
 
     $expire_date = date("Y-m-d", strtotime("+1 month"));
     $expire_date_it = date("d/m/Y", strtotime("+1 month"));
     $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
     foreach ($certificates as $certificate) {
-        //$phone = $certificate->member->phone;
-        $phone = '3893163265';
+        $phone = $certificate->member->phone;
+        $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';
         $params = array(
             'to'            => '+39' . $phone,
             'from'          => env('SMS_FROM', 'Test'),
-            'message'       => $certificate->member->first_name . ', il tuo certificato medico scadrà il ' . $expire_date_it,
+            'message'       => $message,
             'format'        => 'json',
         );
-
         sms_send($params);
-        print "Inviato";
     }
 
-    /*
-
-    $params = array(
-        'to'            => '+393893163265',
-        'from'          => env('SMS_FROM', 'Test'),
-        'message'       => 'Prova SMS da IAO',
-        'format'        => 'json',
-    );
-
-    echo sms_send($params);
+    $expire_date = date("Y-m-d", strtotime("+15 days"));
+    $expire_date_it = date("d/m/Y", strtotime("+15 days"));
+    $certificates = \App\Models\MemberCertificate::where('expire_date', $expire_date)->get();
+    foreach ($certificates as $certificate) {
+        $phone = $certificate->member->phone;
+        $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';
+        $params = array(
+            'to'            => '+39' . $phone,
+            'from'          => env('SMS_FROM', 'Test'),
+            'message'       => $message,
+            'format'        => 'json',
+        );
+        sms_send($params);
+    }
 
-    */
 });