示例#1
0
function insertReserva($idHotel, $data = array(), $data_apartamento = array(), $data_excursiones = array(), $data_usuario = array(), $data_tarjeta = array(), $total = 0)
{
    try {
        $transaction = new Transaction();
        $email = $data_usuario['email'];
        $usuario = getUsuarioByEmail($email);
        if ($usuario && count($usuario)) {
            $usuario_id = $usuario[0]->id;
            $usuario = DAOFactory::getUsuarioDAO()->prepare($data_usuario, $usuario_id);
            DAOFactory::getUsuarioDAO()->update($usuario);
        } else {
            $data_usuario['tiempoCreacion'] = date('Y-m-d');
            $data_usuario['estatus'] = 'Activo';
            $data_usuario['usuarioGrupoId'] = 4;
            $usuario = DAOFactory::getUsuarioDAO()->prepare($data_usuario);
            $usuario_id = DAOFactory::getUsuarioDAO()->insert($usuario);
        }
        $hotel = DAOFactory::getHotelDAO()->load($idHotel);
        $data_reserva = array('hotelId' => $idHotel, 'usuarioId' => $usuario_id, 'tiempoCreacion' => date('Y-m-d'), 'total' => $total, 'peticionesEspeciales' => $data['peticionesEspeciales'], 'urlOrigen' => $data['urlOrigen'], 'monedaId' => $data['monedaId'], 'estado' => $hotel->bookingOnrequest ? 'Pendiente' : 'Aprobada', 'recibirFactura' => $data['recibirFactura'], 'idiomaId' => $data['idiomaId'], 'cartId' => $data['cartId'], 'adultos' => $data['adultos'], 'ninios' => $data['ninios'], 'tipoCobro' => $hotel->tipoReserva);
        if ($data_tarjeta['op'] && strlen(trim($data_tarjeta['op']))) {
            $data_reserva['estado'] = 'Confirmada';
        }
        $stop_sales = DAOFactory::getHotelFechasDAO()->queryInFechas($data_apartamento['inicio'], $data_apartamento['final'], $idHotel);
        if (count($stop_sales)) {
            $data_reserva['estado'] = 'Pendiente';
        }
        $reserva = DAOFactory::getReservaDAO()->prepare($data_reserva);
        $reserva_id = DAOFactory::getReservaDAO()->insert($reserva);
        $localizador = strtoupper(generarLocalizador(5));
        $reserva = DAOFactory::getReservaDAO()->prepare(array('localizador' => $localizador), $reserva_id);
        DAOFactory::getReservaDAO()->update($reserva);
        $data_apartamento['reservaId'] = $reserva_id;
        $apartamento = DAOFactory::getReservaProductoDAO()->prepare($data_apartamento);
        $apartamento_id = DAOFactory::getReservaProductoDAO()->insert($apartamento);
        foreach ($data_excursiones as $data_excursion) {
            $data_excursion['reservaId'] = $reserva_id;
            if ($data_excursion['eventoTpv'] && !is_string($data_excursion['eventoTpv'])) {
                $data_excursion['eventoTpv'] = json_encode($data_excursion['eventoTpv']);
            }
            $excursion = DAOFactory::getReservaProductoDAO()->prepare($data_excursion);
            $excursion_id = DAOFactory::getReservaProductoDAO()->insert($excursion);
        }
        $clave = getClaveByHotel($idHotel);
        $data_tarjeta['reservaId'] = $reserva_id;
        if ($data_tarjeta['tarjetaNumero'] && strlen(trim($data_tarjeta['tarjetaNumero']))) {
            $data_tarjeta['tarjetaNumero'] = Encrypter::encrypt($data_tarjeta['tarjetaNumero'], $clave);
        }
        if ($data_tarjeta['cvv'] && strlen(trim($data_tarjeta['cvv']))) {
            $data_tarjeta['cvv'] = Encrypter::encrypt($data_tarjeta['cvv'], $clave);
        }
        if ($data_tarjeta['importe'] || $hotel->tipoReserva != 'offline') {
            $importe = $data_tarjeta['importe'];
            require 'Logic/afiliado.php';
            insertReservaAfiliado($reserva_id, $importe);
            $pago = DAOFactory::getReservaPagoDAO()->prepare($data_tarjeta);
            $pago_id = DAOFactory::getReservaPagoDAO()->insert($pago);
        }
        $transaction->commit();
        return $reserva_id;
    } catch (Exception $e) {
        var_dump($e);
        $transaction->rollback();
        return false;
    }
}
示例#2
0
function getHotelById($id, $convertirMonedas = true)
{
    try {
        $hotel = DAOFactory::getHotelDAO()->load($id);
        $hotel->direccion = getDireccionByHotel($hotel->id);
        if ($hotel->configuracionId) {
            $configuracion = DAOFactory::getConfiguracionDAO()->load($hotel->configuracionId);
        }
        if ($hotel->configuracionId) {
            $hotel->config = getConfiguracionById($hotel->configuracionId);
        }
        if ($hotel->campaniaId) {
            $hotel->campania = getCampania($hotel->campaniaId);
            if ($hotel->campania->empresaId) {
                $hotel->empresa = getEmpresaById($hotel->campania->empresaId);
            }
            if ($hotel->campania->empresaDistribuidoraId) {
                $hotel->distribuidor = getEmpresaById($hotel->campania->empresaDistribuidoraId);
            }
        }
        $hotel->idiomas = getAllIdiomas();
        $hotel->monedas = getMonedasByHotelId($hotel->id);
        $hotel->condiciones = getCondicionesByHotelId($hotel->id);
        if ($hotel->nombre && strlen(trim($hotel->nombre)) > 2 && $hotel->nombre[0] == '{' && $hotel->nombre[strlen($hotel->nombre) - 1] == '}') {
            $hotel->nombre = json_decode(trim($hotel->nombre))->es;
        }
        if ($hotel->descripcionCorta && strlen(trim($hotel->descripcionCorta)) > 0) {
            $hotel->descripcionesCortas = json_decode(trim($hotel->descripcionCorta));
        }
        if ($hotel->descripcionLarga && strlen(trim($hotel->descripcionLarga)) > 0) {
            $hotel->descripcionesLargas = json_decode(trim($hotel->descripcionLarga));
        }
        if ($hotel->informacionCompra && strlen(trim($hotel->informacionCompra)) > 0) {
            $hotel->informacionesCompra = json_decode(trim($hotel->informacionCompra));
        }
        if ($hotel->tituloSeo && strlen(trim($hotel->tituloSeo)) > 0) {
            $hotel->titulosSeo = json_decode(trim($hotel->tituloSeo));
        }
        if ($hotel->keywordsSeo && strlen(trim($hotel->keywordsSeo)) > 0) {
            $hotel->jkeywordsSeo = json_decode(trim($hotel->keywordsSeo));
        }
        $hotel->fechas = DAOFactory::getHotelFechasDAO()->queryByHotelId($hotel->id);
        if ($hotel->logoId) {
            $hotel->logo = DAOFactory::getArchivoDAO()->load($hotel->logoId);
        }
        $hotel->dominios = DAOFactory::getHotelDominiosDAO()->queryByHotelId($hotel->id);
        $hotel->promociones = DAOFactory::getPromocionDAO()->queryByHotelId($hotel->id);
        if ($hotel->promociones) {
            $hotel->promocionActual = false;
            foreach ($hotel->promociones as $p) {
                $now = time();
                if ($now >= strtotime($p->inicio) && $now <= strtotime($p->fin) + 24 * 60 * 60) {
                    $hotel->promocionActual = $p;
                }
            }
        }
        if ($hotel->monedaId) {
            $hotel->moneda = getMoneda($hotel->monedaId);
        }
        global $money;
        $preciosMinimos = DAOFactory::getHotelPrecioDAO()->queryByHotelId($hotel->id);
        if ($preciosMinimos && count($preciosMinimos)) {
            $precio_minimo_val = $preciosMinimos[0]->precioMinimo;
            if ($convertirMonedas) {
                $precio_moneda_seleccionada = convertFromMonedaToMoneda($precio_minimo_val, $hotel->moneda->codigo, $money);
                $preciosMinimos[0]->precioMinimo = $precio_moneda_seleccionada;
            } else {
                $preciosMinimos[0]->precioMinimo = $precio_minimo_val;
            }
            $hotel->precioMinimo = $preciosMinimos[0];
        }
        $hotel->blacklist = DAOFactory::getBlacklistDAO()->queryByHotelId($hotel->id);
        if ($hotel->destinoId) {
            $hotel->destino = getDestino($hotel->destinoId);
            if ($hotel->destino->descripcion) {
                $hotel->destino->descripciones = json_decode($hotel->destino->descripcion);
            }
            if ($hotel->mostrarHotelesRelacionados) {
                $hoteles = DAOFactory::getHotelDAO()->queryByDestinoId($hotel->destinoId);
                $keys = array_rand($hoteles, count($hoteles) > 10 ? 10 : count($hoteles));
                if (!is_array($keys)) {
                    $keys = array($keys);
                }
                $relacionados = array();
                foreach ($keys as $k) {
                    $h = $hoteles[$k];
                    if ($h->id != $hotel->id) {
                        $precioMinimo = DAOFactory::getHotelPrecioDAO()->queryByHotelId($h->id);
                        $logoHotel = getHotelLogo($h->id);
                        if ($precioMinimo && count($precioMinimo)) {
                            $precio_minimo_val = $precioMinimo[0]->precioMinimo;
                            $precio_moneda_seleccionada = convertFromMonedaToMoneda($precio_minimo_val, $hotel->moneda->codigo, $money);
                            $precioMinimo[0]->precioMinimo = $precio_moneda_seleccionada;
                            $h->precioMinimo = $precioMinimo[0];
                            $h->logo = $logoHotel;
                        }
                        $h->campania = DAOFactory::getCampaniaDAO()->load($h->campaniaId);
                        if (strlen($logoHotel->ruta) > 0) {
                            $relacionados[] = $h;
                        }
                    }
                }
                $hotel->relacionados = $relacionados;
            }
        }
        return $hotel;
    } catch (Exception $e) {
        return false;
    }
}