log general

This commit is contained in:
Felipe
2023-10-07 17:31:35 -05:00
parent 3d3a9cca5e
commit 41605dd83f
12 changed files with 174 additions and 63 deletions
+37 -37
View File
@@ -8,6 +8,7 @@ use App\Models\Cuentas;
use App\Models\Role;
use App\Models\Historial_cuenta;
use App\Models\Historiale;
use App\Models\Log_general;
use App\Models\Promociones;
use App\Models\Saldo;
use App\Models\Servicio;
@@ -89,7 +90,6 @@ class ShowServicios extends Component
$this->nombre_tarjetaPlan = $this->usuario_actual->name;
$this->email_tarjetaPlan = $this->usuario_actual->email;
$this->celular_tarjetaPlan = $this->usuario_actual->celular;
}
if (!empty($this->tarifa_id)) {
$this->paquetesDisponibles();
@@ -124,7 +124,7 @@ class ShowServicios extends Component
->first();
$this->servicio_t = $this->tarifas->servicio;
//Servicio por pantallas
$this->cuentas_creadas = Cuentas::whereDate('inicio', '>=', $this->fecha)
->where('servicio_id', $this->servicio_t->id)
@@ -139,10 +139,10 @@ class ShowServicios extends Component
//$prueba1 = $this->cuentas_creadas->count() * $this->servicio_t->pantallas ;
//$prueba2 = $this->cuentas_tomadas ;
//$prueba1 = $this->cuentas_creadas->count() * $this->servicio_t->pantallas ;
//$prueba2 = $this->cuentas_tomadas ;
//dd($prueba1, $prueba2 , $prueba1-$prueba2);
//dd($prueba1, $prueba2 , $prueba1-$prueba2);
$this->servicio_id = $this->servicio_t->id;
$this->tarifa_id = $id;
@@ -179,8 +179,6 @@ class ShowServicios extends Component
$this->tarjetaPlan = true;
}
public function paquetesDisponibles()
{
@@ -193,7 +191,6 @@ class ShowServicios extends Component
if ($restantes_completas <= 10) {
//$this->notificacionPocas($this->servicio_t,$restantes_completas);
}
} else {
$cantidad_solicitada = (int) $this->cantidad_tarjetaPlan * (int) $this->pantallas_tarjetaPlan;
@@ -210,7 +207,6 @@ class ShowServicios extends Component
if ($restantes <= 10) {
//$this->notificacionPocas($this->servicio_t,$restantes);
}
}
}
@@ -226,7 +222,6 @@ class ShowServicios extends Component
];
Notification::send($user, (new licencias($notificacion)));
}
/* ---------------- Btn Comprar ---------------- */
@@ -265,7 +260,10 @@ class ShowServicios extends Component
$historial->nombre_cliente = $this->nombre_tarjetaPlan;
$historial->save();
$pantallas = Tarifas::where('id', $this->tarifa_id)->with('servicio')->first();
$servicioNombre = $pantallas->servicio->nombre;
$servicio_id = $pantallas->servicio_id;
$pantalla_servicio_completa = $pantallas->servicio->completa;
$pantalla_servicio = $pantallas->servicio->pantallas;
@@ -276,7 +274,6 @@ class ShowServicios extends Component
$suma = $pantalla_servicio - $cantidad_solicitada;
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)->whereDate('inicio', '>=', $this->fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', $suma)->get();
} elseif ((int) $pantalla_servicio_completa == (int) $this->pantallas_tarjetaPlan) {
//Cuentas completas
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
@@ -287,7 +284,6 @@ class ShowServicios extends Component
$suma2 = $pantalla_servicio - $pantallas;
$cantidad_necesaria = $this->cantidad_tarjetaPlan;
$cuenta = Cuentas::where('servicio_id', $this->servicio_id)->whereDate('inicio', '>=', $this->fecha)->Orderby('created_at', 'ASC')->withCount('historiales')->where('estado', 'activo')->having('historiales_count', '<=', $suma2)->get();
} else {
$cuenta = null;
$cantidad_necesaria = null;
@@ -296,7 +292,9 @@ class ShowServicios extends Component
for ($h = 0; $h < (int) $cantidad_necesaria; $h++) {
//dd($h);
if (!empty($cuenta)) {
$cuentasMostar = '';
$perfil = $cuenta[$h]->historiales_count;
for ($y = 0; $y < (int) $pantallas; $y++) {
@@ -307,14 +305,15 @@ class ShowServicios extends Component
$historial_cuenta->perfil = (int) $perfil + (int) $y + 1;
$historial_cuenta->save();
if ($cuenta[$h]->correo != $cuentasMostar) {
$cuentasMostar .= $cuenta[$h]->correo . ' ';
}
}
} else {
$this->alert('warning', 'No hay cuentas disponibles!', [
'position' => 'top'
]);
}
}
//dd($historial->cuentas);
$descuento = Saldo::where('usuario_id', Auth::user()->id)->first();
@@ -326,6 +325,11 @@ class ShowServicios extends Component
if ($cobro) {
$historial->update(['estado' => 'activo']);
$logsGeneral = new Log_general();
$logsGeneral->user_id = Auth::user()->id;
$logsGeneral->detalle = 'El usuario ' . Auth::user()->name . ' - ' . Auth::user()->email . ' ha comprado el servicio ' . $servicioNombre . ' - ' . $cuentasMostar . ' cantidad de ' . $this->cantidad_tarjetaPlan . ' por un valor de $' . $total_valor;
$logsGeneral->save();
$this->credenciales($historial);
} else {
$this->alert('warning', 'Error en el cobro, comuniquese con soporte!', [
@@ -336,7 +340,6 @@ class ShowServicios extends Component
$this->tarjetaPlan = false;
$this->cantidad_tarjetaPlan = 1;
}
public function credenciales($historial)
@@ -375,7 +378,6 @@ class ShowServicios extends Component
$recipients = '+57' . $this->celular_tarjetaPlan;
$this->sendMessage($message, $recipients);
}
public function sendMessage($message, $recipients)
@@ -385,21 +387,23 @@ class ShowServicios extends Component
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.labsmobile.com/json/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"message":"' . $message . '", "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . $auth_basic,
"Cache-Control: no-cache",
"Content-Type: application/json"
),
)
curl_setopt_array(
$curl,
array(
CURLOPT_URL => "https://api.labsmobile.com/json/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"message":"' . $message . '", "tpoa":"Sender","recipient":[{"msisdn":"' . $recipients . '"}]}',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic " . $auth_basic,
"Cache-Control: no-cache",
"Content-Type: application/json"
),
)
);
$response = curl_exec($curl);
@@ -412,7 +416,6 @@ class ShowServicios extends Component
$this->alert('warning', 'Error enviando SMS!' . $err, [
'position' => 'top'
]);
} else {
if (!empty(json_decode($response)->subid)) {
$this->alert('success', 'Credenciales enviadas por Email y SMS! ' . json_decode($response)->subid, [
@@ -423,15 +426,12 @@ class ShowServicios extends Component
'position' => 'top'
]);
}
}
}
public function consultaTarifa($servicio1)
{
$this->servicio = $servicio1;
$this->verServ = false;
}
}
}