Actual prod

This commit is contained in:
mac 2026-07-02 08:12:13 +03:00
parent 7770a35e55
commit 7ee214b7ff

View File

@ -379,7 +379,9 @@ echo '[';
if (isset($_POST['user_id'])) {
if($eobj){
$sql = "SELECT e.*, o.nazv, o.adres, o.dom, o.korpus, o.litera from user_object_events e, objects o WHERE user_id in (". implode(', ', $usersId).") $whereObj $part_task and o.id=e.object_id and e.schedule_date is not null and $startDateWhere and $endDateWhere";
// Явные колонки (НЕ e.*): после колонки moved_on_copy в user_object_events e.* стал шире 2-й ветки UNION
// → «different number of columns» → задачи по своим объектам пропадали из «Кабинет → Задачи». Порядок o.* выровнен со 2-й веткой.
$sql = "SELECT e.id, e.user_id, e.from_id, e.object_id, e.req_id, e.create_date, e.type, e.address, e.sum, e.document_id, e.schedule_date, e.comment, e.platforms_advert, e.calendar_view, e.cancel, e.tel, e.max, e.name, o.adres, o.dom, o.korpus, o.litera, o.nazv from user_object_events e, objects o WHERE user_id in (". implode(', ', $usersId).") $whereObj $part_task and o.id=e.object_id and e.schedule_date is not null and $startDateWhere and $endDateWhere";
$sql .= "union
SELECT s.id, s.user_for as user_id, 0 as from_id, e.object_id as object_id, 0 as req_id, created_at as create_date, 'sub_moderation' as type,
'' as address,null as sum, null as document_id, created_at as schedule_date, sub_comment as comment, '' as platforms_advert, e.calendar_view,e.cancel, 0 as tel, 0 as max,'' as name, o.adres, o.dom, o.korpus, o.litera,
@ -517,6 +519,55 @@ if (isset($_POST['user_id'])) {
echo "}";
$i++;
}
// Найденные листинги парсера: задачи из своей таблицы, чтобы Кабинет→Задачи показывал их наравне с бейджем
// шапки и личным календарём. Offset-free: object_id = РЕАЛЬНЫЙ el.id (он коллизит с objects.id),
// листинг помечаем флагом is_external=1. table_id = реальный id события, from=listing — завершение адресует
// external_listing_events. LEFT JOIN: листинг мог уйти по TTL (адрес тогда пустой). Комментарии — не задачи;
// сделок/модерации у листингов нет.
// $whereObj (фильтры состояния/типа задачи: calendar_view/schedule_date/type) применяем — эти колонки есть у листинга (алиас e).
// $part_task — req-фильтр по активностям: у листинга нет заявки → при активном фильтре листинги исключаем целиком.
if (empty($part_task)) {
$sqlListing = "SELECT e.*, IFNULL(el.address_text, '') AS adres
FROM external_listing_events e
LEFT JOIN external_listings el ON el.id = e.external_listing_id
WHERE e.user_id IN (".implode(', ', $usersId).") AND e.schedule_date IS NOT NULL $whereObj AND $startDateWhere AND $endDateWhere";
$rezListing = mysql_query($sqlListing);
while ($rezListing && ($event = mysql_fetch_assoc($rezListing))) {
if ($event['type'] == 'comment') {
continue;
}
$from_id = $event['user_id'];
if (!empty($event['from_id'])) $from_id = $event['from_id'];
$label = trim($event['adres']) !== '' ? $event['adres'] : ('EXT-' . $event['external_listing_id']);
$label = str_replace(array('"', '\\', "\r", "\n", '"'), array("'", '/', ' ', ' ', "'"), $label);
$evName = str_replace(array('"', '\\', "\r", "\n", '"'), array("'", '/', ' ', ' ', "'"), (string)$event['name']);
$suffix = isset($from_users[$from_id]) ? (' - '.$from_users[$from_id]) : '';
if ($i > 0) { echo ',{'; } else { echo '{'; }
echo '"id" : "'.$i.'", ';
echo '"table_id" : "'.$event['id'].'", ';
echo '"from" : "listing", ';
echo '"is_external" : "1", '; // явный маркер листинга для openEventsWindow (&src=ext); id-диапазон больше не различает
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
echo '"object_id" : "'.(int)$event['external_listing_id'].'",';
$className = ($event['type'] == 'meet') ? 'meet' : (($event['type'] == 'show') ? 'showing' : (($event['type'] == 'even') ? 'even' : 'call'));
if ($event['calendar_view'] != 0) $className .= ' viewed';
if ($event['type'] == 'meet') {
echo '"title": "Встреча '.$label.$suffix.'","className" : "'.$className.'"';
} else if ($event['type'] == 'show') {
echo '"title": "Показ '.$label.$suffix.'","className" : "'.$className.'"';
} else if ($event['type'] == 'even') {
echo '"title": "'.$evName.' '.$label.$suffix.'","className" : "'.$className.'"';
} else {
echo '"title": "Звонок '.$label.$suffix.'","className" : "'.$className.'"';
}
echo "}";
$i++;
}
} // конец if (empty($part_task)) — листинговый блок
}
/*$time = microtime(true) - $start;
@ -536,7 +587,8 @@ if($ecl){
$where .= ' and megafon=0 and mango=0 and telphin=0 and beeline=0 and mts=0 and tele2=0 and allo=0';
}
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") $whereTasks $whereEv $where $part_task and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
// задачи по ответственному = чистый user_id (как личный календарь): убрали $whereEv — who_work-пересечение по ТЕКУЩЕМУ владельцу клиента, из-за него не показывались задачи по переназначенным клиентам
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") $whereTasks $where $part_task and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
if($isReq && empty($whereEv))
$sql = "SELECT * FROM user_client_events as e WHERE user_id in (". implode(', ', $usersId).") and req_id = '-1' and schedule_date is not null and cancel=0 and $startDateWhere and $endDateWhere";
@ -551,14 +603,17 @@ if($ecl){
$clientsIds = array();
$reqsIds = array();
$usersEventIds = array();
$dealIds = array();
$clients = array();
$reqs = array();
$usersEvent = array();
$deals = array();
while ($event = mysql_fetch_assoc($rez)){
$events[] = $event;
if($event['client_id'] > 0) $clientsIds[] = (int)$event['client_id'];
if($event['req_id'] > 0) $reqsIds[] = (int)$event['req_id'];
if($event['user_id'] > 0) $usersEventIds[] = (int)$event['user_id'];
if($event['type'] == 'deal' && !empty($event['deal_id'])) $dealIds[] = (int)$event['deal_id'];
}
if(!empty($clientsIds)){
@ -585,11 +640,26 @@ if($ecl){
}
}
if(!empty($dealIds)){
$sql_deal = "SELECT id, title FROM deals WHERE id in (".implode(',', array_unique($dealIds)).")";
$q_deal = mysql_query($sql_deal);
while($r_deal = mysql_fetch_assoc($q_deal)){
$deals[$r_deal['id']] = $r_deal['title'];
}
}
foreach ($events as $event) {
$from_id = $event['user_id'];
$cancel = 0;
if(!empty($event['from_id'])) $from_id = $event['from_id'];
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
if (in_array($event['deal_id'], $seenDealIds)) {
continue;
}
$seenDealIds[] = $event['deal_id'];
}
$fio = '';
if($event['client_id'] > 0 && isset($clients[$event['client_id']])){
@ -600,6 +670,10 @@ if($ecl){
$cancel = (int)$reqs[$event['req_id']]['cancel'];
}
if ($event['type'] == 'deal' && !empty($event['deal_id']) && isset($deals[$event['deal_id']])) {
$fio = $deals[$event['deal_id']];
}
if($cancel == 0){
if ($i > 0) {