id = $max_id + 1; $place->name = urldecode($input['name']); $place->save(); return [ 'status' => 'success', 'message' => 'Зал успешно добавлен', 'place' => $place ]; } if ($input['action'] == 'update' && isset($input['id']) && isset($input['name'])) { $place = Places::find($input['id']); $place->name = urldecode($input['name']); $place->save(); return [ 'status' => 'success', 'message' => 'Зал успешно обновлен', 'place' => $place ]; } if ($input['action'] == 'delete' && isset($input['id'])) { $place = Places::find($input['id']); $place->delete(); return [ 'status' => 'success', 'message' => 'Зал успешно удален' ]; } if ($input['action'] == 'saveplaces' && isset($input['places'])) { DB::statement("SET foreign_key_checks=0"); Tables::truncate(); Places::truncate(); DB::statement("SET foreign_key_checks=1"); $input['places'] = json_decode(urldecode($input['places']), TRUE); foreach ($input['places'] as $place_items) { $place_name = urldecode($place_items['place_name']); $newPlace = new Places; $newPlace->name = $place_name; $newPlace->save(); foreach ($place_items['tables'] as $table_item) { $table_id = $table_item['table_id']; $table_place_id = $place_items['place_id']; $table_name = urldecode($table_item['name']); $table_width = $table_item['width']; $table_height = $table_item['height']; $table_x = $table_item['x']; $table_y = $table_item['y']; $newTable = new Tables; $newTable->name = $table_name; $newTable->table_id = $table_id; $newTable->place_id = $table_place_id; $newTable->width = $table_width; $newTable->height = $table_height; $newTable->x = $table_x; $newTable->y = $table_y; $newTable->save(); } } $places = Places::all(); foreach ($places as $place) { $tables = Tables::where('place_id', $place['id'])->get(); $roommap[] = array('place_id' => $place['id'], 'place_name' => $place['name'], 'tables' => $tables); } return [ 'status' => 'success', 'message' => 'Карта успешно обновлена', 'roommap' => $roommap, ]; } return [ 'status' => 'success', 'error_message' => 'Проверьте введенные данные', ]; } if (isset($input['type']) && $input['type'] == 'table') { if ($input['action'] == 'create' && isset($input['place_id']) && isset($input['table_id']) && isset($input['name']) && isset($input['width']) && isset($input['height']) && isset($input['x']) && isset($input['y'])) { $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->where('name', $input['name'])->first(); if (isset($table)) { return [ 'status' => 'success', 'error_message' => 'Стол уже существует', ]; } $table_id = $input['table_id']; $table_place_id = $input['place_id']; $table_name = urldecode($input['name']); $table_width = $input['width']; $table_height = $input['height']; $table_x = $input['x']; $table_y = $input['y']; $newTable = new Tables; $newTable->name = $table_name; $newTable->table_id = $table_id; $newTable->place_id = $table_place_id; $newTable->width = $table_width; $newTable->height = $table_height; $newTable->x = $table_x; $newTable->y = $table_y; $newTable->save(); return [ 'status' => 'success', 'message' => 'Стол успешно добавлен', 'table' => $newTable ]; } if ($input['action'] == 'update' && isset($input['place_id']) && isset($input['table_id']) && isset($input['name']) && isset($input['width']) && isset($input['height']) && isset($input['x']) && isset($input['y'])) { $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first(); $table_id = $input['table_id']; $table_place_id = $input['place_id']; $table_name = urldecode($input['name']); $table_width = $input['width']; $table_height = $input['height']; $table_x = $input['x']; $table_y = $input['y']; $table = Tables::find($table['id']); $table->name = $table_name; $table->table_id = $table_id; $table->place_id = $table_place_id; $table->width = $table_width; $table->height = $table_height; $table->x = $table_x; $table->y = $table_y; $table->save(); return [ 'status' => 'success', 'message' => 'Стол успешно обновлен', 'table' => $table ]; } if ($input['action'] == 'delete' && isset($input['place_id']) && isset($input['table_id'])) { $table = Tables::where('place_id', $input['place_id'])->where('table_id', $input['table_id'])->first(); $table = Tables::find($table['id']); $table->delete(); } if ($input['action'] == 'savetables' && isset($input['tables']) && isset($input['place_id'])) { $input['tables'] = json_decode(urldecode($input['tables']), TRUE); $tables = Tables::where('place_id', intval($input['place_id']))->get(); foreach ($tables as $table) { $del_table = Tables::find($table['id']); $del_table->delete(); } foreach ($input['tables'] as $item) { $table_id = $item['table_id']; $table_place_id = $item['place_id']; $table_name = urldecode($item['name']); $table_width = $item['width']; $table_height = $item['height']; $table_x = $item['x']; $table_y = $item['y']; $newTable = new Tables; $newTable->name = $table_name; $newTable->table_id = $table_id; $newTable->place_id = $table_place_id; $newTable->width = $table_width; $newTable->height = $table_height; $newTable->x = $table_x; $newTable->y = $table_y; $newTable->save(); } return [ 'status' => 'success', 'message' => 'Зал успешно обновлен' ]; } } return [ 'status' => 'success', 'error_message' => 'Проверьте введенные данные', ]; } }