- 9
- 1
Бизнесы на карте не отображаются.
дома отображаются но бизнесы нет.
дома отображаются но бизнесы нет.
PHP:
<?php
class CFG {
const DB_URL = 'd';
const DB_USER = 'd';
const DB_PASSWORD = 'd';
const DB_NAME = 'd';
}
header('Content-Type: application/json');
$mysqli = @new mysqli(CFG::DB_URL, CFG::DB_USER, CFG::DB_PASSWORD, CFG::DB_NAME);
if ($mysqli->connect_error) {
die(json_encode(['error' => "Ошибка подключения: " . $mysqli->connect_error]));
}
$mysqli->set_charset("utf8");
$output = [
'houses' => ['hasOwner' => [], 'noOwner' => []],
'businesses' => ['hasOwner' => [], 'noOwner' => []]
];
function parseCoords($coordString) {
$coords = explode(',', $coordString);
return [
'x' => isset($coords[0]) ? (float)$coords[0] : 0,
'y' => isset($coords[1]) ? (float)$coords[1] : 0
];
}
$houses = $mysqli->query("SELECT ID, Enter_X, Enter_Y, Name, Owner FROM houses");
if ($houses) {
while ($house = $houses->fetch_assoc()) {
$item = [
'id' => (int)$house['ID'],
'lx' => (float)$house['Enter_X'],
'ly' => (float)$house['Enter_Y'],
'name' => !empty($house['Name']) ? $house['Name'] : 'Дом №'.$house['ID'],
'owner' => $house['Owner'],
'hasAuction' => 0,
'auMinBet' => 0,
'auTimeEnd' => 0,
'auStartPrice' => 0
];
$category = ($house['Owner'] == "The State" || empty($house['Owner'])) ? 'noOwner' : 'hasOwner';
$output['houses'][$category][] = $item;
}
$houses->close();
}
$businesses = $mysqli->query("SELECT ID, Enter, Exit, Name, Owner, Cost, State FROM businesses ORDER BY ID");
if ($businesses) {
while ($biz = $businesses->fetch_assoc()) {
$enter = parseCoords($biz['Enter'] ?? '0,0,0');
$exit = parseCoords($biz['Exit'] ?? '0,0,0');
$item = [
'id' => (int)$biz['ID'],
'lx' => $enter['x'],
'ly' => $exit['y'],
'name' => !empty($biz['Name']) ? $biz['Name'] : 'Бизнес №'.$biz['ID'],
'owner' => $biz['Owner'],
'cost' => (int)$biz['Cost'],
'state' => (int)$biz['State'],
'hasAuction' => 0,
'auMinBet' => 0,
'auTimeEnd' => 0,
'auStartPrice' => 0
];
$category = ($biz['Owner'] == "The State" || empty($biz['Owner'])) ? 'noOwner' : 'hasOwner';
$output['businesses'][$category][] = $item;
}
$businesses->close();
}
$mysqli->close();
foreach ($output as &$type) {
foreach ($type as &$category) {
if (empty($category)) $category = [];
}
}
echo json_encode($output, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
?>