Hugo Quijada пре 2 година
родитељ
комит
f8f9b1035e

+ 26 - 3
commands/EventoController.php

@@ -782,6 +782,11 @@ class EventoController extends Controller {
       ->indexBy("tag")
       ->column();
 
+    $dependencias = Dependencia::find() 
+      ->select("nombre")
+      ->indexBy("id")
+      ->column();
+
     $totalEventos = count($eventos);
     if ($totalEventos === 0) {
       # ¿Si no hubo eventos en el período de tiempo también hay que avisar?
@@ -859,7 +864,7 @@ class EventoController extends Controller {
     if (!$notificacion->save()) {
       return (new Respuesta($notificacion))
         ->mensaje("Hubo un problema al generar la notificación");
-    }
+    } // */
     # TODO: Revisar si es necesario consultar la información del modelo
     # $notificacion->refresh();
 
@@ -871,6 +876,7 @@ class EventoController extends Controller {
       $notificacionUsuario->idUsuario = $usuario['id'];
       $notificacionUsuario->nombre = $usuario['nombreUsuario'];
       $notificacionUsuario->telefono = $usuario['telefono'];
+      $notificacionUsuario->plantilla = Notificacion::PLANTILLA_EVENTO;
 
       # Es mejor guardar el valor del count en lugar de evaluarlo multiples veces
       $totalParticipaciones = count($usuario["eventosParticipo"]);
@@ -911,6 +917,11 @@ class EventoController extends Controller {
       $dependenciaLider = DependenciaLider::find()
         ->andWhere(["idDependencia" => $id]);
 
+      $nombreDependencia = "";
+      if(isset($dependencias[$id])) {
+        $nombreDependencia = $dependencias[$id];
+      }
+
       foreach ($dependenciaLider->each() as $lider) {
         $usuario = Usuario::findOne($lider["idUsuario"]);
         $notificacionUsuario = new NotificacionUsuario();
@@ -919,15 +930,15 @@ class EventoController extends Controller {
         $notificacionUsuario->idUsuario = $usuario->id;
         $notificacionUsuario->nombre = $usuario->nombre;
         $notificacionUsuario->telefono = $usuario->telefono;
+        $notificacionUsuario->plantilla = Notificacion::PLANTILLA_LIDER_EVENTO;
 
-        # Es mejor guardar el valor del count en lugar de evaluarlo multiples veces
         $totalParticipaciones = $dependencia["eventosParticipo"];
         $totalEventosDependencia = $dependencia["eventosParticipo"] + $dependencia["eventosFaltantes"];
 
         $parametros = [
           [
             "type" => "text",
-            "text" => "{$totalParticipaciones}/{$totalEventosDependencia} eventos"
+            "text" => "*{$nombreDependencia}* fue {$totalParticipaciones}/{$totalEventosDependencia} eventos"
           ],
         ];
 
@@ -957,6 +968,18 @@ class EventoController extends Controller {
     }
 
     $notificacion->estatus = Notificacion::ESTATUS_NUEVO;
+    $domingo = 0;
+    $d = new \DateTime('now', new \DateTimeZone('America/Hermosillo'));
+    $fecha = strtotime('now');
+    $dia = intval($d->format("w"));
+    if($dia !== $domingo) {
+      $d = new \DateTime('next Sunday', new \DateTimeZone('America/Hermosillo'));
+    }
+
+    $d->setTime(18, 0, 0, 0);
+    
+    $siguienteDomingo = $d->format(\DateTime::ISO8601);
+    $notificacion->envio = $siguienteDomingo;
 
     $notificacion->save();
 

+ 12 - 4
commands/NotificacionController.php

@@ -46,6 +46,9 @@ class NotificacionController extends Controller {
           $msgTo = "52".$nu->telefono;
         }
         $template = "laud_resumen_eventos";
+        if($nu->plantilla) {
+          $template = $nu->plantilla;
+        }
         // $template = "informe_de_eventos";
 
         try {
@@ -85,9 +88,14 @@ class NotificacionController extends Controller {
   }
 
   public function actionFecha() {
-    $fecha = \Yii::$app->db->createCommand("select now()")
-      ->queryAll();
-
-    var_dump($fecha);
+    $domingo = 0;
+    $fecha = strtotime('2023-05-07');
+    $dia = intval(date("w", $fecha));
+    if($dia !== $domingo) {
+      $fecha = strtotime('next Sunday');
+    }
+    
+    $siguienteDomingo = date("Y-m-d", $fecha);
+    $this->stdout("{$siguienteDomingo}\n");
   }
 }

+ 3 - 1
components/NotificacionController.php

@@ -4,6 +4,7 @@ namespace app\components;
 
 use app\models\Notificacion;
 use yii\console\Controller;
+use yii\db\Expression;
 
 class NotificacionController extends Controller {
 
@@ -18,7 +19,7 @@ class NotificacionController extends Controller {
   public function consultarNotificacion() {
 
     $query = Notificacion::find()
-      ->orderBy(["id" => SORT_ASC]);
+      ->orderBy(["envio" => SORT_ASC]);
 
     $enviando = (clone $query)
       ->andWhere(["estatus" => Notificacion::ESTATUS_ENVIANDO])
@@ -30,6 +31,7 @@ class NotificacionController extends Controller {
     }
 
     return (clone $query)
+      ->andWhere(["<", "envio", new Expression('now()')])
       ->andWhere(["estatus" => Notificacion::ESTATUS_NUEVO])
       ->one();
   }

+ 24 - 0
migrations/m230506_001938_notificacion_plantilla.php

@@ -0,0 +1,24 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m230506_001938_notificacion_plantilla
+ */
+class m230506_001938_notificacion_plantilla extends Migration {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function safeUp() {
+    $this->addColumn("NotificacionUsuario", "plantilla", $this->string(100));
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function safeDown() {
+    $this->dropColumn("NotificacionUsuario", "plantilla");
+  }
+
+}

+ 3 - 0
models/Notificacion.php

@@ -23,6 +23,9 @@ class Notificacion extends \yii\db\ActiveRecord {
   public const ESTATUS_TERMINADO = "Terminado";
   public const ESTATUS_ERROR = "Error";
 
+  const PLANTILLA_EVENTO = "laud_resumen_eventos";
+  const PLANTILLA_LIDER_EVENTO = "laud_resumen_eventos_dependencia";
+
   /**
    * {@inheritdoc}
    */

+ 3 - 1
models/NotificacionUsuario.php

@@ -14,6 +14,7 @@ use Yii;
  * @property string|null $telefono
  * @property string|null $parametros
  * @property string|null $detalle
+ * @property string|null $plantilla
  *
  * @property Notificacion $notificacion
  * @property Usuario $usuario
@@ -34,7 +35,7 @@ class NotificacionUsuario extends \yii\db\ActiveRecord {
       [['idNotificacion', 'idUsuario'], 'default', 'value' => null],
       [['idNotificacion', 'idUsuario'], 'integer'],
       [['parametros', 'detalle'], 'safe'],
-      [['nombre'], 'string', 'max' => 100],
+      [['nombre', 'plantilla'], 'string', 'max' => 100],
       [['telefono'], 'string', 'max' => 10],
       [['idNotificacion'], 'exist', 'skipOnError' => true, 'targetClass' => Notificacion::class, 'targetAttribute' => ['idNotificacion' => 'id']],
       [['idUsuario'], 'exist', 'skipOnError' => true, 'targetClass' => Usuario::class, 'targetAttribute' => ['idUsuario' => 'id']],
@@ -53,6 +54,7 @@ class NotificacionUsuario extends \yii\db\ActiveRecord {
       'telefono' => 'Telefono',
       'parametros' => 'Parametros',
       'detalle' => 'Detalle',
+      'plantilla' => 'Plantilla',
     ];
   }
 

+ 1 - 0
modules/v1/models/NotificacionUsuario.php

@@ -15,6 +15,7 @@ class NotificacionUsuario extends ModelsNotificacionUsuario {
       'telefono',
       'parametros',
       'detalle',
+      'plantilla',
     ];
   }