773 lines
27 KiB
PHP
Executable File
773 lines
27 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Configuracione;
|
|
use App\Models\Cuentas;
|
|
use App\Models\Historial_cuenta;
|
|
use App\Models\Historiale;
|
|
use App\Models\Log_general;
|
|
use App\Notifications\Vencimiento;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use App\Models\Promociones;
|
|
use App\Models\recarga;
|
|
use App\Models\RegistroCompra;
|
|
use App\Models\Role;
|
|
use App\Models\Saldo;
|
|
use App\Models\slider;
|
|
use App\Models\Tarifas;
|
|
use App\Models\User;
|
|
use App\Notifications\compra;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Exception;
|
|
use Twilio\Rest\Client;
|
|
use AshAllenDesign\ShortURL\Facades\ShortURL;
|
|
|
|
|
|
class MenuController extends Controller
|
|
{
|
|
public function showwelcome()
|
|
{
|
|
$consulta_promociones = slider::get();
|
|
return view('welcome', [
|
|
'promociones' => $consulta_promociones,
|
|
]);
|
|
}
|
|
public function showtarifas()
|
|
{
|
|
return view('menu/tarifas');
|
|
}
|
|
public function showclientes()
|
|
{
|
|
return view('menu/clientes');
|
|
}
|
|
public function showservicios()
|
|
{
|
|
return view('menu/servicios');
|
|
}
|
|
public function showtop()
|
|
{
|
|
return view('menu/top');
|
|
}
|
|
public function showreportes()
|
|
{
|
|
return view('menu/reportes');
|
|
}
|
|
public function showperfil()
|
|
{
|
|
return view('menu/perfil');
|
|
}
|
|
public function showpendientes()
|
|
{
|
|
return view('menu/pendientes');
|
|
}
|
|
public function showconfiguracion()
|
|
{
|
|
return view('menu/configuracion');
|
|
}
|
|
public function showplanes()
|
|
{
|
|
return view('menu/planes');
|
|
}
|
|
|
|
public function showusuarios()
|
|
{
|
|
return view('menu/usuarios');
|
|
}
|
|
|
|
public function showadmin()
|
|
{
|
|
return view('menu/admin');
|
|
}
|
|
|
|
public function showrecarga()
|
|
{
|
|
return view('menu/recarga');
|
|
}
|
|
|
|
public function showcomprar()
|
|
{
|
|
return view('menu/comprar');
|
|
}
|
|
|
|
public function showLogRecargas()
|
|
{
|
|
return view('menu/logs_recargas');
|
|
}
|
|
public function showLogGeneral()
|
|
{
|
|
return view('menu/log_general');
|
|
}
|
|
public function showLogHistorial()
|
|
{
|
|
return view('menu/log_historial');
|
|
}
|
|
|
|
public function showroles()
|
|
{
|
|
return view('menu/roles');
|
|
}
|
|
|
|
public function mantenimiento()
|
|
{
|
|
return view('menu/mantenimiento');
|
|
}
|
|
|
|
public function pay($estado)
|
|
{
|
|
return view('menu/order', [
|
|
'estado' => $estado,
|
|
]);
|
|
}
|
|
|
|
|
|
|
|
public function showcredenciales(Request $request)
|
|
{
|
|
|
|
$credencial = Crypt::decryptString($request->id);
|
|
$consulta_historiales = Historiale::where('id', $credencial)->with('cuentas')->first();
|
|
$msj = Configuracione::orderby('id', 'desc')->select('msj_compra', 'msj_wp', 'clave_1', 'clave_2', 'clave_3', 'clave_4', 'clave_5', 'clave_6', 'iptv')->first();
|
|
|
|
return view('menu/credenciales', [
|
|
'consulta' => $consulta_historiales,
|
|
'msj' => $msj,
|
|
]);
|
|
}
|
|
|
|
|
|
public function order(Request $request)
|
|
{
|
|
|
|
$payment_id = $request->get('payment_id');
|
|
$response = Http::get("https://api.mercadopago.com/v1/payments/$payment_id" . "?access_token=APP_USR-7353579040069171-102716-58fdd1f52a604a1febd18a638227f603-260361439");
|
|
$response = json_decode($response);
|
|
|
|
$status = $response->status;
|
|
if ($status == 'approved') {
|
|
|
|
$metodo_pago = $response->payment_method_id;
|
|
$referencia = $response->external_reference;
|
|
$consulta = recarga::where('reference', $referencia)->where('status', $status)->exists();
|
|
if ($consulta == false) {
|
|
$update_recargas = recarga::where('reference', $referencia)->update(['status' => $status, 'payment_method_id' => $metodo_pago]);
|
|
$recarga = recarga::where('reference', $referencia)->with('usuario')->first();
|
|
$usuario = $recarga->usuario;
|
|
|
|
$saldo = $usuario->saldo;
|
|
$saldo_anterior = $saldo->valor;
|
|
$rol = $usuario->rol->nombre;
|
|
$monto = $recarga->valor_recarga;
|
|
|
|
if (!empty($saldo_anterior)) {
|
|
|
|
$valor = (float)$saldo_anterior + (float)$monto;
|
|
$nuevo_saldo = $saldo->update(['valor' => $valor]);
|
|
} else {
|
|
$nuevo_saldo = $saldo->update(['valor' => $monto]);
|
|
}
|
|
|
|
$consulta_recarga = recarga::where('reference', $referencia)->where('status', $status)->first();
|
|
|
|
$usuario_a_recargar = User::find($consulta_recarga->usuario_id);
|
|
$nombre = $usuario_a_recargar->name;
|
|
$email = $usuario_a_recargar->email;
|
|
|
|
$logsGeneral = new Log_general();
|
|
$logsGeneral->user_id = $consulta_recarga->usuario_id;
|
|
$logsGeneral->detalle = 'El usuario ' . $nombre . ' - ' . $email . 'ha recargador por MP el monto de ' . $monto . ', Nuevo saldo disponible: $' . $nuevo_saldo;
|
|
$logsGeneral->tipo = 'recarga';
|
|
$logsGeneral->historial_id = null;
|
|
$logsGeneral->save();
|
|
}
|
|
$estado = 'aprobado';
|
|
} elseif ($status == 'pending') {
|
|
|
|
|
|
$metodo_pago = $response->payment_method_id;
|
|
$referencia = $response->external_reference;
|
|
$update_recargas = recarga::where('reference', $referencia)->update(['status' => $status, 'payment_method_id' => $metodo_pago]);
|
|
$usuario = recarga::where('reference', $referencia)->with('usuario')->first()->usuario;
|
|
|
|
$estado = 'pendiente';
|
|
} else {
|
|
|
|
|
|
$metodo_pago = $response->payment_method_id;
|
|
$referencia = $response->external_reference;
|
|
$update_recargas = recarga::where('reference', $referencia)->update(['status' => $status, 'payment_method_id' => $metodo_pago]);
|
|
$usuario = recarga::where('reference', $referencia)->with('usuario')->first()->usuario;
|
|
|
|
$estado = 'rechazado';
|
|
};
|
|
|
|
|
|
return redirect()->route('pay', $estado);
|
|
}
|
|
|
|
|
|
public function showwebhooks(Request $request) {}
|
|
|
|
public function recargas()
|
|
{
|
|
return view('menu/recargas');
|
|
}
|
|
|
|
public function showutilidad()
|
|
{
|
|
return view('menu/utilidades');
|
|
}
|
|
|
|
public function showwompi($monto)
|
|
{
|
|
return view('menu/wompi', [
|
|
'monto' => $monto,
|
|
]);
|
|
}
|
|
|
|
|
|
public function showoferta()
|
|
{
|
|
return view('portadaservicio');
|
|
}
|
|
|
|
|
|
public function showsingle()
|
|
{
|
|
return view('menu/single');
|
|
}
|
|
|
|
|
|
public function showpromo()
|
|
{
|
|
return view('menu/promo');
|
|
}
|
|
|
|
|
|
public function showlogs()
|
|
{
|
|
return view('menu/logs');
|
|
}
|
|
|
|
|
|
public function showpromociones()
|
|
{
|
|
return view('menu/promociones');
|
|
}
|
|
|
|
public function showimport()
|
|
{
|
|
return view('menu/importar');
|
|
}
|
|
|
|
public function showcategoria()
|
|
{
|
|
return view('menu/categoria');
|
|
}
|
|
|
|
public function showcategorias()
|
|
{
|
|
return view('menu/ver');
|
|
}
|
|
|
|
public function showservicio()
|
|
{
|
|
return view('menu/servicio');
|
|
}
|
|
public function compras(Request $request)
|
|
{
|
|
|
|
$payment_id = $request->get('payment_id');
|
|
$response = Http::get("https://api.mercadopago.com/v1/payments/$payment_id" . "?access_token=APP_USR-7353579040069171-102716-58fdd1f52a604a1febd18a638227f603-260361439");
|
|
$response = json_decode($response);
|
|
|
|
|
|
$status = $response->status;
|
|
if ($status == 'approved') {
|
|
|
|
foreach ($response->additional_info->items as $item) {
|
|
$consulta = Historiale::where('id', $item->id)->first();
|
|
$tarifa_id = $consulta->tarifa_id;
|
|
}
|
|
$date = Carbon::now()->subDay(30);
|
|
$fecha = $date->format('Y-m-d');
|
|
|
|
//SERVICIO//
|
|
if (!empty($consulta->tarifa_id)) {
|
|
|
|
$pantallas = Tarifas::where('id', $tarifa_id)->with('servicio')->first();
|
|
$servicio_id = $pantallas->servicio_id;
|
|
$pantalla_servicio = $pantallas->servicio->pantallas;
|
|
$pantalla_servicio_completa = $pantallas->servicio->completa;
|
|
|
|
|
|
|
|
$pantallas = $pantallas->pantallas ?? null;
|
|
$cantidad_tarjetaPlan = $consulta->cantidad;
|
|
|
|
$cantidad_solicitada = (int)$cantidad_tarjetaPlan * (int)$pantallas;
|
|
//dd($cantidad_tarjetaPlan);
|
|
if ((int)$pantalla_servicio_completa >= (int)$cantidad_solicitada) {
|
|
$suma = $pantalla_servicio - $cantidad_solicitada;
|
|
$cuenta = Cuentas::where('servicio_id', $servicio_id)
|
|
->whereDate('inicio', '>=', $fecha)
|
|
->where('estado', 'activo')
|
|
->orderBy('created_at', 'ASC')
|
|
->withCount('historiales') // Contar los historiales
|
|
->first();
|
|
|
|
if ($cuenta && $cuenta->historiales_count <= $suma) {
|
|
// La cuenta cumple con el filtro de cantidad de historiales.
|
|
} else {
|
|
// La cuenta no cumple con el filtro (tiene más historiales de los permitidos o no existe).
|
|
$cuenta = null;
|
|
}
|
|
} elseif ((int)$pantalla_servicio_completa == (int)$cantidad_solicitada) {
|
|
$this->fecha_final_1 = $today = Carbon::now()->addDays($pantallas->dias - 15);
|
|
$this->fecha_final_2 = $today = Carbon::now()->addDays($pantallas->dias + 15);
|
|
//completas
|
|
$cuentas = Cuentas::where('servicio_id', $this->servicio_id)
|
|
->whereDate('inicio', '>=', $this->fecha)
|
|
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
|
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
|
->orderBy('created_at', 'ASC')
|
|
->withCount('historiales') // Contar los historiales
|
|
->where('estado', 'pendiente') // Filtrar por estado pendiente
|
|
->get(); // Obtener todas las cuentas que coincidan con los filtros
|
|
|
|
$cuenta = $cuentas->first(function ($cuenta) {
|
|
return $cuenta->historiales_count == 0; // Filtrar solo cuentas que no tengan historiales
|
|
});
|
|
} else {
|
|
$cuenta = null;
|
|
}
|
|
|
|
|
|
if (!empty($cuenta)) {
|
|
|
|
$perfil = $cuenta->historiales_count;
|
|
for ($n = 1; $n <= $cantidad_solicitada; $n++) {
|
|
|
|
$historial_cuenta = new Historial_cuenta();
|
|
$historial_cuenta->cuenta_id = $cuenta->id;
|
|
$historial_cuenta->historial_id = $item->id;
|
|
$historial_cuenta->perfil = (int)$perfil + (int)$n;
|
|
$historial_cuenta->save();
|
|
//dd($historial_cuenta->id);
|
|
}
|
|
|
|
if (($n - 1) == $cantidad_solicitada) {
|
|
|
|
$consulta->update(['estado' => 'activo']);
|
|
$this->cred($consulta);
|
|
$encryptado = Crypt::encryptString($consulta->id);
|
|
//dd('llegue');
|
|
return redirect('/credenciales?id=' . $encryptado);
|
|
} else {
|
|
|
|
return 'Error en la asignacion de cuentas, comuniquese con soporte!';
|
|
}
|
|
} else {
|
|
//dd($cuenta);
|
|
$suma2 = $pantalla_servicio - $pantallas;
|
|
|
|
|
|
for ($h = 0; $h < (int)$cantidad_tarjetaPlan; $h++) {
|
|
//dd($n);
|
|
$cuentas = Cuentas::where('servicio_id', $servicio_id)
|
|
->whereDate('inicio', '>=', $fecha)
|
|
->orderBy('created_at', 'ASC')
|
|
->with('historiales') // Obtener los historiales relacionados
|
|
->withCount('historiales') // Contar los historiales asociados
|
|
->where('estado', 'activo') // Filtrar por estado 'activo'
|
|
->get(); // Obtener todas las cuentas que coincidan con los filtros
|
|
$cuenta = $cuentas->first(function ($cuenta) use ($suma2) {
|
|
return $cuenta->historiales_count <= (int)$suma2; // Filtrar por el número de historiales
|
|
});
|
|
|
|
//dd($cuenta);
|
|
if (!empty($cuenta)) {
|
|
$perfil = $cuenta->historiales_count;
|
|
for ($y = 0; $y < (int)$pantallas; $y++) {
|
|
//dd($pantallas);
|
|
$historial_cuenta = new Historial_cuenta;
|
|
$historial_cuenta->cuenta_id = $cuenta->id;
|
|
$historial_cuenta->historial_id = $item->id;
|
|
$historial_cuenta->perfil = (int)$perfil + (int)$y + 1;
|
|
$historial_cuenta->save();
|
|
}
|
|
} else {
|
|
return 'No hay cuentas disponibles, comuniquese con soporte!';
|
|
}
|
|
}
|
|
|
|
|
|
$consulta->update(['estado' => 'activo']);
|
|
$this->cred($consulta);
|
|
$encryptado = Crypt::encryptString($consulta->id);
|
|
return redirect('/credenciales?id=' . $encryptado);
|
|
}
|
|
}
|
|
|
|
//PROMOCION
|
|
if (!empty($consulta->promocion_id)) {
|
|
|
|
for ($p = 0; $p < (int)$consulta->cantidad; $p++) {
|
|
//dd($this->cantidad_comprarPromo);
|
|
foreach ($consulta->promocion->tarifas as $tarifa) {
|
|
|
|
$pantallas_tarifa = $tarifa->pantallas;
|
|
$servicio_id = $tarifa->servicio_id;
|
|
$pantalla_servicio = $tarifa->servicio->pantallas;
|
|
$pantalla_servicio_completa = $tarifa->servicio->completa;
|
|
|
|
$faltante = $pantalla_servicio - $pantallas_tarifa;
|
|
if ($pantalla_servicio_completa == $pantallas_tarifa) {
|
|
$this->fecha_final_1 = $today = Carbon::now()->addDays($tarifa->dias - 15);
|
|
$this->fecha_final_2 = $today = Carbon::now()->addDays($tarifa->dias + 15);
|
|
$cuentas = Cuentas::where('servicio_id', $servicio_id)
|
|
->whereDate('inicio', '>=', $fecha)
|
|
->whereDate('vencimiento', '>=', $this->fecha_final_1)
|
|
->whereDate('vencimiento', '<=', $this->fecha_final_2)
|
|
->orderBy('created_at', 'ASC')
|
|
->with('historiales') // Relación con los historiales
|
|
->withCount('historiales') // Contar los historiales
|
|
->where('estado', 'pendiente') // Filtrar por estado 'pendiente'
|
|
->get(); // Obtener todas las cuentas que coincidan con los filtros
|
|
|
|
$cuenta = $cuentas->first(function ($cuenta) {
|
|
return $cuenta->historiales_count == 0; // Filtrar solo cuentas que no tengan historiales
|
|
});
|
|
} else {
|
|
$cuentas = Cuentas::where('servicio_id', $servicio_id)
|
|
->whereDate('inicio', '>=', $fecha)
|
|
->orderBy('created_at', 'ASC')
|
|
->with('historiales') // Relación con los historiales
|
|
->withCount('historiales') // Contar los historiales asociados
|
|
->where('estado', 'activo') // Filtrar por el estado 'activo'
|
|
->get(); // Obtener todas las cuentas que cumplan con los filtros
|
|
|
|
$cuenta = $cuentas->first(function ($cuenta) use ($faltante) {
|
|
return $cuenta->historiales_count <= (int) $faltante;
|
|
});
|
|
}
|
|
//dd($tarifa);
|
|
|
|
|
|
if (!empty($cuenta)) {
|
|
$perfil = $cuenta->historiales_count;
|
|
for ($y = 0; $y < (int)$pantallas_tarifa; $y++) {
|
|
|
|
$historial_cuenta = new Historial_cuenta();
|
|
$historial_cuenta->cuenta_id = $cuenta->id;
|
|
$historial_cuenta->historial_id = $item->id;
|
|
$historial_cuenta->perfil = (int)$perfil + (int)$y + 1;
|
|
$historial_cuenta->save();
|
|
}
|
|
} else {
|
|
|
|
return 'No hay cuentas disponibles, comuniquese con soporte!';
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($y)) {
|
|
|
|
$consulta->update(['estado' => 'activo']);
|
|
$this->cred($consulta);
|
|
$encryptado = Crypt::encryptString($consulta->id);
|
|
//dd('llegue');
|
|
return redirect('/credenciales?id=' . $encryptado);
|
|
} else {
|
|
return 'No hay cuentas disponibles, comuniquese con soporte!';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//wompi
|
|
|
|
public function wompi_pagos(Request $request)
|
|
{
|
|
|
|
$response = Http::get("https://sandbox.wompi.co/v1/transactions/136099-1677473887-65588");
|
|
$response = json_decode($response);
|
|
//dd($response);
|
|
|
|
}
|
|
|
|
public function wompi_hook(Request $request)
|
|
{
|
|
//return json_encode('hola');
|
|
|
|
if (!empty($request)) {
|
|
|
|
|
|
|
|
foreach ($request->data as $item) {
|
|
//return $item;
|
|
$status = $item['status'];
|
|
$user_id = $item['reference'];
|
|
$monto = substr($item['amount_in_cents'], 0, -2);
|
|
$metodo_pago = $item['payment_method_type'];
|
|
}
|
|
|
|
$update_recargas = recarga::where('reference', $referencia)->update(['status' => $status, 'payment_method_id' => $metodo_pago]);
|
|
if ($status == 'APPROVED') {
|
|
|
|
$usuario = recarga::where('reference', $referencia)->with('usuario')->first()->usuario;
|
|
$saldo = $usuario->saldo;
|
|
$saldo_anterior = $saldo->valor;
|
|
$rol = $usuario->rol->nombre;
|
|
//return $rol;
|
|
$monto_adicional = 0;
|
|
if ($rol == "super" || $rol == "administrador" || $rol == "distribuidor") {
|
|
$monto_adicional = 500;
|
|
}
|
|
|
|
|
|
if (!empty($saldo_anterior)) {
|
|
|
|
$valor = (float)$saldo_anterior + (float)$monto - (float)$monto_adicional;
|
|
$nuevo_saldo = $saldo->update(['valor' => $valor]);
|
|
|
|
// return $nuevo_saldo;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function cred($consulta)
|
|
{
|
|
|
|
|
|
$encryptado = Crypt::encryptString($consulta->id);
|
|
|
|
$enlace = '/credenciales?id=' . $encryptado;
|
|
|
|
$user = User::find($consulta->cliente);
|
|
if (!empty($consulta->promocion_id)) { {
|
|
|
|
$shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co' . $enlace)->make();
|
|
$shortURL = $shortURLObject->default_short_url;
|
|
$message = $consulta->promocion->nombre . '. Ver credenciales: ' . $shortURL;
|
|
$recipients = '+57' . $consulta->cliente->celular;
|
|
|
|
$this->sendMessage($message, $recipients);
|
|
|
|
$notificacion = [
|
|
'enlace' => $enlace,
|
|
'fecha_final' => $consulta->fecha_final,
|
|
'cliente' => $consulta->cliente->name,
|
|
'servicio' => $consulta->promocion->nombre,
|
|
'tipo' => 'compra',
|
|
'vendedor' => Role::where('nombre', 'super')->first()->usuarios->first()->name,
|
|
|
|
];
|
|
}
|
|
|
|
if (!empty($consulta->tarifa_id)) {
|
|
|
|
$shortURLObject = ShortURL::destinationUrl('https://app.sirpremium.com.co' . $enlace)->make();
|
|
$shortURL = $shortURLObject->default_short_url;
|
|
$message = $consulta->tarifa->servicio->nombre . '-' . $consulta->tarifa->pantallas . 'P. Ver credenciales: ' . $shortURL;
|
|
$recipients = '+57' . $consulta->cliente->celular;
|
|
|
|
$this->sendMessage($message, $recipients);
|
|
|
|
|
|
$notificacion = [
|
|
'enlace' => $enlace,
|
|
'fecha_final' => $consulta->fecha_final,
|
|
'cliente' => $consulta->cliente->name,
|
|
'servicio' => $consulta->tarifa->servicio->nombre . '-' . $consulta->tarifa->pantallas . 'pantallas',
|
|
'tipo' => 'compra',
|
|
'vendedor' => Role::where('nombre', 'super')->first()->usuarios->first()->name,
|
|
|
|
];
|
|
}
|
|
|
|
|
|
Notification::send($user, new compra($notificacion));
|
|
}
|
|
}
|
|
|
|
public function sendMessage($message, $recipients)
|
|
{
|
|
|
|
|
|
$auth_basic = base64_encode(getenv("USER_LABSMOBILE") . ':' . getenv("PASS_LABSMOBILE"));
|
|
|
|
$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"
|
|
),
|
|
));
|
|
|
|
$response = curl_exec($curl);
|
|
$err = curl_error($curl);
|
|
|
|
curl_close($curl);
|
|
|
|
if ($err) {
|
|
} else {
|
|
}
|
|
}
|
|
public function showmp(Request $request)
|
|
{
|
|
|
|
Log::info('MercadoPago webhook received', $request->all());
|
|
|
|
// Aquí puedes agregar la lógica para manejar las notificaciones de MercadoPago
|
|
$data = json_decode($request->getContent(), true);
|
|
$paymentId = $data['data']['id'];
|
|
|
|
$response = Http::get("https://api.mercadopago.com/v1/payments/$paymentId" . "?access_token=APP_USR-7353579040069171-102716-58fdd1f52a604a1febd18a638227f603-260361439");
|
|
//return $response;
|
|
$response = json_decode($response);
|
|
$status = $response->status;
|
|
|
|
if ($status == 'approved') {
|
|
$metodo_pago = $response->payment_method_id;
|
|
$referencia = $response->external_reference;
|
|
$consulta = recarga::where('reference', $referencia)->where('status', $status)->exists();
|
|
if ($consulta == false) {
|
|
$update_recargas = recarga::where('reference', $referencia)->update(['status' => $status, 'payment_method_id' => $metodo_pago]);
|
|
$recarga = recarga::where('reference', $referencia)->with('usuario')->first();
|
|
$usuario = $recarga->usuario;
|
|
|
|
$saldo = $usuario->saldo;
|
|
$saldo_anterior = $saldo->valor;
|
|
$monto = $recarga->valor_recarga;
|
|
|
|
$valor = (float)$saldo_anterior + (float)$monto;
|
|
$nuevo_saldo = $saldo->update(['valor' => $valor]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return response()->json(['status' => 'ok']);
|
|
}
|
|
|
|
public function pruebas()
|
|
{
|
|
$fechaHoy = Carbon::now()->format('Y-m-d');
|
|
|
|
$consulta_historial = Historiale::whereDate('fecha_final', $fechaHoy)->with('cliente')->get();
|
|
|
|
foreach ($consulta_historial as $item) {
|
|
|
|
$user = User::find($item->cliente->id);
|
|
|
|
if (!empty($item->promocion_id)) {
|
|
|
|
$nombre = $item->promocion->nombre;
|
|
}
|
|
if (!empty($item->tarifa_id)) {
|
|
$nombre = $item->tarifa->servicio->nombre . '-' . $item->tarifa->pantallas . 'P';
|
|
}
|
|
|
|
$notificacion = [
|
|
//'valor' => $value['precio'],
|
|
'fecha_final' => $item->fecha_final,
|
|
'cliente' => $item->cliente->name,
|
|
'servicio' => $nombre,
|
|
'tipo' => 'vencimiento',
|
|
'vendedor' => $item->vendedor->name,
|
|
|
|
];
|
|
|
|
Notification::sendNow($user, new Vencimiento($notificacion));
|
|
|
|
// $fecha=Carbon::parse($item->fecha_final)->format('d/m/Y');
|
|
|
|
//$message = 'Su '.$nombre.', Vence Hoy, '.$fecha.'. Renueva ahora!!' ;
|
|
//$recipients= '+57'.$item->cliente->celular;
|
|
|
|
//$auth_basic = base64_encode('admin@jaguarws.ga:9u3xxXhHt8maeiOexg07pFKI0rpYazI0');
|
|
|
|
//$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"
|
|
//),
|
|
//));
|
|
|
|
//$response = curl_exec($curl);
|
|
//$err = curl_error($curl);
|
|
|
|
//curl_close($curl);
|
|
//return $response;
|
|
//if ($err) {
|
|
|
|
|
|
//} else {
|
|
|
|
//}
|
|
|
|
|
|
}
|
|
|
|
$fechaHoy1 = Carbon::now();
|
|
$fechaHoy1 = Carbon::parse($fechaHoy1)->subDay(1);
|
|
|
|
$consulta_historial1 = Historiale::whereDate('fecha_final', '<', $fechaHoy1)->with('cliente', 'cuentas')->get();
|
|
foreach ($consulta_historial1 as $item1) {
|
|
|
|
foreach ($item1->cuentas->unique() as $item2) {
|
|
//dd($item2);
|
|
$logs = new log;
|
|
$logs->historial_id = $item1->id;
|
|
$logs->cuenta_id = $item2->id;
|
|
$logs->save();
|
|
}
|
|
//$eliminar_cuentas = Historial_cuenta::where('historial_id',$item1->id)->truncate();
|
|
//dd('termine');
|
|
|
|
}
|
|
}
|
|
|
|
public function click_compra(Request $request)
|
|
{
|
|
// Aquí puedes guardar, registrar o procesar la info
|
|
RegistroCompra::create([
|
|
'user_id' => auth()->id(),
|
|
'nombre' => $request->nombre,
|
|
'email' => $request->email,
|
|
'saldo' => $request->saldo,
|
|
]);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|