Initial commit
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\Categoria;
|
||||
use App\Models\Cuentas;
|
||||
use App\Models\Historial_cuenta;
|
||||
use App\Models\Historiale;
|
||||
use App\Models\Promocion_tarifa;
|
||||
use App\Models\Promociones;
|
||||
use App\Models\Role;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\Servicio;
|
||||
use App\Models\Tarifas;
|
||||
use App\Models\User;
|
||||
use App\Notifications\compra;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Jantinnerezo\LivewireAlert\LivewireAlert;
|
||||
use Livewire\Component;
|
||||
|
||||
class PortadaServicio extends Component
|
||||
{
|
||||
|
||||
use LivewireAlert;
|
||||
|
||||
public $categoria_id;
|
||||
|
||||
public $nombre_promocion;
|
||||
public $descripcion_promocion;
|
||||
public $valor_promocion;
|
||||
public $estado_promocion;
|
||||
public $fecha_limite_promocion;
|
||||
public $categoria_id_promocion;
|
||||
|
||||
public $fechaFinal;
|
||||
|
||||
public $tarifa_id_promocion;
|
||||
public $dias_comprarPromo;
|
||||
public $valor_comprarPromo;
|
||||
public $nombre_comprarPromo;
|
||||
public $celular_comprarPromo;
|
||||
public $email_comprarPromo;
|
||||
public $cantidad_comprarPromo = 1;
|
||||
|
||||
public $newCategoria = false;
|
||||
public $nombre_categoria;
|
||||
public $descripcion_categoria;
|
||||
|
||||
public $modalComprarPromo = false;
|
||||
|
||||
public $verPromo = false;
|
||||
public $precioAntes;
|
||||
public $precioAhora;
|
||||
public $fechaLimite;
|
||||
public $nombrePromo;
|
||||
public $descripcionPromo;
|
||||
|
||||
public $editarPromo = false;
|
||||
public $nombre_editarPromo;
|
||||
public $descripcion_editarPromo;
|
||||
public $valor_editarPromo;
|
||||
public $estado_editarPromo;
|
||||
public $fecha_limite_editarPromo;
|
||||
public $categoria_id_editarPromo;
|
||||
public $editar_promo_id;
|
||||
public $imagen;
|
||||
public $dias;
|
||||
public $total;
|
||||
public $consulta;
|
||||
public $fechaHoy;
|
||||
public $fechafinal;
|
||||
public $fecha;
|
||||
public $credenciales;
|
||||
public $cuentas;
|
||||
|
||||
|
||||
protected $rules = [
|
||||
'nombre_comprarPromo' => 'required',
|
||||
'celular_comprarPromo' => 'required',
|
||||
'email_comprarPromo' => 'required',
|
||||
'cantidad_comprarPromo' => 'required',
|
||||
];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$date = Carbon::now()->subDay(8);
|
||||
$this->fecha= $date->format('Y-m-d');
|
||||
|
||||
$this->fechaActual = Carbon::now();
|
||||
$this->fechaActual = Carbon::parse($this->fechaActual);
|
||||
|
||||
$this->fechaHoy = Carbon::now();
|
||||
$this->fechaHoy = $this->fechaHoy->format('d/m/Y');
|
||||
|
||||
$consulta_promociones = Promociones::with('tarifas')->where('visible', 'true');
|
||||
if (!is_null($this->categoria_id)) {
|
||||
$consulta_promociones = $consulta_promociones->where('categoria_id', 'LIKE', '%' . $this->categoria_id . '%');
|
||||
}
|
||||
//dd($consulta_promociones->get());
|
||||
$consulta_promociones = $consulta_promociones->get();
|
||||
|
||||
return view('livewire.portada-servicio',[
|
||||
'promociones' => $consulta_promociones,
|
||||
'categorias' => Categoria::get(),
|
||||
'tarifas' => Tarifas::with('servicio')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function verPromocion($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
|
||||
$this->verPromo = true;
|
||||
}
|
||||
|
||||
public function comprarPromo($id)
|
||||
{
|
||||
$consulta_verpromocion = Promociones::with('tarifas')->where('id', $id)->first();
|
||||
|
||||
$this->consulta = $consulta_verpromocion;
|
||||
$this->precioAntes = $consulta_verpromocion->tarifas->first()->valor;
|
||||
|
||||
$this->precioAhora = $consulta_verpromocion->precio;
|
||||
$this->imagen = $consulta_verpromocion->img_publicidad;
|
||||
$this->fechaLimite = $consulta_verpromocion->fecha_limite;
|
||||
$this->nombrePromo = $consulta_verpromocion->nombre;
|
||||
$this->dias = $consulta_verpromocion->dias;
|
||||
$this->descripcionPromo = $consulta_verpromocion->descripcion;
|
||||
$this->fechaFinal = $this->fechaActual->addDay($this->dias);
|
||||
|
||||
|
||||
$this->modalComprarPromo = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* ---------------- Btn Comprar ---------------- */
|
||||
|
||||
|
||||
public function pagar()
|
||||
{
|
||||
|
||||
$this->validate();
|
||||
|
||||
|
||||
$usuario_existe = User::firstWhere('email', $this->email_comprarPromo)->id ?? null;
|
||||
|
||||
if (is_null($usuario_existe)) {
|
||||
$usuario = new User;
|
||||
$usuario->name = $this->nombre_tarjetaPlan;
|
||||
$usuario->email = $this->email_tarjetaPlan;
|
||||
$usuario->password = '123';
|
||||
$usuario->celular = $this->celular_tarjetaPlan;
|
||||
$usuario->save();
|
||||
|
||||
$usuario_id = $usuario->id;
|
||||
} else {
|
||||
|
||||
$usuario_id = $usuario_existe;
|
||||
}
|
||||
if (empty(Auth::user())) {
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Role::where('nombre','super')->first()->usuarios->first()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
|
||||
}else{
|
||||
$historial = new Historiale();
|
||||
$historial->fecha_inicio = $this->fechaHoy;
|
||||
$historial->fecha_final = $this->fechaFinal;
|
||||
$historial->valor = $this->precioAhora *$this->cantidad_comprarPromo;
|
||||
$historial->tipo_pago = 'manual';
|
||||
$historial->estado = 'pendiente';
|
||||
$historial->vendedor_id = Auth::user()->id;
|
||||
$historial->promocion_id = $this->consulta->id;
|
||||
$historial->cliente_id = $usuario_id;
|
||||
$historial->cantidad = $this->cantidad_comprarPromo;
|
||||
$historial->save();
|
||||
}
|
||||
|
||||
return redirect('/comprar?monto='.$historial->valor.'&id='.$historial->id);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function limpiarInputPromocion()
|
||||
{
|
||||
$this->nombre_promocion = '';
|
||||
$this->descripcion_promocion = '';
|
||||
$this->valor_promocion = '';
|
||||
$this->estado_promocion = null;
|
||||
$this->fecha_limite_promocion = null;
|
||||
$this->categoria_id_promocion = null;
|
||||
$this->newCategoria = false;
|
||||
$this->newPromocion = false;
|
||||
|
||||
$this->list = null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user