Parcourir la source

Reporte lider global

ElPoteito il y a 2 ans
Parent
commit
53a39134bf

+ 69 - 6
commands/EventoController.php

@@ -429,7 +429,7 @@ class EventoController extends Controller {
     $ultimaFecha = null;
     $limite = 100; // 1000;
     $continuar = true;
-    
+
     $fechaActual = new DateTime();
     $finFirebase = new Timestamp($fechaActual);
 
@@ -798,7 +798,7 @@ class EventoController extends Controller {
       ->indexBy("tag")
       ->column();
 
-    $dependencias = Dependencia::find() 
+    $dependencias = Dependencia::find()
       ->select("nombre")
       ->indexBy("id")
       ->column();
@@ -934,7 +934,7 @@ class EventoController extends Controller {
         ->andWhere(["idDependencia" => $id]);
 
       $nombreDependencia = "";
-      if(isset($dependencias[$id])) {
+      if (isset($dependencias[$id])) {
         $nombreDependencia = $dependencias[$id];
       }
 
@@ -966,7 +966,7 @@ class EventoController extends Controller {
         } else if ($totalParticipaciones > 0) {
           $parametros[] = [
             "type" => "text",
-            "text" => ", gracias por tu participación. Vamos por el 100% de"
+            "text" => " gracias por tu participación. Vamos por el 100% de"
           ];
         } else {
           $parametros[] = [
@@ -983,17 +983,80 @@ class EventoController extends Controller {
       }
     }
 
+    //LIDER GLOBAL
+    $liderGlobal = Usuario::find()
+      ->andWhere(["liderGlobal" => true]);
+
+    foreach ($liderGlobal->each() as $lider) {
+      $mensaje = "";
+      $participaciones = 0;
+      foreach ($auxDependencia as $id => $dependencia) {
+        $nombreDependencia = "";
+        if (isset($dependencias[$id])) {
+          $nombreDependencia = $dependencias[$id];
+
+          $totalParticipaciones = $dependencia["eventosParticipo"];
+          $totalEventosDependencia = $dependencia["eventosParticipo"] + $dependencia["eventosFaltantes"];
+
+          $mensaje .= "*{$nombreDependencia}* fue {$totalParticipaciones}/{$totalEventosDependencia} eventos || ";
+          $participaciones += $totalParticipaciones;
+        }
+      }
+
+      $notificacionUsuario = new NotificacionUsuario();
+
+      $notificacionUsuario->idNotificacion = $notificacion->id;
+      $notificacionUsuario->idUsuario = $lider->id;
+      $notificacionUsuario->nombre = $lider->nombre;
+      $notificacionUsuario->telefono = $lider->telefono;
+      $notificacionUsuario->plantilla = Notificacion::PLANTILLA_LIDER_GLOBAL;
+
+      // $totalParticipaciones = $dependencia["eventosParticipo"];
+      // $totalEventosDependencia = $dependencia["eventosParticipo"] + $dependencia["eventosFaltantes"];
+
+      $parametros = [
+        [
+          "type" => "text",
+          "text" => $mensaje
+        ],
+      ];
+
+
+      if ($participaciones === $totalEventosDependencia) {
+        $parametros[] = [
+          "type" => "text",
+          "text" => "Gracias por tu"
+        ];
+      } else if ($participaciones > 0) {
+        $parametros[] = [
+          "type" => "text",
+          "text" => "Gracias por tu participación. Vamos por el 100% de"
+        ];
+      } else {
+        $parametros[] = [
+          "type" => "text",
+          "text" => "Vamos por el 100% de"
+        ];
+      }
+      $notificacionUsuario->parametros = $parametros;
+
+      if (!$notificacionUsuario->save()) {
+        return (new Respuesta($notificacionUsuario))
+          ->mensaje("Hubo un problema al generar la notificación");
+      }
+    }
+
     $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) {
+    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;
 

+ 24 - 0
migrations/m230515_183220_ajustes_usuario.php

@@ -0,0 +1,24 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m230515_183220_ajustes_usuario
+ */
+class m230515_183220_ajustes_usuario extends Migration {
+  /**
+   * {@inheritdoc}
+   */
+  public function safeUp() {
+
+    $this->addColumn('Usuario', 'liderGlobal', $this->boolean());
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function safeDown() {
+
+    $this->dropColumn('Usuario', 'liderGlobal');
+  }
+}

+ 1 - 0
models/Notificacion.php

@@ -25,6 +25,7 @@ class Notificacion extends \yii\db\ActiveRecord {
 
   const PLANTILLA_EVENTO = "laud_resumen_eventos";
   const PLANTILLA_LIDER_EVENTO = "laud_resumen_eventos_dependencia";
+  const PLANTILLA_LIDER_GLOBAL = "laud_resumen_dependencias_lider_global";
 
   /**
    * {@inheritdoc}

+ 3 - 1
models/Usuario.php

@@ -20,6 +20,7 @@ use Yii;
  * @property bool|null $twitterVerificado
  * @property string|null $genero H: Hombre - M: Mujer
  * @property string|null $verificado
+ * @property bool|null $liderGlobal
  * @property string|null $creado
  * @property string|null $modificado
  * @property string|null $eliminado
@@ -43,7 +44,7 @@ class Usuario extends \yii\db\ActiveRecord {
   public function rules() {
     return [
       [['nombre'], 'required'],
-      [['facebookVerificado', 'instagramVerificado', 'twitterVerificado'], 'boolean'],
+      [['facebookVerificado', 'instagramVerificado', 'twitterVerificado', 'liderGlobal'], 'boolean'],
       [['verificado', 'creado', 'modificado', 'eliminado'], 'safe'],
       [['uid', 'genero'], 'string', 'max' => 50],
       [['email', 'nombre', 'facebook', 'instagram', 'twitter'], 'string', 'max' => 100],
@@ -70,6 +71,7 @@ class Usuario extends \yii\db\ActiveRecord {
       'twitterVerificado' => 'Twitter Verificado',
       'genero' => 'Género',
       'verificado' => 'Verificado',
+      'liderGlobal' => 'Lider Global',
       'creado' => 'Creado',
       'modificado' => 'Modificado',
       'eliminado' => 'Eliminado',

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

@@ -21,6 +21,7 @@ class Usuario extends ModeloUsuario {
       'twitterVerificado',
       'genero',
       'verificado',
+      'liderGlobal',
       'creado',
       'modificado',
       'eliminado',