Actualizar Interfaz/verificar_e_insertar_asientos.php
This commit is contained in:
parent
2da4802310
commit
b04da3bead
|
@ -12,7 +12,6 @@ if (empty($artista) || empty($dias) || $filas <= 0 || $columnas <= 0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Verificar si ya existen asientos para el artista y los días especificados
|
|
||||||
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM asientos WHERE artista = :artista AND dia IN (" . implode(',', $dias) . ")");
|
$stmt = $conn->prepare("SELECT COUNT(*) AS total FROM asientos WHERE artista = :artista AND dia IN (" . implode(',', $dias) . ")");
|
||||||
$stmt->execute([':artista' => $artista]);
|
$stmt->execute([':artista' => $artista]);
|
||||||
$resultado = $stmt->fetch(PDO::FETCH_ASSOC);
|
$resultado = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
|
@ -22,14 +21,13 @@ try {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insertar los asientos para cada día
|
|
||||||
$stmt = $conn->prepare("INSERT INTO asientos (artista, dia, asiento, estado, precio) VALUES (:artista, :dia, :asiento, 'disponible', :precio)");
|
$stmt = $conn->prepare("INSERT INTO asientos (artista, dia, asiento, estado, precio) VALUES (:artista, :dia, :asiento, 'disponible', :precio)");
|
||||||
|
|
||||||
foreach ($dias as $dia) {
|
foreach ($dias as $dia) {
|
||||||
for ($i = 1; $i <= $filas; $i++) {
|
for ($i = 1; $i <= $filas; $i++) {
|
||||||
for ($j = 0; $j < $columnas; $j++) {
|
for ($j = 0; $j < $columnas; $j++) {
|
||||||
$asiento = $i . chr(65 + $j); // Ej: 1A, 1B, ..., 10L
|
$asiento = $i . chr(65 + $j);
|
||||||
$precio = obtenerPrecio($i); // Función para calcular el precio según la fila
|
$precio = obtenerPrecio($i);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
':artista' => $artista,
|
':artista' => $artista,
|
||||||
':dia' => $dia,
|
':dia' => $dia,
|
||||||
|
@ -45,7 +43,6 @@ try {
|
||||||
die(json_encode(['error' => 'Error al insertar los asientos: ' . $e->getMessage()]));
|
die(json_encode(['error' => 'Error al insertar los asientos: ' . $e->getMessage()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Función para calcular el precio según la fila
|
|
||||||
function obtenerPrecio($fila) {
|
function obtenerPrecio($fila) {
|
||||||
if ($fila >= 1 && $fila <= 3) return 4500;
|
if ($fila >= 1 && $fila <= 3) return 4500;
|
||||||
if ($fila >= 4 && $fila <= 7) return 2600;
|
if ($fila >= 4 && $fila <= 7) return 2600;
|
||||||
|
@ -53,3 +50,4 @@ function obtenerPrecio($fila) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue