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

102 lines
3.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']) {
die("Доступ запрещён!");
}
global $PROMO_TARGETS;
$currentUserId = $_SESSION['id'];
$post = clearInputData($_POST);
$user_view = new User;
$user_view->get($currentUserId);
if (!isset($user_view->agencyId)) {
$user_view->agencyId = $currentUserId;
$user_view->agencyName = $user_view->agency_name;
}
$agency_id = (int) $user_view->agencyId;
$action = $post['action'];
$section = $post['section'];
$old_price_string = trim($post['old_price']);
if ($action == 'edit_price' && !empty($post['id']) && !empty($post['object_id'])) {
if (in_array($section, ['promotion', 'regular'])) {
$service_name = '';
$price = (string)$post['price'];
if (in_array($post['destination'], array_keys($PROMO_TARGETS))) {
if (strpos($post['destination'], 'AVITO_') !== false) {
$service_name = 'продвижения в Рекламе для Avito';
} else if (strpos($post['destination'], 'CIAN_') !== false) {
$service_name = 'продвижения в Рекламе для ЦИАН';
} else if (strpos($post['destination'], 'YANDEX_') !== false) {
$service_name = 'продвижения в Рекламе для Я.Недвижимость';
} else if (strpos($post['destination'], 'DOMCLICK_') !== false) {
$service_name = 'продвижения в Рекламе для ДомКлик';
}
} else if (strpos($post['destination'], '_JW_FEED') !== false) {
if (strpos($post['destination'], 'AVITO_') !== false) {
$service_name = 'размещения для Фида Avito';
} else if (strpos($post['destination'], 'CIAN_') !== false) {
$service_name = 'размещения для Фида ЦИАН';
} else if (strpos($post['destination'], 'YANDEX_') !== false) {
$service_name = 'размещения для Фида Я.Недвижимость';
} else if (strpos($post['destination'], 'DOMCLICK_') !== false) {
$service_name = 'размещения для Фида ДомКлик';
} else if (strpos($post['destination'], 'EMLS_') !== false) {
$service_name = 'размещения для Фида JCat';
}
} else {
$service_name = 'размещения';
}
$sql = "UPDATE `object_publish_statistic`
SET `price`='$price'
WHERE `id`='{$post['id']}' AND
`object_id`='{$post['object_id']}' AND
`destination`='{$post['destination']}'";
if (!empty($sql)) {
if (mysql_query($sql)) {
$price_string = (((float)$price < 1) ? declOfNum((float)$price * 100, ['%d копейка', '%d копейки', '%d копеек']) : declOfNum((float)$price, ['%s рубль', '%s рубля', '%s рублей']));
$message = 'Изменена стоимость ' . $service_name . ' с '. $old_price_string . ' на ' . $price_string;
$sqlEvent = "INSERT INTO user_object_events(user_id, object_id, type, comment) VALUES($_SESSION[id], $post[object_id], 'comment', '$message')";
mysql_query($sqlEvent);
echo json_encode([
'object_id' => $post['object_id'],
'destination' => $post['destination'],
'price' => $price,
'price_string' => $price_string,
//'_sql' => $sql,
]);
}
} else {
echo json_encode([
'error' => mysql_error(),
]);
}
exit();
}
} else {
$tableName = $post['name'];
if ($tableName === '') {
$tableName = 'Таблица';
}
$tableId = (int) $post['id'];
$tableType = (int) $post['type'];
$funnelsJSON = $post['funnels'];
$addFieldsJSON = $post['addFields'];
mysql_query("UPDATE stat_tables SET `name`='$tableName', `type`=$tableType, `json_funnel`='$funnelsJSON', "
. "`json_add`='$addFieldsJSON' WHERE id=$tableId");
}