576 lines
24 KiB
PHP
576 lines
24 KiB
PHP
|
|
<?php
|
|||
|
|
error_reporting(1);
|
|||
|
|
// Routes
|
|||
|
|
use App\Controller\CyrToLat;
|
|||
|
|
use App\Controller\DateStr;
|
|||
|
|
use App\Controller\ApiController;
|
|||
|
|
|
|||
|
|
$app->get('/main', 'App\Controller\ApiController:index')
|
|||
|
|
->name('index')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->get('/blocks', 'App\Controller\ApiController:blocks')
|
|||
|
|
->name('blocks')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->get('/catalog', 'App\Controller\ApiController:catalog')
|
|||
|
|
->name('catalog')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->get('/catalog/metro/:metro', function ($metro) use ($app){
|
|||
|
|
$catalog = new ApiController;
|
|||
|
|
return $catalog->catalog($app, $metro, 'metro');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
$app->get('/catalog/region/:region', function ($region) use ($app){
|
|||
|
|
$catalog = new ApiController;
|
|||
|
|
return $catalog->catalog($app, $region, 'region');
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
$app->get('/catalog/:page', function ($page) use ($app){
|
|||
|
|
//echo $page;
|
|||
|
|
$catalog = new ApiController;
|
|||
|
|
return $catalog->catalog($app, $page);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$app->post('/catalog', 'App\Controller\ApiController:catalog')
|
|||
|
|
->name('catalog')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
$app->post('/review', 'App\Controller\ApiController:review')
|
|||
|
|
->name('review')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->post('/review_builder', 'App\Controller\ApiController:review_builder')
|
|||
|
|
->name('review_builder')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->post('/message', 'App\Controller\ApiController:message')
|
|||
|
|
->name('message')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->get('/sitemap', 'App\Controller\ApiController:sitemap')
|
|||
|
|
->name('sitemap')
|
|||
|
|
->setParams(array($app));
|
|||
|
|
|
|||
|
|
$app->get('/block/:slug', function ($slug) use ($app) {
|
|||
|
|
|
|||
|
|
$cyr = new CyrToLat();
|
|||
|
|
$pdo = $app->container->get('db');
|
|||
|
|
$sql="SELECT id, name FROM blocks";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->execute();
|
|||
|
|
$blocks = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
foreach ($blocks as $block) {
|
|||
|
|
$block_name = $cyr->convert($block['name']);
|
|||
|
|
if ($block_name == $slug) {
|
|||
|
|
$args['id'] = $block['id'];
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block entry
|
|||
|
|
$sql="SELECT blocks.*, class_types.name as types_name, regions.name as reg_name FROM blocks LEFT JOIN class_types on class_types.id = blocks.class_id
|
|||
|
|
LEFT JOIN regions
|
|||
|
|
ON regions.id=blocks.region_id
|
|||
|
|
WHERE blocks.id=:id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$block_entry = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_data = array();
|
|||
|
|
if ($block_entry) {
|
|||
|
|
// block add info
|
|||
|
|
$sql = "SELECT subways.name, block_subways.distance, blocks.address
|
|||
|
|
FROM block_subways
|
|||
|
|
INNER JOIN subways
|
|||
|
|
ON block_subways.subway_id=subways.id
|
|||
|
|
INNER JOIN blocks
|
|||
|
|
ON block_subways.block_id=blocks.id
|
|||
|
|
WHERE block_id=:block_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$block_add = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
|
|||
|
|
//builder info
|
|||
|
|
$sql = "SELECT * FROM builders WHERE id=:builder_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("builder_id", $block_entry[0]['builder_id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$builders = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if(!$builders) {
|
|||
|
|
$builders = array();
|
|||
|
|
}
|
|||
|
|
$builder_info = array('id' => $builders[0]['id'],'name' => $builders[0]['name'], 'logo' => 'http://' . $_SERVER['SERVER_NAME'] . '/photos/builder/' . $builders[0]['logo']);
|
|||
|
|
|
|||
|
|
//builder_reviews
|
|||
|
|
$sql = "SELECT * FROM `builder_reviews` WHERE builder_id=:builder_id order by id desc";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("builder_id", $block_entry[0]['builder_id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$reviewsb = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
|
|||
|
|
$builder_reviews = [];
|
|||
|
|
if(!empty($reviewsb)){
|
|||
|
|
|
|||
|
|
foreach ($reviewsb as $review) {
|
|||
|
|
$name = 'Не указано';
|
|||
|
|
if(!empty($review['name'])) $name = $review['name'];
|
|||
|
|
$date = 'Не указана';
|
|||
|
|
if(!empty($review['date']) && $review['date'] != '0000-00-00 00:00:00') $date = date('d.m.Y в H:i', strtotime($review['date']));
|
|||
|
|
$builder_reviews[] = array('avatar' => '/assets/img/avatar.svg', 'name' => $name, 'feedback' => $review['review'], 'date' => $date);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//additional images
|
|||
|
|
$block_images[] = $block_entry[0]['image'];
|
|||
|
|
$sql="SELECT image FROM block_images WHERE model_id=:id AND type is NULL";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$ad_images = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if ($ad_images) {
|
|||
|
|
foreach ($ad_images as $ad_image) {
|
|||
|
|
$block_images[] = 'http://'.$_SERVER['SERVER_NAME'].$ad_image['image'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//Corpuses
|
|||
|
|
$sql="SELECT * FROM buildings WHERE block_id=:block_id order by deadline";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$corpuses = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if (!empty($corpuses)) {
|
|||
|
|
foreach ($corpuses as $corpuse) {
|
|||
|
|
if(!empty($corpuse['corp'])){
|
|||
|
|
$corpuses_info[$corpuse['id']]['name'] = $corpuse['corp'].' корпус';
|
|||
|
|
} else {
|
|||
|
|
$corpuses_info[$corpuse['id']]['name'] = $corpuse['line'].' очередь';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$date = date_create_from_format('Y-m-d H:i:s', $corpuse['deadline']);
|
|||
|
|
$corpuses_info[$corpuse['id']]['date'] = DateStr::get_month($date->format('n')).' '.$date->format('Y');
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//get block_apartments
|
|||
|
|
$sql = "SELECT d.room_type_id as aptype, d.price, d.space_total, d.count as amount, room_types.name as name FROM
|
|||
|
|
(SELECT a.room_type_id, a.price, a.space_total, b.count
|
|||
|
|
FROM apartments a
|
|||
|
|
INNER JOIN
|
|||
|
|
(SELECT count(room_type_id) as count, room_type_id, MIN(price) AS minprice
|
|||
|
|
FROM apartments
|
|||
|
|
WHERE apartments.block_id=:block_id
|
|||
|
|
GROUP BY room_type_id) b
|
|||
|
|
ON a.room_type_id = b.room_type_id AND a.price = b.minprice GROUP BY a.room_type_id, a.price, a.space_total ORDER BY a.price) d
|
|||
|
|
INNER JOIN room_types ON d.room_type_id = room_types.id";
|
|||
|
|
// echo $sql;
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$apartments = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
|
|||
|
|
//decoration
|
|||
|
|
$decoration = array();
|
|||
|
|
//apartments_list
|
|||
|
|
$sql = "SELECT a.id as fid, a.height, a.space_total as square, a.flat_floor as floor, b.floors as totalFloor, d.name as type, a.discount_price as cost,
|
|||
|
|
a.room_type_id AS room, t.name AS room_name,
|
|||
|
|
a.image as imgPlan, a.image2 as images
|
|||
|
|
FROM apartments a
|
|||
|
|
INNER JOIN room_types t ON a.room_type_id = t.id
|
|||
|
|
INNER JOIN decoration_types d ON a.decoration_id = d.id
|
|||
|
|
INNER JOIN buildings b ON a.building_id = b.id
|
|||
|
|
WHERE a.block_id=:block_id
|
|||
|
|
ORDER BY cost";
|
|||
|
|
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$ap_list = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$apartments_list = array();
|
|||
|
|
foreach ($ap_list as $ap => $ap_item) {
|
|||
|
|
//var_dump($ap_item);
|
|||
|
|
if(!in_array($ap_item['type'], $decoration)){
|
|||
|
|
$decoration[] = $ap_item['type'];
|
|||
|
|
}
|
|||
|
|
$imgs = array();
|
|||
|
|
foreach ($ap_item as $key => $value) {
|
|||
|
|
if(($key == 'imgPlan' || $key == 'images') && $value != '') {
|
|||
|
|
$imgs[] = $value;
|
|||
|
|
}
|
|||
|
|
if ($key != 'images') {
|
|||
|
|
$apartments_list[$ap][$key] = $value;
|
|||
|
|
} else {
|
|||
|
|
$apartments_list[$ap]['images'] = $imgs;
|
|||
|
|
}
|
|||
|
|
$apartments_list[$ap]['id'] = $ap;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//get block videos
|
|||
|
|
$sql = "SELECT id, url FROM block_videos WHERE block_id=:block_id AND url!=''";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$videos = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_videos = array();
|
|||
|
|
foreach ($videos as $video) {
|
|||
|
|
$pos = '';
|
|||
|
|
$url = htmlspecialchars_decode($video['url']);
|
|||
|
|
|
|||
|
|
if (strpos($url, 'youtu.be') !== false) {
|
|||
|
|
$pos = strripos($url, '/') + 1;
|
|||
|
|
}
|
|||
|
|
if (strpos($url, 'youtube.com') !== false) {
|
|||
|
|
$pos = strripos($url, 'v=') + 2;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if ($pos != '') {
|
|||
|
|
$tempPos = '';
|
|||
|
|
$id = $tempId = substr($url, $pos);
|
|||
|
|
|
|||
|
|
if(strpos($tempId, '&') !== false){
|
|||
|
|
$tempPos = strpos($tempId, '&');
|
|||
|
|
}
|
|||
|
|
if($tempPos != ''){
|
|||
|
|
$id = substr($tempId, 0, -(strlen($tempId) -$tempPos));
|
|||
|
|
}
|
|||
|
|
$arr = array('id'=>$video['id'], 'idvid'=>$id);
|
|||
|
|
$block_videos[] = $arr;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block real images
|
|||
|
|
$sql = "SELECT image FROM block_images WHERE model_id=:block_id AND type=1";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$real_images = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_real_images = array();
|
|||
|
|
if ($real_images) {
|
|||
|
|
foreach ($real_images as $real_image) {
|
|||
|
|
$block_real_images[] = 'http://'.$_SERVER['SERVER_NAME'].$real_image['image'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block features
|
|||
|
|
$sql = "SELECT * FROM block_features WHERE block_id=:block_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$block_features = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
|
|||
|
|
|
|||
|
|
//get block sales
|
|||
|
|
$date_from = date('Y-m-d', strtotime('first day of -5 month'));
|
|||
|
|
$date_to = date('Y-m-d', strtotime('today'));
|
|||
|
|
|
|||
|
|
$sql = "SELECT t.name, DATE_FORMAT(a.updated_at, \"%Y-%m-01 00:00:00\") as period, AVG(discount_meter_price) as price
|
|||
|
|
FROM apartments_sales a
|
|||
|
|
LEFT JOIN room_types t
|
|||
|
|
ON a.room_type_id = t.id
|
|||
|
|
WHERE a.block_id=:block_id
|
|||
|
|
AND a.is_sold = 1
|
|||
|
|
AND a.updated_at >=:period
|
|||
|
|
GROUP BY room_type_id, DATE_FORMAT(updated_at, \"%Y-%m-01 00:00:00\")
|
|||
|
|
UNION
|
|||
|
|
SELECT name, period, price
|
|||
|
|
FROM nb_sales
|
|||
|
|
LEFT JOIN room_types
|
|||
|
|
ON nb_sales.room_type_id = room_types.id
|
|||
|
|
WHERE nb_sales.block_id=:block_id
|
|||
|
|
AND nb_sales.period >=:period";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->bindParam("period", $date_from);
|
|||
|
|
$sth->execute();
|
|||
|
|
$sales = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
// echo json_encode($sales);exit;
|
|||
|
|
|
|||
|
|
|
|||
|
|
$chart_labels = array();
|
|||
|
|
$block_sales = array();
|
|||
|
|
$temp_sales = 0;
|
|||
|
|
if (!empty($sales)) {
|
|||
|
|
$period = new DatePeriod(
|
|||
|
|
new DateTime($date_from),
|
|||
|
|
new DateInterval('P1M'),
|
|||
|
|
new DateTime($date_to)
|
|||
|
|
);
|
|||
|
|
foreach ($period as $key => $value) {
|
|||
|
|
$chart_mon = DateStr::get_month($value->format('n'));
|
|||
|
|
$chart_year = $value->format('Y');
|
|||
|
|
$chart_labels[] = $chart_mon."'".$chart_year;
|
|||
|
|
}
|
|||
|
|
foreach ($sales as $sale) {
|
|||
|
|
if((int)$sale['price'] == 0){
|
|||
|
|
$res_sales[$sale['name']][$sale['period']] = $temp_sales;
|
|||
|
|
} else {
|
|||
|
|
$res_sales[$sale['name']][$sale['period']] = $sale['price'];
|
|||
|
|
$temp_sales = (int)$sale['price'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$temp_sales = 0;
|
|||
|
|
foreach ($res_sales as $res_sale_name => $res_sale) {
|
|||
|
|
foreach ($period as $key => $value) {
|
|||
|
|
if (isset($res_sale[$value->format('Y-m-d 00:00:00')])) {
|
|||
|
|
$block_sales[$res_sale_name][] = (int)$res_sale[$value->format('Y-m-d 00:00:00')];
|
|||
|
|
$temp_sales = (int)$res_sale[$value->format('Y-m-d 00:00:00')];
|
|||
|
|
} else {
|
|||
|
|
$block_sales[$res_sale_name][] = $temp_sales;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block documents
|
|||
|
|
$sql = "SELECT name, file FROM documents WHERE target_id=:block_id AND target_type=9 AND file!=''";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$documents = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_documents=array();
|
|||
|
|
foreach ($documents as $key => $document) {
|
|||
|
|
$block_documents[$key]['name'] = $document['name'];
|
|||
|
|
$file_path = '../..'.$document['file'];
|
|||
|
|
if (file_exists($file_path)) {
|
|||
|
|
$block_documents[$key]['weight'] = round(filesize($file_path)/1000000, 1).'Мб';
|
|||
|
|
} else {
|
|||
|
|
$block_documents[$key]['weight'] = '';
|
|||
|
|
}
|
|||
|
|
$block_documents[$key]['document'] = 'http://'.$_SERVER['SERVER_NAME'].$document['file'];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block progress images
|
|||
|
|
$sql = "SELECT * FROM block_images WHERE model_id=:block_id AND type=2 ORDER BY img_date DESC";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$progress_images = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_progress_images = array();
|
|||
|
|
if ($progress_images) {
|
|||
|
|
foreach ($progress_images as $key => $progress_image) {
|
|||
|
|
$date = date_create_from_format('Y-m-d H:i:s', $progress_image['img_date']);
|
|||
|
|
$block_progress_images[$key]['year'] = $date->format('Y');
|
|||
|
|
$block_progress_images[$key]['month'] = DateStr::get_month_en($date->format('n'));
|
|||
|
|
$block_progress_images[$key]['photo'] = 'http://'.$_SERVER['SERVER_NAME'].$progress_image['image'];
|
|||
|
|
$block_progress_images[$key]['photoLarge'] = 'http://'.$_SERVER['SERVER_NAME'].$progress_image['image'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block video images
|
|||
|
|
$sql = "SELECT * FROM block_images WHERE model_id=:block_id AND type=10";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$video_images = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
$block_video_images = array();
|
|||
|
|
if($video_images) {
|
|||
|
|
foreach ($video_images as $key => $video_image) {
|
|||
|
|
$block_video_images[$video_image['video_id']]['photo'] = 'http://'.$_SERVER['SERVER_NAME'].$video_image['image'];
|
|||
|
|
$block_video_images[$video_image['video_id']]['id'] = $video_image['video_id'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// get block benefits
|
|||
|
|
$sql = "SELECT * FROM block_benefits WHERE block_id=:block_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$block_benefits = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
foreach ($block_benefits as &$benefit) {
|
|||
|
|
$benefit['benefit_icon'] = $benefit['benefit_icon'];
|
|||
|
|
}
|
|||
|
|
// $app->response->setStatus(200);
|
|||
|
|
// $app->response['Content-Type'] = 'application/json';
|
|||
|
|
// echo json_encode($block_benefits);
|
|||
|
|
// exit;
|
|||
|
|
|
|||
|
|
// get block banks
|
|||
|
|
$block_banks = array();
|
|||
|
|
$sql = "SELECT DISTINCT res.id, res.timeFrom, res.timeTo, res.rate, res.deposit, res.name, res.img
|
|||
|
|
FROM
|
|||
|
|
(SELECT min(r.period_min) as timeFrom, max(r.period_max) as timeTo, min(r.rate_percent) as rate, min(r.first_pay_percent) as deposit, b.name, b.id, b.logo as img
|
|||
|
|
FROM buildings bu
|
|||
|
|
INNER JOIN mortgages m
|
|||
|
|
ON bu.id = m.building_id
|
|||
|
|
INNER JOIN bank_programs p
|
|||
|
|
ON p.id = m.program_id
|
|||
|
|
INNER JOIN bank_program_rates r
|
|||
|
|
ON r.bank_program_id = m.program_id
|
|||
|
|
INNER JOIN banks b
|
|||
|
|
ON b.id = p.bank_id
|
|||
|
|
WHERE block_id=:block_id AND b.id in (1,3,8,13)
|
|||
|
|
GROUP BY b.id
|
|||
|
|
ORDER BY b.id) res";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$banks = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
foreach ($banks as $bank) {
|
|||
|
|
$bank['img'] = 'http://'.$_SERVER['SERVER_NAME'].'/photos/bank/'.$bank['img'];
|
|||
|
|
$block_banks[] = $bank;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$sql = "SELECT DISTINCT res.id, res.timeFrom, res.timeTo, res.rate, res.deposit, res.name, res.img
|
|||
|
|
FROM
|
|||
|
|
(SELECT min(r.period_min) as timeFrom, max(r.period_max) as timeTo, min(r.rate_percent) as rate, min(r.first_pay_percent) as deposit, b.name, b.id, b.logo as img
|
|||
|
|
FROM buildings bu
|
|||
|
|
INNER JOIN mortgages m
|
|||
|
|
ON bu.id = m.building_id
|
|||
|
|
INNER JOIN bank_programs p
|
|||
|
|
ON p.id = m.program_id
|
|||
|
|
INNER JOIN bank_program_rates r
|
|||
|
|
ON r.bank_program_id = m.program_id
|
|||
|
|
INNER JOIN banks b
|
|||
|
|
ON b.id = p.bank_id
|
|||
|
|
WHERE block_id=:block_id AND b.id not in (1,3,8,13)
|
|||
|
|
GROUP BY b.id
|
|||
|
|
ORDER BY b.id) res";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$banks = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
foreach ($banks as $bank) {
|
|||
|
|
$bank['img'] = 'http://'.$_SERVER['SERVER_NAME'].'/photos/bank/'.$bank['img'];
|
|||
|
|
$block_banks[] = $bank;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$sql = "SELECT * FROM block_reviews WHERE block_id=:block_id order by id desc";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$block_reviews = [];
|
|||
|
|
|
|||
|
|
$reviews = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
|
|||
|
|
if(!empty($reviews)){
|
|||
|
|
$block_reviews = [];
|
|||
|
|
foreach ($reviews as $review) {
|
|||
|
|
$name = 'Не указано';
|
|||
|
|
if(!empty($review['name'])) $name = $review['name'];
|
|||
|
|
$date = 'Не указана';
|
|||
|
|
if(!empty($review['created_at']) && $review['created_at'] != '0000-00-00 00:00:00') $date = date('d.m.Y в H:i', strtotime($review['created_at']));
|
|||
|
|
$block_reviews[] = array('avatar' => '/assets/img/avatar.svg', 'name' => $name, 'feedback' => $review['review'], 'date' => $date);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$analog_blocks = array();
|
|||
|
|
$ri=(int)$block_entry[0]['region_id'];
|
|||
|
|
$sql = "SELECT b.id, b.name, b.address, b.image, s.name as metro, bs.distance,
|
|||
|
|
b.builder_id, bl.name as builder_name, bl.logo, c.name as class_name,
|
|||
|
|
min(cor.deadline) as min_data, max(cor.deadline) as max_data,
|
|||
|
|
min(a.price) as min_price
|
|||
|
|
FROM blocks as b
|
|||
|
|
LEFT JOIN block_subways as bs
|
|||
|
|
ON bs.block_id=b.id
|
|||
|
|
LEFT JOIN subways as s
|
|||
|
|
ON bs.subway_id=s.id
|
|||
|
|
LEFT JOIN builders as bl
|
|||
|
|
ON bl.id=b.builder_id
|
|||
|
|
LEFT JOIN buildings as cor
|
|||
|
|
ON b.id=cor.block_id
|
|||
|
|
LEFT JOIN class_types as c
|
|||
|
|
ON c.id=b.class_id
|
|||
|
|
INNER JOIN apartments as a
|
|||
|
|
ON b.id=a.block_id AND price != 0
|
|||
|
|
WHERE region_id=$ri and b.id != :block_id group by b.id";
|
|||
|
|
// echo $sql;
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$ab = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if(!empty($ab)){
|
|||
|
|
foreach ($ab as $bl) {
|
|||
|
|
$bl['slug'] = $cyr->convert($bl['name']);
|
|||
|
|
$analog_blocks[] = $bl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$plus_minus = array('plus'=>array(), 'minus'=>array());
|
|||
|
|
$sql = "SELECT * FROM `block_plus_minus` WHERE block_id = :block_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$pm = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if(empty($pm)) {
|
|||
|
|
$plus_minus = array();
|
|||
|
|
} else {
|
|||
|
|
foreach ($pm as $value) {
|
|||
|
|
if($value['plus_minus'] == 0){
|
|||
|
|
$plus_minus['minus'][] = $value;
|
|||
|
|
} else if ($value['plus_minus'] == 1){
|
|||
|
|
$plus_minus['plus'][] = $value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$metas = array('title' => '', 'description' => '', 'keywords' => '');
|
|||
|
|
|
|||
|
|
$sql = "SELECT * FROM `block_meta` WHERE block_id = :block_id";
|
|||
|
|
$sth = $pdo->prepare($sql);
|
|||
|
|
$sth->bindParam("block_id", $args['id']);
|
|||
|
|
$sth->execute();
|
|||
|
|
$met = $sth->fetchAll(\PDO::FETCH_ASSOC);
|
|||
|
|
if(!empty($met)){
|
|||
|
|
foreach ($met as $key => $value) {
|
|||
|
|
$metas = $value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// { avatar: '/assets/img/avatar.svg', name: 'Самойлова Виктория5', feedback: 'хороший комплекс', date: '27.10.2019 в 18:00' }
|
|||
|
|
|
|||
|
|
$foto_author = 'http://'.$_SERVER['SERVER_NAME'].'/images/user-pic.svg';
|
|||
|
|
if(!empty($block_entry[0]['author_photo'])){
|
|||
|
|
$foto_author = 'http://'.$_SERVER['SERVER_NAME'].'/block_images/author_desc/'.$block_entry[0]['author_photo'];
|
|||
|
|
}
|
|||
|
|
// all data
|
|||
|
|
$block_data['block_entry'] = $block_entry[0];
|
|||
|
|
$block_data['block_images'] = $block_images;
|
|||
|
|
$block_data['builder_info'] = $builder_info;
|
|||
|
|
$block_data['corpuses_info'] = $corpuses_info;
|
|||
|
|
$block_data['apartments'] = $apartments;
|
|||
|
|
$block_data['block_videos'] = $block_videos;
|
|||
|
|
$block_data['block_real_images'] = $block_real_images;
|
|||
|
|
$block_data['block_features'] = empty($block_features) ? '' : $block_features[0];
|
|||
|
|
$block_data['block_author'] = array('name' => $block_entry[0]['author_name'],
|
|||
|
|
'photo' => $foto_author,
|
|||
|
|
'desc' => str_replace('../block_images/author_desc', 'http://'.$_SERVER['SERVER_NAME'].'/block_images/author_desc', $block_entry[0]['author_desc']));
|
|||
|
|
$block_data['block_chart_labels'] = $chart_labels;
|
|||
|
|
$block_data['block_sales'] = $block_sales;
|
|||
|
|
$block_data['block_documents'] = $block_documents;
|
|||
|
|
$block_data['block_progress_images'] = $block_progress_images;
|
|||
|
|
$block_data['apartments_list'] = $apartments_list;
|
|||
|
|
$block_data['block_benefits'] = $block_benefits;
|
|||
|
|
$block_data['block_banks'] = $block_banks;
|
|||
|
|
$block_data['block_add'] = $block_add[0];
|
|||
|
|
$block_data['decoration'] = $decoration;
|
|||
|
|
$block_data['corpuses'] = $corpuses;
|
|||
|
|
$block_data['block_reviews'] = $block_reviews;
|
|||
|
|
$block_data['builder_reviews'] = $builder_reviews;
|
|||
|
|
$block_data['block_video_images'] = $block_video_images;
|
|||
|
|
$block_data['analog_blocks'] = $analog_blocks;
|
|||
|
|
$block_data['plus_minus'] = $plus_minus;
|
|||
|
|
$block_data['metas'] = $metas;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$app->response->setStatus(200);
|
|||
|
|
$app->response['Content-Type'] = 'application/json';
|
|||
|
|
echo json_encode($block_data, JSON_UNESCAPED_UNICODE);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// Page not found handler
|
|||
|
|
$app->notFound(function () use ($app) {
|
|||
|
|
$app->render('errors/404.phtml');
|
|||
|
|
});
|