Joywork/ajax/getAdCostStatWindowContent.php
2026-05-22 21:21:54 +03:00

225 lines
9.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
if ($_SESSION['id'] && $_GET['id'] && is_numeric($_GET['id'])) {
global $PROMO_TARGETS;
global $ZIPAL_TARGETS;
$get = clearInputData($_GET);
$user = new User;
$user->checkPermissions();
$gmtmsk = get_time_zone_user();
$time_zone = '';
if($gmtmsk >= 0){
$time_zone = '+'.$gmtmsk.' hour';
} else {
$time_zone = '-'.$gmtmsk.' hour';
}
$stats_items = [];
$use_advert_budget = $_SESSION['use_advert_budget'];
$buildRowDate = null;
$key = 1000;
$daySum = 0;
$totalSum = 0;
$sql = "SELECT `stats`.*,
`stats`.`id` AS `id`,
`users`.`last_name` AS `last_name`,
`users`.`first_name` AS `first_name`,
`users`.`middle_name` AS `middle_name`,
`users`.`agency` AS `agency`,
`users`.`fio` AS `fio`,
`users`.`manager` AS `manager`
FROM `object_publish_statistic` AS `stats`
LEFT JOIN `users` AS `users` ON `users`.`id` = `stats`.`publish_user_id`
WHERE `stats`.`object_id` = '$get[id]' AND `stats`.`on_moderation` = 0
ORDER BY `stats`.`publish_start_date` DESC,
`stats`.`id` ASC";
echo '<div class="history__results" style="height: 300px !important;">';
echo '<div style="padding-bottom: 13px;font-size: 17px;font-weight: bold;" id="sum_adv_block_' . $get['id'] . '">Всего затрачено на рекламу 0 рублей</div>';
echo '<div class="log_history" style="margin-top: 0 !important;">';
$stats = [];
if ($query = mysql_query($sql)) {
while ($stat = mysql_fetch_assoc($query)) {
$stats[] = $stat;
}
$num = 0;
$targets = array_merge($PROMO_TARGETS, $ZIPAL_TARGETS);
$columns = array_column($stats, 'publish_start_date');
array_multisort($columns, SORT_DESC, $stats);
foreach ($stats as $stat) {
$num++;
$targetName = $targets[$stat['destination']];
if (in_array($stat['destination'], array_keys($PROMO_TARGETS)))
$stat['type'] = 'promotion';
else
$stat['type'] = 'regular';
if (!$stat['fio']) {
if ($stat['middle_name']) {
$stat['fio'] = $stat['last_name'] . " " . $stat['first_name'] . " " . $stat['middle_name'];
} else {
$stat['fio'] = $stat['last_name'] . " " . $stat['first_name'];
}
}
if ($stat['agency']) {
$master = "Агентство " . $stat['fio'];
} else if ($stat['manager']) {
$master = "Менеджер " . $stat['fio'];
} else {
$master = "Агент " . $stat['fio'];
}
$dateTime = strtotime($time_zone, strtotime($stat['publish_start_date']));
$dateFromRow = date('d', $dateTime) . ' ' . getRusMonth(date('m', $dateTime)) . ' ' . date('Y', $dateTime);
if (!$targetName)
$targetName = $stat['destination'];
$item = '<li>';
$item .= '<div class="log_event" title="' . $master . '">';
$item .= '<span class="name">' .date('H:i:s', $dateTime) . '</span>';
$item .= ' <i class="ti-arrow-right"></i> ';
if ($stat['type'] == 'promotion')
$item .= '<span class="address">Продвижение от ' . trim($targetName) . '</span>';
else
$item .= '<span class="address">Выставлено ' . ((strpos($targetName, 'Фид') !== false) ? 'в ' : 'на ') . trim($targetName) . '</span>';
$info = [];
if ($stat['days_count'] == 5000)
$info[] = ', бессрочно' ;
else if ($stat['days_count'] > 0)
$info[] = ' срок ' . declOfNum($stat['days_count'], ['%d день', '%d дня', '%d дней']) . ' (до ' . date('d.m.Y', strtotime($stat['publish_end_date'])) . ')';
$price_string = 'бесплатно';
if ($stat['type'] == 'promotion' && ($_SESSION['users_admin'] || $_SESSION['agency'])) {
if ($stat['price'] > 0)
$price_string = (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
else
$price_string = 'бесплатно';
$info[] = ' сумма <a href="javascript:{};" id="ad_cost_link_'.$num.'" onclick="$(\'#ad_cost_link_'.$num.'\').toggleClass(\'hidden\', \'\') && $(\'#ad_cost_input_'.$num.'\').toggleClass(\'hidden\', \'\') && $(\'#ad_cost_input_'.$num.'\').focus();">' . $price_string . ' <i class="ti-pencil"></i></a>' .
' <span id="ad_cost_input_'.$num.'" class="wrapper hidden"><input style="font-size:14px;"' .
' name="ad_cost_input_'.$num.'" data-type="promotion" data-old-price="'.$price_string.'" value="'.$stat['price'].'"' .
' data-link="#ad_cost_link_'.$num.'"' .
' data-object-id="'.$get['id'].'"' .
' data-destination="'.$stat['destination'].'" /> <i id="ad_cost_save_'.$num.'" class="ti-save" data-id="'.$stat['id'].'" data-ref="input[name=\'ad_cost_input_'.$num.'\']" style="cursor: pointer"></i></span>';
} else if ($stat['type'] == 'regular' && ($_SESSION['users_admin'] || $_SESSION['agency'])) {
if ($stat['price'] > 0)
$price_string = (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
else
$price_string = 'бесплатно';
$info[] = ' сумма <a href="javascript:{};" id="ad_cost_link_'.$num.'" onclick="$(\'#ad_cost_link_'.$num.'\').toggleClass(\'hidden\', \'\') && $(\'#ad_cost_input_'.$num.'\').toggleClass(\'hidden\', \'\') && $(\'#ad_cost_input_'.$num.'\').focus();">' . $price_string . ' <i class="ti-pencil"></i></a>' .
' <span id="ad_cost_input_'.$num.'" class="wrapper hidden"><input style="font-size:14px;"' .
' name="ad_cost_input_'.$num.'" data-type="regular" data-old-price="'.$price_string.'" value="'.$stat['price'].'"' .
' data-link="#ad_cost_link_'.$num.'"' .
' data-object-id="'.$get['id'].'"' .
' data-destination="'.$stat['destination'].'" /> <i id="ad_cost_save_'.$num.'" class="ti-save" data-id="'.$stat['id'].'" data-ref="input[name=\'ad_cost_input_'.$num.'\']" style="cursor: pointer"></i></span>';
} else {
$info[] = ' сумма ' . (((float)$stat['price'] < 1) ? declOfNum((float)$stat['price'] * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$stat['price'], ['%s рубль', '%s рубля', '%s рублей']));
}
if ($stat['unpublish_user_id']) {
$user = mysql_fetch_assoc(mysql_query("SELECT agency, manager, fio, last_name, first_name, middle_name FROM users WHERE id=$stat[unpublish_user_id]"));
$master = '-';
if ($user) {
if (!$user['fio']) {
if ($user['middle_name']) {
$user['fio'] = $user['last_name'] . " " . $user['first_name'] . " " . $user['middle_name'];
} else {
$user['fio'] = $user['last_name'] . " " . $user['first_name'];
}
}
if ($user['agency'])
$master = "Агентство $user[fio]";
else if ($user['manager'])
$master = "Менеджер $user[fio]";
else
$master = "Агент $user[fio]";
}
$info[] = ' снято с публикации ' . date('d.m.Y H:i:s', strtotime($time_zone, strtotime($stat['updated_at']))) . ' пользователем ' . $master;
} else {
if ($stat['unpublish_user_id'] == '0')
$info[] = ' снято с публикации автоматически ' . date('d.m.Y H:i:s', strtotime($time_zone, strtotime($stat['publish_end_date'])));
}
$item .= implode(', ', $info);
$item .= '<div class="clear"></div>';
$item .= '</div>';
$item .= '</li>';
$date_key = date('Y-m-d', strtotime($stat['publish_start_date']));
$stats_items[$date_key]['items'][] = $item;
$stats_items[$date_key]['total'] += (float)$stat['price'];
$totalSum += (float)$stat['price'];
}
}
if (!empty($stats_items)) {
$key = 1000;
foreach ($stats_items as $stat_date => $stat_data) {
echo '<div class="by-date">';
$date_string = date('d', strtotime($stat_date)) . ' ' . getRusMonth(date('m', strtotime($stat_date))) . ' ' . date('Y', strtotime($stat_date));
echo '<p><a href="javascript:{}" class="open_folder" id="link'.$key.$get['id'].'" data-id="'.$stat_date.'">';
if ($stat_data['total'] > 0)
echo $date_string . ' затрачено ' . declOfNum($stat_data['total'], ['%s рубль', '%s рубля', '%s рублей']);
else
echo $date_string . ' затрачено 0 рублей';
echo '</a></p>';
echo '<ul class="link'.$key.$get['id'].' ">';
if (!empty($stat_data['items'])) {
foreach ($stat_data['items'] as $item) {
echo $item;
}
}
$key++;
echo '</ul>';
echo '</div>';
}
}
$totalSumText = $totalSum < 1 ? declOfNum($totalSum * 100, array('%d копейка', '%d копейки', '%d копеек')) : declOfNum($totalSum, array('%s рубль', '%s рубля', '%s рублей'));
echo '<script type="text/javascript">$("#sum_adv_block_' . $get['id'] . '").html("Всего затрачено на рекламу ' . $totalSumText . '");</script>';
echo '</div>';
echo '</div>';
}