0) $ids = $_SESSION['checked']; } else { $ids[] = (int)$object; } foreach($ids as $object_id){ $owner_id = (int)mysql_fetch_assoc(mysql_query("SELECT * FROM `objects` WHERE id = '$object_id'"))['id_add_user']; if (!$owner_id) $owner_id = (int)$_SESSION['id']; /*if(isset($post['cian_bet'])){ $cian_bet = (int)$post['cian_bet']; $sql_sh = "UPDATE objects SET cian_bet = $cian_bet WHERE id=$object_id"; //file_put_contents(__DIR__.'/log_add_obj.txt', date('d.m.Y H:i:s').'-'.$sql_sh. "\n", FILE_APPEND); $db_sphinx->query($sql_sh, true); }*/ $sql = "SELECT `id` FROM `ads_promo` WHERE `object_id` = '$object_id' AND `agency_id` = '$agency_id' LIMIT 1"; $id = (int)mysql_fetch_assoc(mysql_query($sql))['id']; if ($id) { $setArr = array(); foreach($post as $field => $val){ if($field != 'object_id' && $field != 'user_id'){ $setArr[] = "`".$field."` = '".$val."'"; } } $sql = "UPDATE `ads_promo` SET "; if(!empty($setArr)){ $sql .= implode(',', $setArr).", "; } $sql .= " `object_owner_id` = '$owner_id', `updated_at` = NOW(), `updated_by` = '$_SESSION[id]' WHERE `id` = '$id'"; } else { $sql = "INSERT INTO `ads_promo` ( `object_id`, `agency_id`, `avito_highlight`, `avito_xl`, `avito_x2_1`, `avito_x2_7`, `avito_x5_1`, `avito_x5_7`, `avito_x10_1`, `avito_x10_7`, `avito_price`, `cian_standard`, `cian_highlight`, `cian_paid`, `cian_premium`, `cian_top3`, `cian_bet`, `cian_ignore_pkg`, `cian_price`, `yandex_premium`, `yandex_raise`, `yandex_promotion`, `yandex_price`, `domclick_express`, `domclick_premium`, `domclick_top`, `domclick_price`, `object_owner_id`, `created_at`, `created_by`, `updated_at`, `updated_by`, `avito_promo_type` ) VALUES( {$object_id}, '$agency_id', '$post[avito_highlight]', '$post[avito_xl]', '$post[avito_x2_1]', '$post[avito_x2_7]', '$post[avito_x5_1]', '$post[avito_x5_7]', '$post[avito_x10_1]', '$post[avito_x10_7]', '$post[avito_price]', '$post[cian_standard]', '$post[cian_highlight]', '$post[cian_paid]', '$post[cian_premium]', '$post[cian_top3]', '$post[cian_bet]', '$post[cian_ignore_pkg]', '$post[cian_price]', '$post[yandex_premium]', '$post[yandex_raise]', '$post[yandex_promotion]', '$post[yandex_price]', '$post[domclick_express]', '$post[domclick_premium]', '$post[domclick_top]', '$post[domclick_price]', '$owner_id', NOW(), '$_SESSION[id]', NULL, NULL, '$post[avito_promo_type]' )"; } $id = null; if (mysql_query($sql)) { $days = 5000; $id = mysql_insert_id(); // Добавляем запись в статистику размещения $sqls = []; $sql = "INSERT INTO object_publish_statistic( object_id, user_owner_id, publish_user_id, created_at, publish_start_date, publish_end_date, days_count, destination, price, price_period, on_moderation ) VALUES"; // + часть запроса по продвижению в Авито if (!empty($post['avito_price'])) { $price = intval($post['avito_price']); $destination = null; if ($post['avito_highlight'] == '1') $destination = 'AVITO_HIGHLIGHT'; else if ($post['avito_xl'] == '1') $destination = 'AVITO_XL'; else if ($post['avito_x2_1'] == '1') $destination = 'AVITO_X2_1'; else if ($post['avito_x2_7'] == '1') $destination = 'AVITO_X2_7'; else if ($post['avito_x5_1'] == '1') $destination = 'AVITO_X5_1'; else if ($post['avito_x5_7'] == '1') $destination = 'AVITO_X5_7'; else if ($post['avito_x10_1'] == '1') $destination = 'AVITO_X10_1'; else if ($post['avito_x10_7'] == '1') $destination = 'AVITO_X10_7'; if (!is_null($destination)) { $sqls[] = $sql . " ( {$object_id}, $owner_id, {$_SESSION['id']}, NOW(), NOW(), DATE_ADD(NOW(), INTERVAL 5000 DAY), 5000, '$destination', $price, $price, 0 )"; } } // + часть запроса по продвижению в ЦИАН if (!empty($post['cian_price'])) { $price = intval($post['cian_price']); $destination = null; if ($post['cian_standard'] == '1') $destination = 'CIAN_STANDARD'; if ($post['cian_highlight'] == '1') $destination = 'CIAN_HIGHLIGHT'; else if ($post['cian_paid'] == '1') $destination = 'CIAN_PAID'; else if ($post['cian_premium'] == '1') $destination = 'CIAN_PREMIUM'; else if ($post['cian_top3'] == '1') $destination = 'CIAN_TOP3'; else if ($post['cian_ignore_pkg'] == '1') $destination = 'CIAN_IGNORE_PKG'; if (!is_null($destination)) { $sqls[] = $sql . " ( {$object_id}, $owner_id, {$_SESSION['id']}, NOW(), NOW(), DATE_ADD(NOW(), INTERVAL 5000 DAY), 5000, '$destination', $price, $price, 0 )"; } } // + часть запроса по продвижению в Я.Недвижимость if (!empty($post['yandex_price'])) { $price = intval($post['yandex_price']); $destination = null; if ($post['yandex_premium'] == '1') $destination = 'YANDEX_PREMIUM'; else if ($post['yandex_raise'] == '1') $destination = 'YANDEX_RAISE'; else if ($post['yandex_promotion'] == '1') $destination = 'YANDEX_PROMOTION'; if (!is_null($destination)) { $sqls[] = $sql . " ( {$object_id}, $owner_id, {$_SESSION['id']}, NOW(), NOW(), DATE_ADD(NOW(), INTERVAL 5000 DAY), 5000, '$destination', $price, $price, 0 )"; } } // + часть запроса по продвижению в ДомКлик if (!empty($post['domclick_price'])) { $price = intval($post['domclick_price']); $destination = null; if ($post['domclick_express'] == '1') $destination = 'DOMCLICK_EXPRESS'; else if ($post['domclick_premium'] == '1') $destination = 'DOMCLICK_PREMIUM'; else if ($post['domclick_top'] == '1') $destination = 'DOMCLICK_TOP'; if (!is_null($destination)) { $sqls[] = $sql . " ( {$object_id}, $owner_id, {$_SESSION['id']}, NOW(), NOW(), DATE_ADD(NOW(), INTERVAL 5000 DAY), 5000, '$destination', $price, $price, 0 )"; } } if (count($sqls) > 0) { foreach ($sqls as $sql) { mysql_query($sql); } } echo json_encode(['success' => true, 'id' => $id, 'errors' => mysql_error()]); } else { echo json_encode(['success' => false, 'errors' => mysql_error()]); } } }