134 lines
5.3 KiB
PHP
134 lines
5.3 KiB
PHP
<?php
|
|
set_time_limit(0);
|
|
|
|
$start = microtime(true);
|
|
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . "/config.php";
|
|
header('Content-Type: application/json');
|
|
|
|
ini_set('error_reporting', E_ALL);
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
|
|
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
|
$sql = "SET NAMES 'utf8'";
|
|
$pdo->query($sql);
|
|
|
|
$complex_status = new ComplexStatus;
|
|
$tel = new Telegram(false, $pdo);
|
|
$max = new MaxClass();
|
|
|
|
|
|
$csr = $complex_status::getComplexStatusReservations();
|
|
|
|
function get_message($csr)
|
|
{
|
|
if (!$csr) return null;
|
|
|
|
global $complex_status;
|
|
global $tel;
|
|
global $max;
|
|
|
|
foreach ($csr as $csr_item)
|
|
{
|
|
if (!$csr_item) return null;
|
|
|
|
$requisition = new Requisitions;
|
|
$requisitions = $requisition->getReqAndWhoWorkByStatusId($csr_item['complex_status_id'], 0, true);
|
|
|
|
$now = new DateTime("now", new \DateTimeZone("Europe/Moscow"));
|
|
|
|
foreach ($requisitions as $req_and_user)
|
|
{
|
|
if($req_and_user
|
|
&& $req_and_user['telegramm_notice']
|
|
&& $req_and_user['telegramm_notice'] == 1
|
|
&& $req_and_user['telegramm_chat_id']
|
|
&& $req_and_user['telegramm_chat_id'] > 0
|
|
){
|
|
$booking_date = new DateTime($req_and_user['reservation_updated_at']);
|
|
$booking_date->modify('+' . $csr_item['booking_day'] . ' day');
|
|
$booking_date->modify('+' . $csr_item['booking_hour'] . ' hour');
|
|
|
|
$reminder_date = new DateTime($booking_date->format('Y-m-d H:i:s'));
|
|
$reminder_date->modify('-' . (int)$csr_item['reminder_day'] . ' day');
|
|
$reminder_date->modify('-' . (int)$csr_item['reminder_hour'] . ' hour');
|
|
|
|
if ($now >= $reminder_date)
|
|
{
|
|
$chatId = $req_and_user['telegramm_chat_id'];
|
|
|
|
if($chatId > 0)
|
|
{
|
|
$text = "<b>Истекает бронь</b>\nID заявки: " . $req_and_user['req_id'] . "\nЖК: " . $req_and_user['complex_name'] . "\nНомер помещения: " . $req_and_user['complex_room_number'] . "\nСрок истечения бронирования: \n" . $booking_date->format('d.m.Y H:i:s');
|
|
|
|
$requisition->update_reservation_is_interrupted($req_and_user['req_id']);
|
|
|
|
try {
|
|
|
|
$tel->send($chatId, $text, 'html');
|
|
}
|
|
catch (Exception $e) {
|
|
(new Logger())->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if($req_and_user
|
|
&& $req_and_user['max_notice']
|
|
&& $req_and_user['max_notice'] == 1
|
|
&& $req_and_user['max_user_id']
|
|
&& $req_and_user['max_user_id'] > 0
|
|
){
|
|
$booking_date = new DateTime($req_and_user['reservation_updated_at']);
|
|
$booking_date->modify('+' . $csr_item['booking_day'] . ' day');
|
|
$booking_date->modify('+' . $csr_item['booking_hour'] . ' hour');
|
|
|
|
$reminder_date = new DateTime($booking_date->format('Y-m-d H:i:s'));
|
|
$reminder_date->modify('-' . (int)$csr_item['reminder_day'] . ' day');
|
|
$reminder_date->modify('-' . (int)$csr_item['reminder_hour'] . ' hour');
|
|
|
|
if ($now >= $reminder_date)
|
|
{
|
|
$maxUserId = $req_and_user['max_user_id'];
|
|
|
|
if($chatId > 0)
|
|
{
|
|
$text = "<b>Истекает бронь</b>\nID заявки: " . $req_and_user['req_id'] . "\nЖК: " . $req_and_user['complex_name'] . "\nНомер помещения: " . $req_and_user['complex_room_number'] . "\nСрок истечения бронирования: \n" . $booking_date->format('d.m.Y H:i:s');
|
|
|
|
$requisition->update_reservation_is_interrupted($req_and_user['req_id']);
|
|
|
|
try {
|
|
|
|
$max->send_messages_to_user($maxUserId, $text);
|
|
}
|
|
catch (Exception $e) {
|
|
(new Logger())->error($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$er_is_interrupted_requisitions = $requisition->getReqAndWhoWorkByStatusId($csr_item['complex_status_id'], 0, false, 0, true);
|
|
foreach ($er_is_interrupted_requisitions as $req_and_user_item)
|
|
{
|
|
$booking_date_mc = new DateTime($req_and_user_item['reservation_updated_at']);
|
|
$booking_date_mc = $booking_date_mc->modify('+' . $csr_item['booking_day'] . ' day');
|
|
$booking_date_mc = $booking_date_mc->modify('+' . $csr_item['booking_hour'] . ' hour');
|
|
|
|
if ($now >= $booking_date_mc)
|
|
{
|
|
$complex_status::addEditEventsClinetsExtensionReservation($csr_item['complex_status_id'], $req_and_user_item['user_id'], $req_and_user_item['client_id'], $req_and_user_item['req_id'], $req_and_user_item['who_work']);
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
get_message($csr);
|
|
|