'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; } }