1254 lines
67 KiB
PHP
1254 lines
67 KiB
PHP
<?php
|
||
|
||
//use App\v2\Controller\RequisitionsController;
|
||
|
||
set_time_limit(0);
|
||
ini_set('memory_limit', '8192M');
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
||
require_once($_SERVER['DOCUMENT_ROOT']."/ajax/vue_php_function.php");
|
||
header('Content-Type: application/json');
|
||
ini_set('display_errors', 1);
|
||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE);
|
||
|
||
//$w = new WebHookSend(13154, 2, 622489, 'req');
|
||
|
||
|
||
/*$cl = new Clients();
|
||
$res = get_class_etap(3840715, 994);
|
||
var_dump($res);*/
|
||
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
||
|
||
$sql = "SET NAMES 'utf8'";
|
||
|
||
$pdo->query($sql);
|
||
|
||
$db_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
|
||
|
||
|
||
|
||
|
||
/*
|
||
|
||
$sql = "SELECT req.*, req.id as reqid, 'main' as funnel_type FROM requisitions as req LEFT JOIN events_clients ON events_clients.id = (SELECT id FROM events_clients WHERE events_clients.req_id = req.id ORDER BY id DESC LIMIT 1) WHERE funnel_id in (216) AND cancel=0 AND deleted = 0 AND req.confirm = 0 AND req.who_work = 0 AND req.created_at between '1970-01-01 00:00:00' AND '3000-12-31 23:59:59' AND (req.user_id in (SELECT id FROM `users` WHERE id=8826 or id_manager=8826 or id_manager in (select id from users where id_manager=8826) or id_manager in (select id from users where id_manager in (select id from users where id_manager=8826)))) UNION SELECT req.id, req.name, req.user_id, req.created_at, req.client_id,
|
||
req.object_id, a.funnel_id, req.type_id, a.step_id_active as step_id,
|
||
a.who_work as who_work, req.who_delete, a.confirm, req.description,
|
||
req.stage, req.deleted, req.cancel, req.priority, req.doer_clients,
|
||
req.hot, req.reason, req.denial, req.summa, req.activities, req.asfilter_id,
|
||
req.source, req.doers, req.doers_confirm, req.employee_id, req.property_type_id,
|
||
req.integration, req.call_id, req.id as reqid, 'adjacent' as funnel_type
|
||
FROM adjacent_funnels as a
|
||
LEFT JOIN requisitions as req on a.req_id = req.id LEFT JOIN events_clients ON events_clients.id = (SELECT id FROM events_clients WHERE events_clients.req_id = req.id ORDER BY id DESC LIMIT 1) WHERE a.funnel_id in (216) AND cancel=0 AND deleted = 0 AND a.confirm = 0 AND a.who_work = 0 AND req.created_at between '1970-01-01 00:00:00' AND '3000-12-31 23:59:59' AND (req.user_id in (SELECT id FROM `users` WHERE id=8826 or id_manager=8826 or id_manager in (select id from users where id_manager=8826) or id_manager in (select id from users where id_manager in (select id from users where id_manager=8826)))) ORDER BY if ((SELECT date_update from events_clients where req_id=reqid AND (event = 'accepted' OR event = 'restored' OR event = 'accepted_doer') order by id desc limit 1) > created_at, (SELECT date_update from events_clients where req_id=reqid AND (event = 'accepted' OR event = 'restored' OR event = 'accepted_doer') order by id desc limit 1) ,created_at) desc";
|
||
|
||
|
||
$q = $pdo->query($sql);
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
echo $r['id']." - ".$r['user_id']."\n";
|
||
$sql_up = "UPDATE requisitions SET who_work={$r['user_id']}, confirm = 1 WHERE id = {$r['id']}";
|
||
echo $sql_up."\n";
|
||
// $pdo->query($sql_up);
|
||
}
|
||
/*$sql = "SELECT * FROM clients WHERE objects is not null AND objects != '' AND objects != 'null'";
|
||
$q = $pdo->query($sql);
|
||
$num = 0;
|
||
$cl = new Clients();
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
echo $r['id']." - ".$r['objects']."\n";
|
||
$cl->update_objects($r['id'], $r['objects']);
|
||
$num++;
|
||
// if($num == 1) break;
|
||
echo $num."\n";
|
||
}
|
||
echo $num;*/
|
||
|
||
/*$user = new User();
|
||
|
||
$sql = "SELECT id FROM users WHERE id in (select id from users where id=12482 or id_manager=12482 or id_manager in (select id from users where id_manager=12482 or id_manager in (select id from users where id_manager=12482)))";
|
||
//echo $sql;
|
||
$q = mysql_query($sql);
|
||
while($r = mysql_fetch_assoc($q)){
|
||
echo $r['id'].",";
|
||
//$user->gen_token((int)$r['id']);
|
||
}*/
|
||
|
||
/*$arr = array();
|
||
$q = mysql_query("SELECT object_id FROM complex_objects WHERE complex_id = 48");
|
||
while($r = mysql_fetch_assoc($q)){
|
||
$arr[] = (int)$r['object_id'];
|
||
}*/
|
||
|
||
//echo json_encode($arr);
|
||
/* set_time_limit(0);
|
||
ini_set('memory_limit', '8192M');
|
||
error_reporting(E_ALL | E_STRICT);
|
||
ini_set('display_errors', 1);
|
||
header('Content-Type: application/json');
|
||
|
||
|
||
$clients = array();
|
||
$user_ids = array();
|
||
$users_arr = array();
|
||
$user_ids_new = array();
|
||
$sql = "SELECT id, phone, last_name FROM users WHERE phone in (
|
||
'+79201163623',
|
||
'+79109730769',
|
||
'+79109737587',
|
||
'+79109739550',
|
||
'+79201163937',
|
||
'+79109730224',
|
||
'+79109730516',
|
||
'+79109733489',
|
||
'+79109732971',
|
||
'+79109734124',
|
||
'+79201163797'
|
||
)";
|
||
$q = $pdo->query($sql);
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
|
||
$users_arr[$r['id']] = array('id_old'=>$r['id'], 'phone_old'=>$r['phone'], 'last_name_old'=>$r['last_name']);
|
||
$user_ids[] = $r['id'];
|
||
}
|
||
echo '*****'. "\n";
|
||
$sql = "SELECT id, phone, last_name FROM users WHERE phone in (
|
||
'+79159972297',
|
||
'+79201160029',
|
||
'+79201160032',
|
||
'+79290762323',
|
||
'+79301159470',
|
||
'+79201160177',
|
||
'+79108123875',
|
||
'+79201160151',
|
||
'+79605296016',
|
||
'+79201160206',
|
||
'+79201162000'
|
||
)";
|
||
$q = $pdo->query($sql);
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
$user_ids_new[] = $r['id'];
|
||
//echo json_encode($r,JSON_UNESCAPED_UNICODE); echo "\n";
|
||
foreach($users_arr as $id => $user){
|
||
|
||
if($user['last_name_old'] == $r['last_name']){
|
||
$users_arr[$id]['id_new'] = $r['id'];
|
||
$users_arr[$id]['phone_new'] = $r['phone'];
|
||
$users_arr[$id]['last_name_new'] = $r['last_name'];
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
echo json_encode($user_ids_new)."\n";
|
||
//die();
|
||
|
||
$db_sphinx = new MysqlPdo(hstsph2, null, null, null, true, '9306');
|
||
|
||
$post = clearInputData($_POST);
|
||
|
||
$sql3="SELECT * FROM objects WHERE id_add_user in (".implode(',', $user_ids_new).")";
|
||
$rez_obj=$pdo->query($sql3);
|
||
echo $pdo->num_rows($rez_obj)."\n";
|
||
/* while($obj=$pdo->fetch_assoc($rez_obj)){
|
||
$sql_up = "UPDATE objects SET id_add_user={$obj['id_add_user']} WHERE id=$obj[id]";
|
||
$db_sphinx->query($sql_up, true);
|
||
}*/
|
||
|
||
/* while($obj=$pdo->fetch_assoc($rez_obj)){
|
||
$who_work = $obj['id_add_user'];
|
||
$who_work_new = $users_arr[$who_work];
|
||
$id_add_user_new = $who_work_new['id_new'];
|
||
// echo $who_work.' '.$id_add_user_new."\n";
|
||
|
||
echo $obj['id']."\n";
|
||
//переносим объект
|
||
$sql = "INSERT INTO `objects`(`type`, `rayon`, `adres`, `dom`, `korpus`, `litera`, `srok`, `komnat`, `etazh`, `etaz_first_type`, `ploshad`, `ploshad_k`, `holod`, `stirka`, `tv`, `mebel`, `stoim`, `date_add`, `ploshad_komn`, `etazh_iz`, `stoim_prim`, `peshkom`, `transport`, `nazv`, `opis`, `phone`, `archive`, `sobstv`, `phone_search`, `id_user`, `date_really_add`, `prim_srok`, `black`, `vsego_komn`, `moder`, `id_kv`, `id_add_user`, `commission`, `prepay`, `add_to_yandex_feed`, `add_from_archive`, `initial_object_id`, `initial_object_phone`, `initial_object_sobstv`, `type_category`, `use_in_advert`, `initial_object_stoim`, `operation_type`, `studio_flag`, `cadastral_number`, `cadastral_number_land`, `add_to_avito_feed`, `add_to_emls_feed`, `property_type_id`, `land_area`, `rent_house_type_id`, `country_wall_type_id`, `stoim_ky`, `lo_city_id`, `lease_deposit_id`, `add_to_bn_feed`, `kladr_id`, `add_to_zipal`, `add_to_domclick_feed`, `no_pets`, `no_child`, `land_purpose_id`, `land_distance`, `land_burden`, `electricity_type_id`, `gas_type_id`, `plumbing_type_id`, `sewerage_type_id`, `relief_type_id`, `shape_type_id`, `land_usage_type_id`, `lease`, `add_to_cian_feed`, `city_town_id`, `bath_type_id`, `hot_water_id`, `rubbish_chute`, `parking_type_id`, `id_rf_region`, `fbn_id`, `is_main`)
|
||
VALUES ('$obj[type]', '$obj[rayon]', '$obj[adres]', '$obj[dom]', '$obj[korpus]', '$obj[litera]', '$obj[srok]', '$obj[komnat]', '$obj[etazh]', '$obj[etaz_first_type]', '$obj[ploshad]', '$obj[ploshad_k]', '$obj[holod]', '$obj[stirka]', '$obj[tv]', '$obj[mebel]', '$obj[stoim]', NOW(), '$obj[ploshad_komn]', '$obj[etazh_iz]', '$obj[stoim_prim]', '$obj[peshkom]', '$obj[transport]', '$obj[nazv]', '$obj[opis]', '$obj[phone]', '$obj[archive]', '$obj[sobstv]', '$obj[phone_search]', '$obj[id_user]', '$obj[date_really_add]', '$obj[prim_srok]', '$obj[black]', '$obj[vsego_komn]', '$obj[moder]', '$obj[id_kv]', '$id_add_user_new', '$obj[commission]', '$obj[prepay]', '$obj[add_to_yandex_feed]', '$obj[add_from_archive]', '$obj[id]', '$obj[initial_object_phone]', '$obj[initial_object_sobstv]', '$obj[type_category]', '$obj[use_in_advert]', '$obj[initial_object_stoim]', '$obj[operation_type]', '$obj[studio_flag]', '$obj[cadastral_number]', '$obj[cadastral_number_land]', '$obj[add_to_avito_feed]', '$obj[add_to_emls_feed]', '$obj[property_type_id]', '$obj[land_area]', '$obj[rent_house_type_id]', '$obj[country_wall_type_id]', '$obj[stoim_ky]', '$obj[lo_city_id]', '$obj[lease_deposit_id]', '$obj[add_to_bn_feed]', '$obj[kladr_id]', '$obj[add_to_zipal]', '$obj[add_to_domclick_feed]', '$obj[no_pets]', '$obj[no_child]', '$obj[land_purpose_id]', '$obj[land_distance]', '$obj[land_burden]', '$obj[electricity_type_id]', '$obj[gas_type_id]', '$obj[plumbing_type_id]', '$obj[sewerage_type_id]', '$obj[relief_type_id]', '$obj[shape_type_id]', '$obj[land_usage_type_id]', '$obj[lease]', '$obj[add_to_cian_feed]', '$obj[city_town_id]', '$obj[bath_type_id]', '$obj[hot_water_id]', '$obj[rubbish_chute]', '$obj[parking_type_id]', '$obj[id_rf_region]', '$obj[fbn_id]', 0)";
|
||
$pdo->query($sql);
|
||
|
||
$id = $pdo->insert_id();
|
||
|
||
echo 'id=' . $id."\n";
|
||
|
||
//Запрос в сфинкс
|
||
$sql_sh = "INSERT INTO objects_rt (id, type, rayon_id, adres, peshkom, transport, srok, komnat, etazh, ploshad, ploshad_k, ploshad_komn, holod, stirka, tv, mebel, stoim, stoim_prim, moder, date_add, phone_search, id_add_user, commission, type_category, operation_type, id_rf_region, archive, date_really_add)
|
||
VALUES('$id', '$obj[type]', '$obj[rayon]', '$obj[adres]', '$obj[peshkom]', '$obj[transport]', '$obj[srok]', '$obj[komnat]', '$obj[etazh]', '$obj[ploshad]', '$obj[ploshad_k]', '$obj[ploshad_komn]', '$obj[holod]', '$obj[stirka]', '$obj[tv]', '$obj[mebel]', '$obj[stoim]', '$obj[stoim_prim]', '$obj[moder]', '" . strtotime($obj['date_add']) ."', '$obj[phone_search]', '$obj[id_add_user]', '$obj[commission]', '$obj[type_category]', '$obj[operation_type]', '$obj[id_rf_region]', '$obj[archive]', '" . strtotime($obj['date_really_add']) ."')";
|
||
|
||
//echo $sql_sh;
|
||
$db_sphinx->query($sql_sh, true);
|
||
|
||
//переносим доп. инфу
|
||
$sql = "INSERT INTO `objects_additional_information`(`object_id`, `ceiling_height`, `bathroom_unit`, `balcony`, `renovation`, `window_view`, `apartments`, `video_url`, `loggias`, `separate_wcs`, `combined_wcs`, `passenger_lifts`, `cargo_lifts`, `vat_type_id`, `house_category`, `commercial_object_id`, `isPartsEnabled`, `parts_area`, `legal_address`, `isOccupied`, `is_occupied_month`, `is_occupied_year`, `layout_id`, `number_wet_spots`, `electricity_power`, `commer_condition`, `isFurniture`, `commer_access`, `parking_price`, `parkingIsFree`, `building_nazv`, `commerc_year`, `commerc_building_type_id`, `commerc_building_class_id`, `building_area`, `commerc_site`, `commerc_owned`, `commerc_building_category_id`, `building_developer`, `building_management_company`, `commerc_building_ventilation`, `commerc_building_conditioning`, `commerc_building_heating`, `commerc_building_fire`, `commerc_houseLineType_id`, `commerc_opened_id`, `commerc_infrastructure`, `column_grid`, `tax_number`, `floor_material_id`, `commerc_portal_id`, `commerc_purpose`, `gsk_nazv`, `commerc_specifications`, `commerc_land_category_id`, `can_land_category_change`, `commerc_permitted_use_id`, `can_permitted_use_change`, `commerc_investproject`, `is_encumbrances`, `commerc_electricity_id`, `can_electricity`, `commerc_gas_id`, `can_gas`, `commerc_water_id`, `can_water`, `commerc_sewage_id`, `can_sewage`, `commerc_driveways_id`, `garage_type_id`, `commerc_lift1`, `lift1_carrying`, `commerc_lift2`, `lift2_carrying`, `commerc_lift3`, `lift3_carrying`, `commerc_crane1`, `crane1_carrying`, `commerc_crane2`, `crane2_carrying`, `commerc_crane3`, `crane3_carrying`, `commerc_crane4`, `crane4_carrying`, `parking_id`, `commerc_services`, `garage_vid_id`, `boks_vid_id`, `commerc_status_id`, `flat_number`, `restate_feed_id`, `avito_room_type_id`)
|
||
SELECT '$id', `ceiling_height`, `bathroom_unit`, `balcony`, `renovation`, `window_view`, `apartments`, `video_url`, `loggias`, `separate_wcs`, `combined_wcs`, `passenger_lifts`, `cargo_lifts`, `vat_type_id`, `house_category`, `commercial_object_id`, `isPartsEnabled`, `parts_area`, `legal_address`, `isOccupied`, `is_occupied_month`, `is_occupied_year`, `layout_id`, `number_wet_spots`, `electricity_power`, `commer_condition`, `isFurniture`, `commer_access`, `parking_price`, `parkingIsFree`, `building_nazv`, `commerc_year`, `commerc_building_type_id`, `commerc_building_class_id`, `building_area`, `commerc_site`, `commerc_owned`, `commerc_building_category_id`, `building_developer`, `building_management_company`, `commerc_building_ventilation`, `commerc_building_conditioning`, `commerc_building_heating`, `commerc_building_fire`, `commerc_houseLineType_id`, `commerc_opened_id`, `commerc_infrastructure`, `column_grid`, `tax_number`, `floor_material_id`, `commerc_portal_id`, `commerc_purpose`, `gsk_nazv`, `commerc_specifications`, `commerc_land_category_id`, `can_land_category_change`, `commerc_permitted_use_id`, `can_permitted_use_change`, `commerc_investproject`, `is_encumbrances`, `commerc_electricity_id`, `can_electricity`, `commerc_gas_id`, `can_gas`, `commerc_water_id`, `can_water`, `commerc_sewage_id`, `can_sewage`, `commerc_driveways_id`, `garage_type_id`, `commerc_lift1`, `lift1_carrying`, `commerc_lift2`, `lift2_carrying`, `commerc_lift3`, `lift3_carrying`, `commerc_crane1`, `crane1_carrying`, `commerc_crane2`, `crane2_carrying`, `commerc_crane3`, `crane3_carrying`, `commerc_crane4`, `crane4_carrying`, `parking_id`, `commerc_services`, `garage_vid_id`, `boks_vid_id`, `commerc_status_id`, `flat_number`, `restate_feed_id`, `avito_room_type_id` FROM `objects_additional_information` WHERE object_id = $obj[id]";
|
||
$pdo->query($sql);
|
||
|
||
//переносим activity
|
||
/*$sql = "INSERT INTO `objects_activities`(`activity_id`, `object_id`) SELECT `activity_id`, '$id' FROM `objects_activities` where `object_id` = $post[objId]";
|
||
$pdo->query($sql);*/
|
||
|
||
//переносим price hist
|
||
/* $sqlPriceHist= "INSERT INTO `objects_price_history`(`object_id`, `date_change_price`, `price`, `price_ku`) SELECT '$id', `date_change_price`, `price`, `price_ku` FROM `objects_price_history` where `object_id` = $obj[id]";
|
||
$pdo->query($sqlPriceHist);
|
||
|
||
//переносим новостройки
|
||
$sql = "INSERT INTO `object_nb_info`(`object_id`, `newbuilding_id`, `nb_end_date`, `zipal_new_flat_type_id`, `zipal_new_flat_decoration_type_id`, `investor_type_id`, `last_name_id`, `first_name_id`, `second_name_id`, `inn_id`, `documentation_url`) SELECT '$id', `newbuilding_id`, `nb_end_date`, `zipal_new_flat_type_id`, `zipal_new_flat_decoration_type_id`, `investor_type_id`, `last_name_id`, `first_name_id`, `second_name_id`, `inn_id`, `documentation_url` FROM `object_nb_info` where `object_id` = $obj[id]";
|
||
$pdo->query($sql);
|
||
|
||
//переносим метро
|
||
$sql4="SELECT * FROM sp_metro WHERE id_obj = $obj[id]";
|
||
$rez_metro=$pdo->query($sql4);
|
||
while($m = $pdo->fetch_assoc($rez_metro)) {
|
||
$sql = "INSERT INTO sp_metro(id_obj, id_metro) VALUES('$id', '$m[id_metro]')";
|
||
$pdo->query($sql);
|
||
}
|
||
|
||
//переносим фото
|
||
$sqlSelectPhoto = "select oop.id, oop.object_photo_id, oop.sort_order from objects_object_photo oop where oop.object_id = $obj[id]";
|
||
$rezSelectPhoto = $pdo->query($sqlSelectPhoto);
|
||
|
||
if ($pdo->num_rows($rezSelectPhoto) > 0) {
|
||
while ($objPh = $pdo->fetch_assoc($rezSelectPhoto)) {
|
||
$sqlPhoto = "SELECT * FROM object_photo where id = $objPh[object_photo_id]";
|
||
$rezPhoto = $pdo->query($sqlPhoto);
|
||
|
||
if ($pdo->num_rows($rezPhoto) > 0) {
|
||
$photo = $pdo->fetch_assoc($rezPhoto);
|
||
|
||
$pathInfo = pathinfo($photo['photo']);
|
||
|
||
if (stripos($photo['photo'], "http://") === false && stripos($photo['photo'], "https://") === false) {
|
||
$photo['photo'] = $_SERVER['DOCUMENT_ROOT'] . "/photos/" . $photo['photo'];
|
||
}
|
||
|
||
$content = file_get_contents($photo['photo']);
|
||
|
||
$ext = $pathInfo['extension'];
|
||
|
||
if (!$pathInfo['extension']) {
|
||
$ext = 'jpg';
|
||
}
|
||
|
||
if (strlen($ext) > 4) {
|
||
$ext = 'jpg';
|
||
}
|
||
|
||
$ph = md5($pathInfo['filename'].time())."_cpd.".$ext;
|
||
|
||
$one = mb_substr($ph, 0, 1);
|
||
$two = mb_substr($ph, 1, 1);
|
||
$three = mb_substr($ph, 3, 1);
|
||
|
||
$ph = "$one/$two/$three/$ph";
|
||
|
||
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one")) {
|
||
mkdir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one");
|
||
}
|
||
|
||
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one/$two")) {
|
||
mkdir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one/$two");
|
||
}
|
||
|
||
if (!is_dir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one/$two/$three")) {
|
||
mkdir($_SERVER['DOCUMENT_ROOT'] . "/photos/$one/$two/$three");
|
||
}
|
||
|
||
$f1 = fopen($_SERVER['DOCUMENT_ROOT'] . "/photos/" . $ph, "a");
|
||
fwrite($f1, $content);
|
||
fclose($f1);
|
||
|
||
$sqlInsPhoto = "INSERT INTO object_photo(photo) VALUES('$ph')";
|
||
$pdo->query($sqlInsPhoto);
|
||
|
||
$photoId = $pdo->insert_id();
|
||
$sqlInsPhotoLink = "INSERT INTO objects_object_photo(object_id, object_photo_id, sort_order) VALUES($id, $photoId, $objPh[sort_order])";
|
||
$pdo->query($sqlInsPhotoLink);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
//переносим адрес
|
||
$sqlLoc="SELECT * FROM object_location WHERE object_id = $obj[id]";
|
||
$rezLoc=$pdo->query($sqlLoc);
|
||
while($loc = $pdo->fetch_assoc($rezLoc)) {
|
||
$sqlInsLoc = "INSERT INTO object_location(`object_id`, `address`, `latitude`, `longitude`, `street`, `rf_region_rayon`, `city`, `deleted`, `part`) VALUES($id, '$loc[address]', '$loc[latitude]', '$loc[longitude]', '$loc[street]', '$loc[rf_region_rayon]', '$loc[city]', '$loc[deleted]', '$loc[part]')";
|
||
$pdo->query($sqlInsLoc);
|
||
}
|
||
|
||
//переносим доп поля продажи
|
||
if ($obj['operation_type'] == 1) {
|
||
$sql77 = "SELECT * FROM sale_objects WHERE object_id=$obj[id]";
|
||
$rez77 = $pdo->query($sql77);
|
||
while ($saleObj = $pdo->fetch_assoc($rez77)) {
|
||
$sql88 = "INSERT INTO sale_objects (object_id, house_material, house_type, deal_type, build_year) VALUES ('$id', '$saleObj[house_material]', '$saleObj[house_type]', '$saleObj[deal_type]', '$saleObj[build_year]')";
|
||
$pdo->query($sql88);
|
||
}
|
||
}
|
||
|
||
//переносим заметки
|
||
$sql4="SELECT * FROM user_object_events WHERE object_id = $obj[id]";
|
||
$rez_events=$pdo->query($sql4);
|
||
while($event = $pdo->fetch_assoc($rez_events)) {
|
||
$address = 'NULL';
|
||
if ($event['address']) {
|
||
$address = "'$event[address]'";
|
||
}
|
||
|
||
$sum = 'NULL';
|
||
if ($event['sum']) {
|
||
$sum = "'$event[sum]'";
|
||
}
|
||
|
||
$schDate = 'NULL';
|
||
if ($event['schedule_date']) {
|
||
$schDate = "'$event[schedule_date]'";
|
||
}
|
||
|
||
$comment = 'NULL';
|
||
if ($event['comment']) {
|
||
$comment = "'$event[comment]'";
|
||
}
|
||
|
||
$sql = "INSERT INTO user_object_events(user_id, object_id, create_date, type, address, sum, schedule_date, comment, calendar_view)
|
||
VALUES($id_add_user_new, '$id', '$event[create_date]', '$event[type]', $address, $sum, $schDate, $comment, '$event[calendar_view]')";
|
||
$pdo->query($sql);
|
||
}
|
||
|
||
//переносим примечания
|
||
$sql5 = "SELECT * FROM object_notes WHERE object_id = $obj[id]";
|
||
$rez_notes = $pdo->query($sql5);
|
||
while($note = $pdo->fetch_assoc($rez_notes)) {
|
||
$sql = "INSERT INTO object_notes(object_id, message, created_at, created_by, updated_at, updated_by)
|
||
VALUES($id, '$note[message]', '$note[created_at]', '$note[created_by]', '$note[updated_at]', '$note[updated_by]')";
|
||
$pdo->query($sql);
|
||
}
|
||
|
||
//break;
|
||
}
|
||
|
||
/* $sql = "SELECT * FROM `mango_calls` WHERE `vpbx_id`='+79229765337'";
|
||
$q = $pdo->query($sql);
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
if($r['client_id'] > 0){
|
||
$pdo->query("UPDATE user_client_events SET `from_id` = '13420' WHERE client_id={$r['client_id']} and megafon=1");
|
||
|
||
}
|
||
$pdo->query("update `user_call` SET `user_id` = '13420' WHERE call_id = {$r['id']}");
|
||
}*/
|
||
|
||
|
||
/* $sql_del = "SELECT id FROM clients WHERE integration=2";
|
||
$q_del = $pdo->query($sql_del);
|
||
while($r_del = $pdo->fetch_assoc($q_del)){
|
||
$client_id=(int)$r_del['id'];
|
||
$pdo->query("DELETE FROM `clients` WHERE id = {$client_id}");
|
||
$pdo->query("DELETE FROM requisitions WHERE client_id = {$client_id}");
|
||
|
||
}*/
|
||
$number=0;
|
||
// for($num=1; $num<=6; $num++){
|
||
$filepath = $_SERVER['DOCUMENT_ROOT']."/upload/clients_trend/clients_22666.xlsx";
|
||
//echo $filepath."\n";
|
||
require_once $_SERVER['DOCUMENT_ROOT'] . '/engine/classes/phpexcel/Classes/PHPExcel/IOFactory.php';
|
||
//require_once $_SERVER['DOCUMENT_ROOT'] . '/engine/classes/phpexcel/Classes/PHPExcel/PHPExcel_Shared_Date.php';
|
||
$type = PHPExcel_IOFactory::identify($filepath);
|
||
$objReader = PHPExcel_IOFactory::createReader($type);
|
||
|
||
$objPHPExcel = $objReader->load($filepath);
|
||
|
||
$rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator();
|
||
foreach($rowIterator as $row){
|
||
$cellIterator = $row->getCellIterator();
|
||
foreach ($cellIterator as $cell) {
|
||
$clients[$row->getRowIndex()][$cell->getColumn()] = $cell->getCalculatedValue();
|
||
/* if($cell->getColumn() == 'A' && !empty($clients[$row->getRowIndex()][$cell->getColumn()])){
|
||
//var_dump($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
$clients[$row->getRowIndex()][$cell->getColumn()] = PHPExcel_Shared_String::ControlCharacterOOXML2PHP($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
} */
|
||
/* if($cell->getColumn() == 'H' && !empty($clients[$row->getRowIndex()][$cell->getColumn()])){
|
||
//var_dump($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
$clients[$row->getRowIndex()][$cell->getColumn()] = PHPExcel_Shared_Date::ExcelToPHP($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
} */
|
||
/* if($cell->getColumn() == 'A' && !empty($clients[$row->getRowIndex()][$cell->getColumn()])){
|
||
//var_dump($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
$clients[$row->getRowIndex()][$cell->getColumn()] = PHPExcel_Shared_Date::ExcelToPHP($clients[$row->getRowIndex()][$cell->getColumn()]);
|
||
} */
|
||
}
|
||
}
|
||
|
||
//var_dump($clients);
|
||
|
||
$agency_id = 22666;
|
||
$allClients = array();
|
||
$total = 0;
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* $sql_client = "SELECT * FROM requisitions WHERE (user_id in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))) or who_work in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))))";
|
||
|
||
$q_client=mysql_query($sql_client);
|
||
while($r_client = mysql_fetch_assoc($q_client)){
|
||
var_dump($r_client['id']);
|
||
$sql = "SELECT id FROM clients WHERE id = {$r_client['client_id']}";
|
||
// echo $sql;
|
||
$q= mysql_query($sql);
|
||
if(mysql_num_rows($q) == 0){
|
||
var_dump($r_client['id']);
|
||
$total++;
|
||
}
|
||
}*/
|
||
|
||
//if(isset($phone) && !empty($phone)){
|
||
|
||
/* $sql_client = "SELECT * FROM clients WHERE deleted=0 and (id_agent in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))) or who_work in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))))";
|
||
// echo $sql_client."\n";
|
||
$q_client=mysql_query($sql_client);
|
||
// $phone = '';
|
||
while($r_client = mysql_fetch_assoc($q_client)){
|
||
//var_dump($r_client['id']);
|
||
if(!in_array($r_client['phone'],$allClients)){
|
||
$total++;
|
||
$allClients[$r_client['phone']] = $r_client;
|
||
}
|
||
|
||
}
|
||
|
||
// echo $total;
|
||
// }
|
||
//Все клиенты
|
||
|
||
$allUsers = array();
|
||
$usersIds = array();
|
||
$requisitions = array();
|
||
// $allObjects = array();
|
||
/* $sql_client = "SELECT *, (SELECT phone FROM clients WHERE requisitions.client_id = clients.id) as phone FROM requisitions WHERE integration = 3 and (user_id in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))) or who_work in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id))))";
|
||
//echo $sql_client."\n";
|
||
$q_client = $pdo->query($sql_client);
|
||
// echo $pdo->num_rows($q_client);
|
||
while($r_client = $pdo->fetch_assoc($q_client)){
|
||
// $sql_up = "UPDATE requisitions SET who_delete = '{$r_client['who_work']}' WHERE id = {$r_client['id']}";
|
||
//echo $sql_up."\n";
|
||
//$pdo->query($sql_up);
|
||
$requisitions[$r_client['id']] = $r_client;
|
||
}*/
|
||
// var_dump($requisitions);
|
||
/* $sql_obj = "SELECT * FROM `bnru_objects` WHERE old={$agency_id}";
|
||
$q_obj = $pdo->query($sql_obj);
|
||
while($r_obj = $pdo->fetch_assoc($q_obj)){
|
||
$allObjects[$r_obj['internal_id_guid']] = $r_obj;
|
||
}*/
|
||
|
||
$sql_u = "SELECT * FROM users WHERE id in (select id from users where id=$agency_id or id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id or id_manager in
|
||
(select id from users where id_manager=$agency_id)))";
|
||
//echo $sql_u."\n";
|
||
|
||
$q_u = $pdo->query($sql_u);
|
||
while($r_u = $pdo->fetch_assoc($q_u)){
|
||
$allUsers[$r_u['phone']] = $r_u;
|
||
$usersIds[] = (int)$r_u['id'];
|
||
}
|
||
|
||
echo json_encode($usersIds);
|
||
|
||
|
||
|
||
/*$sql_req = "SELECT *, if((SELECT date_update from events_clients WHERE req.id=events_clients.req_id AND (event = 'accepted' OR event = 'restored' OR event = 'accepted_doer') order by id desc limit 1) > req.created_at,(SELECT date_update from events_clients where req.id=events_clients.req_id AND (event = 'accepted' OR event = 'restored' OR event = 'accepted_doer' OR event = 'delete') order by id desc limit 1), req.created_at) as date_update FROM requisitions as req WHERE user_id in (".implode(',', $usersIds).")";
|
||
$q_req = $pdo->query($sql_req);
|
||
while($r_req = $pdo->fetch_assoc($q_req)){
|
||
echo $r_req['id'].'--'.$r_req['date_update'] . "\n";
|
||
$sql_up = "UPDATE requisitions SET updated_at = '{$r_req['date_update']}' WHERE id = {$r_req['id']}";
|
||
$pdo->query($sql_up);
|
||
}*/
|
||
|
||
// die();
|
||
|
||
|
||
/* $usersIds = array();
|
||
$agentsOfAgency = User::getAgentsOfManager($agency_id, true);
|
||
foreach($agentsOfAgency as $ag){
|
||
$usersIds[] = $ag['id'];
|
||
}
|
||
|
||
$agentsOfManager = User::getAllManagers($agency_id);
|
||
|
||
foreach($agentsOfManager as $manager){
|
||
$usersIds[] = $manager['id'];
|
||
$agentsOfAgency = User::getAgentsOfManager($manager['id'], true);
|
||
foreach($agentsOfAgency as $ag){
|
||
$usersIds[] = $ag['id'];
|
||
}
|
||
}
|
||
|
||
echo json_encode($usersIds); */
|
||
//die();
|
||
$num = 0;
|
||
|
||
/* $sql = "SELECT id FROM objects WHERE id_add_user in (".implode(',', $usersIds).") limit 1000";
|
||
|
||
$q = $db_sphinx->query($sql, true);
|
||
|
||
while($r = $db_sphinx->fetch_assoc($q)){
|
||
$objectId = (int)$r['id'];
|
||
$sql_req = "SELECT * FROM `requisitions` WHERE type_id = 2 AND object_id = {$r['id']} AND cancel=0 and deleted=0";
|
||
$q_req = $pdo->query($sql_req, true);
|
||
if($pdo->num_rows($q_req) > 0){
|
||
$r_req = $pdo->fetch_assoc($q_req);
|
||
$sql_cl_obj = "SELECT * FROM client_objects WHERE client_id = {$r_req['client_id']} AND object_id = {$r['id']}";
|
||
$q_cl_obj = $pdo->query($sql_cl_obj, true);
|
||
if($pdo->num_rows($q_cl_obj) == 0){
|
||
echo $r['id']."\n";
|
||
$sql_cl = "SELECT * FROM clients WHERE id = {$r_req['client_id']}";
|
||
$q_cl = $pdo->query($sql_cl);
|
||
$r_client = $pdo->fetch_assoc($q_cl);
|
||
$arrObj = json_decode(html_entity_decode($r_client['objects']), ENT_QUOTES);
|
||
$arrObj[] = (string)$objectId;
|
||
|
||
|
||
if(!empty($arrObj)){
|
||
var_dump($arrObj);
|
||
$arrObj = array_unique($arrObj);
|
||
$objList = htmlentities(json_encode($arrObj));
|
||
$up_client = "UPDATE clients SET objects='$objList' where id = {$r_req['client_id']}";
|
||
echo $up_client."\n";
|
||
$pdo->query($up_client, true);
|
||
}
|
||
|
||
$cl = new Clients();
|
||
$cl->update_objects($r_req['client_id'], null, $arrObj);
|
||
$total++;
|
||
//break;
|
||
}
|
||
}
|
||
|
||
} */
|
||
|
||
/* echo $total;
|
||
|
||
die(); */
|
||
// var_dump($allUsers);
|
||
|
||
/* $sql = "SELECT * FROM `user_client_events` where `user_id` in (".implode(',', $usersIds).")";
|
||
echo $sql;*/
|
||
/* $q = $pdo->query($sql);
|
||
while($r = $pdo->fetch_assoc($q)){
|
||
if($r['req_id'] > 0){
|
||
$sql_r = "SELECT id FROM requisitions WHERE id = {$r['req_id']}";
|
||
$q_r = $pdo->query($sql_r);
|
||
if($pdo->num_rows($q_r) == 0){
|
||
$sql_delete = "DELETE FROM user_client_events WHERE id = {$r['id']}";
|
||
$pdo->query($sql_delete);
|
||
echo $sql_delete."\n";
|
||
$num++;
|
||
}
|
||
}
|
||
}
|
||
|
||
echo $num;
|
||
*/ //var_dump($clients);
|
||
//die();
|
||
$mango = new MangoApiClass(0, 0);
|
||
if(!empty($clients)){
|
||
foreach($clients as $key => $client){
|
||
|
||
if($key > 1){
|
||
// if(isset($allObjects[$client['A']])){
|
||
// var_dump($client['C']);
|
||
$fio = trim(str_replace('"','',$client['B']));
|
||
$phone = '+'. str_replace('+','',$client['D']);
|
||
$firstChar = substr($phone, 0, 1);
|
||
|
||
if(empty($phone)) die();
|
||
|
||
//echo $phone; die();
|
||
|
||
if(empty($fio)) $fio = "Без имени";
|
||
$fioReq = 'Подбор объекта для '.$fio;
|
||
/* if(!empty($client['B'])){
|
||
$fioReq = trim(str_replace('"','',$client['B']));
|
||
}*/
|
||
$type_id = 1;
|
||
|
||
$role = '';
|
||
if(!empty($client['C'])){
|
||
$role = "["".$client['C'].""]";
|
||
}
|
||
$objectId = 0;
|
||
$email = '';
|
||
if(!empty($client['E'])){
|
||
$email = trim($client['E']);
|
||
}
|
||
//$work_type = "["".$client['D'].""]";
|
||
//$arrObj = array();
|
||
/*$objList = '';
|
||
$objectZ = $client['A'];
|
||
|
||
|
||
$sql_o = "SELECT * FROM bnru_objects WHERE internal_id = '{$objectZ}' AND user_id in (".implode(',', $usersIds).")";
|
||
echo $sql_o."\n";
|
||
$q_o = $pdo->query($sql_o);
|
||
$r_o = $pdo->fetch_assoc($q_o);*/
|
||
if(!empty($client['I'])){
|
||
$objectId = (int)$client['I'];
|
||
}
|
||
|
||
if($objectId > 0){
|
||
$type_id = 4;
|
||
$fioReq = 'Спрос по нашему объекту для '.$fio;
|
||
}
|
||
|
||
//if($objectId == 0) echo "\n****".$objectZ."********\n";
|
||
echo $client['A']."\n";
|
||
$date_add_temp = strtotime($client['A']);
|
||
|
||
if($date_add_temp > 0){
|
||
$date_add = date('Y-m-d H:i:s', $date_add_temp);
|
||
} else {
|
||
$date_add = 0;
|
||
}
|
||
|
||
$user_id = $agency_id;
|
||
$who_work = $agency_id;
|
||
$client_p =$mango->ver_phone(trim($client['F']));
|
||
//echo $client_p."\n";
|
||
//echo strlen($client_p)."\n";
|
||
if(isset($allUsers[$client_p])){
|
||
$user_id = $allUsers[$client_p]['id'];
|
||
$who_work = $allUsers[$client_p]['id'];
|
||
}
|
||
if(empty($user_id)) {
|
||
$user_id = $agency_id;
|
||
$who_work = $agency_id;
|
||
}
|
||
|
||
/*$sql_obj_up = "UPDATE objects SET id_add_user={$user_id} WHERE id = {$objectId}";
|
||
echo "\n\n".$sql_obj_up."\n\n";*/
|
||
//$pdo->query($sql_obj_up);
|
||
// $db_sphinx->query($sql_obj_up);
|
||
|
||
$source_id = 0;
|
||
/*if(!empty($client['G'])) {
|
||
$source_id = (int)$client['G'];
|
||
}*/
|
||
$source = $client['G'];
|
||
$r_source = null;
|
||
if(!empty($source)){
|
||
|
||
$sql_source = "SELECT * FROM `advertising_sources` WHERE `source` = '{$source}' and user_id in (".implode(',',$usersIds).")";
|
||
echo $sql_source."\n";
|
||
|
||
$q_source = $pdo->query($sql_source);
|
||
if($pdo->num_rows($q_source) > 0) {
|
||
$r_source = $pdo->fetch_assoc($q_source);
|
||
$source_id = (int)$r_source['id'];
|
||
} else {
|
||
$sql_source_in = "INSERT INTO advertising_sources (user_id,manager_id, `source`) VALUES ({$agency_id}, {$agency_id}, '{$source}')";
|
||
$pdo->query($sql_source_in);
|
||
$source_id = $pdo->insert_id();
|
||
}
|
||
}
|
||
|
||
$opis = "По файлу от агенства.";
|
||
if(!empty($client['H'])){
|
||
$opis = mysql_real_escape_string($client['H']);
|
||
}
|
||
|
||
$arrObj = array();
|
||
|
||
$funnel_id_req = 2095;
|
||
$confirm = 1;
|
||
$deleted = 1;
|
||
/* if($client['G'] && (int)$client['G'] > 0){
|
||
$deleted = 1;
|
||
|
||
}*/
|
||
//$denial = 0;
|
||
/*if($client['D']){
|
||
$denial = (int)$client['D'];
|
||
} */
|
||
|
||
$activities_ids = array();
|
||
/*if($client['I'] > 0){
|
||
$activities_ids[] = (int)$client['I'];
|
||
}*/
|
||
/*if($source_id > 0){
|
||
$sql_aa = "SELECT * FROM advertising_sources_activities WHERE source_id = {$source_id}";
|
||
|
||
$q_aa = $pdo->query($sql_aa, true);
|
||
while($r_aa = $pdo->fetch_assoc($q_aa)) {
|
||
$activities_ids[] = (int)$r_aa['activities_id'];
|
||
}
|
||
// var_dump($activities_ids);
|
||
}*/
|
||
|
||
$hot = 0;
|
||
// $sql_source = "SELECT * FROM advertising_sources WHERE id = {$source_id}";
|
||
//echo $sql_source."\n";
|
||
// $q_source = $pdo->query($sql_source, true);
|
||
//$r_source = $pdo->fetch_assoc($q_source);
|
||
// var_dump($r_source);
|
||
/* if($r_source['group_id'] == 290){
|
||
$hot = 1;
|
||
} */
|
||
//die();
|
||
$sql_client = "SELECT * FROM clients WHERE phone='{$phone}' AND (id_agent in (".implode(',',$usersIds).") or who_work in (".implode(',',$usersIds)."))";
|
||
//echo $sql_client."\n";
|
||
$q_client=$pdo->query($sql_client, true);
|
||
if($pdo->num_rows($q_client) > 0){
|
||
$r_client = $pdo->fetch_assoc($q_client);
|
||
//if($pdo->num_rows($q_client) > 0){
|
||
/*$r_client = $pdo->fetch_assoc($q_client);
|
||
$client_id = (int)$r_client['id'];
|
||
$arrObj = json_decode(html_entity_decode($r_client['objects']), ENT_QUOTES);*/
|
||
//var_dump($arrObj);
|
||
//}
|
||
/* $arrObj[] = (string)$allObjects[$client['A']]['object_id'];
|
||
if(!empty($arrObj)){
|
||
var_dump($arrObj);
|
||
$arrObj = array_unique($arrObj);
|
||
$objList = htmlentities(json_encode($arrObj));
|
||
$up_client = "UPDATE clients SET objects='$objList' where id = $client_id";
|
||
echo $up_client."\n";
|
||
// $pdo->query($up_client);
|
||
}*/
|
||
$objList = '';
|
||
$client_id = (int)$r_client['id'];
|
||
/*$arrObj = json_decode(html_entity_decode($r_client['objects']), ENT_QUOTES);
|
||
$arrObj[] = (string)$objectId;
|
||
|
||
|
||
if(!empty($arrObj)){
|
||
var_dump($arrObj);
|
||
$arrObj = array_unique($arrObj);
|
||
$objList = htmlentities(json_encode($arrObj));
|
||
$up_client = "UPDATE clients SET objects='$objList' where id = $client_id";
|
||
echo $up_client."\n";
|
||
$pdo->query($up_client);
|
||
} */
|
||
|
||
$cl = new Clients();
|
||
//$cl->update_objects($client_id, null, $arrObj);
|
||
|
||
|
||
|
||
|
||
// if($objectId > 0){
|
||
|
||
$sqlr = "INSERT INTO requisitions SET client_id={$client_id}, object_id={$objectId}, name='{$fioReq}', description='{$opis}',
|
||
user_id={$user_id}, who_work={$who_work}, type_id={$type_id}, confirm={$confirm}, funnel_id={$funnel_id_req},
|
||
deleted='{$deleted}', stage=1, source='{$source_id}', integration=103";
|
||
|
||
if($date_add != 0){
|
||
$sqlr .= ", created_at='{$date_add}'";
|
||
}
|
||
|
||
if($deleted > 0){
|
||
$sqlr .= ", who_delete ='{$user_id}'";
|
||
}
|
||
echo $sqlr."\n";
|
||
//$number++;
|
||
|
||
// $pdo->query($sqlr, true);
|
||
$req_id = $pdo->insert_id();
|
||
|
||
/* if($client['D']){
|
||
$step_id = (int)$client['D'];
|
||
$next_step_id = (int)$client['C'];
|
||
if($step_id > 0){
|
||
$sql_step = "INSERT INTO `clients_funnel_step`(`step_id`, `req_id`, `next_id`, `prev_id`) VALUES
|
||
({$step_id}, {$req_id}, {$next_step_id}, {$step_id})";
|
||
$pdo->query($sql_step);
|
||
}
|
||
} */
|
||
if($req_id>0 && $funnel_id_req > 0){
|
||
$Requisitions = new Requisitions();
|
||
$Requisitions->get_class_etap($req_id, $funnel_id_req);
|
||
}
|
||
|
||
if($activities_ids && !empty($activities_ids)){
|
||
foreach($activities_ids as $activities_id){
|
||
$sql_a = "INSERT INTO `requisitions_activities` (`activity_id`, `req_id`) VALUES ({$activities_id}, {$req_id})";
|
||
echo $sql_a;
|
||
//$pdo->query($sql_a);
|
||
}
|
||
}
|
||
|
||
if($deleted > 0){
|
||
|
||
$sql_del = "INSERT INTO `events_clients`(`user_id`, `req_id`, `from_id`, `event`, `dop_text`, `send_telegramm`, `read`, `viewed`, `funnel_type`, `date`, `date_update`) VALUES
|
||
({$user_id}, {$req_id}, {$user_id}, 'delete', '', 0, 1, 0, 'main', '{$date_add}', '{$date_add}')";
|
||
echo $sql_del."\n";
|
||
// $pdo->query($sql_del);
|
||
|
||
//}
|
||
|
||
}
|
||
|
||
$arr_data = array();
|
||
|
||
/* if(!empty($client['G']) && $client['G'] !== '-'){
|
||
$value = $client['G'];
|
||
$arr_data[] = "({$req_id}, 380, 1, '\"{$value}\"')";
|
||
}
|
||
var_dump($client['H']);
|
||
if(!empty($client['H']) && $client['H'] !== '-'){
|
||
$value = date('d.m.Y',$client['H']);
|
||
$arr_data[] = "({$req_id}, 381, 1, '\"{$value}\"')";
|
||
}
|
||
if(!empty($client['I']) && $client['I'] !== '-'){
|
||
$value = $client['I'];
|
||
$arr_data[] = "({$req_id}, 382, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['J']) && $client['J'] !== '-'){
|
||
$value = $client['J'];
|
||
$arr_data[] = "({$req_id}, 383, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['K']) && $client['K'] !== '-'){
|
||
$value = $client['K'];
|
||
$arr_data[] = "({$req_id}, 384, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['L']) && $client['L'] !== '-'){
|
||
$value = $client['L'];
|
||
$arr_data[] = "({$req_id}, 385, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['M']) && $client['M'] !== '-'){
|
||
$value = $client['M'];
|
||
$arr_data[] = "({$req_id}, 386, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['N']) && $client['N'] !== '-'){
|
||
$value = $client['N'];
|
||
$arr_data[] = "({$req_id}, 387, 1, '{$value}')";
|
||
}
|
||
|
||
if(!empty($client['O']) && $client['O'] !== '-'){
|
||
$value = $client['O'];
|
||
$arr_data[] = "({$req_id}, 408, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['P']) && $client['P'] !== '-'){
|
||
$value = $client['P'];
|
||
$arr_data[] = "({$req_id}, 409, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['Q']) && $client['Q'] !== '-'){
|
||
$value = $client['Q'];
|
||
$arr_data[] = "({$req_id}, 412, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AB']) && $client['AB'] !== '-'){
|
||
$value = $client['AB'];
|
||
$arr_data[] = "({$req_id}, 413, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
|
||
if(!empty($arr_data)){
|
||
$sql_data = "INSERT INTO requisition_data (`req_id`, `field_id`, `type`, `value`) VALUES ".implode(',' , $arr_data);
|
||
}
|
||
var_dump($arr_data);
|
||
// echo $sql_data."\n";
|
||
$pdo->query($sql_data);*/
|
||
} else {
|
||
|
||
// if(isset($allClients[$phone])){
|
||
//echo $allClients[$phone]."\n";
|
||
// else {
|
||
// $client_id = (int)$allClients[$phone]['id'];
|
||
|
||
|
||
$birthday = '';
|
||
/*if(!empty($client['D'])){
|
||
$birthday = $client['D'];
|
||
}*/
|
||
|
||
$deleted = 0;
|
||
/*if(trim($client['E']) == 'Архив'){
|
||
$deleted = 1;
|
||
}*/
|
||
$objList = '';
|
||
/*$arrObj[] = (string)$objectId;
|
||
if(!empty($arrObj)){
|
||
$arrObj = array_unique($arrObj);
|
||
$objList = htmlentities(json_encode($arrObj));
|
||
} */
|
||
|
||
|
||
|
||
|
||
$confirm=1;
|
||
|
||
|
||
|
||
|
||
$insetrC = "INSERT INTO clients SET phone='{$phone}', fio='{$fio}', email='{$email}', objects='$objList', opis='{$opis}', deleted='{$deleted}', id_agent={$user_id}, who_work={$who_work}, confirm={$confirm}, stage=1, source={$source_id}, role='$role', integration=103";
|
||
if($date_add != 0){
|
||
$insetrC .= ", date_add='{$date_add}'";
|
||
} else {
|
||
$insetrC .= ", date_add=NOW()";
|
||
}
|
||
echo $insetrC."\n";
|
||
// $pdo->query($insetrC);
|
||
|
||
$client_id = $pdo->insert_id();
|
||
|
||
/* if($deleted > 0 && $client_id > 0){
|
||
|
||
$sql_del = "INSERT INTO `events_clients`(`user_id`, `client_id`, `from_id`, `event`, `dop_text`, `send_telegramm`, `read`, `viewed`, `funnel_type`) VALUES
|
||
({$user_id}, {$client_id}, {$user_id}, 'delete', '', 0, 1, 0, 'main')";
|
||
$pdo->query($sql_del);
|
||
|
||
}*/
|
||
|
||
if($activities_ids && !empty($activities_ids)){
|
||
foreach($activities_ids as $activities_id){
|
||
$sql_a = "INSERT INTO `clients_activities` (`activity_id`, `client_id`) VALUES ({$activities_id}, {$client_id})";
|
||
echo $sql_a;
|
||
//$pdo->query($sql_a);
|
||
}
|
||
}
|
||
//$number++;
|
||
/*if(!empty($birthday)){
|
||
$insetrC .= ", birthday='{$birthday}'";
|
||
}*/
|
||
//echo $insetrC."\n";
|
||
/*if(!empty($arrObj)){
|
||
$cl = new Clients();
|
||
$cl->update_objects($client_id, null, $arrObj);
|
||
} */
|
||
$funnel_id_req = 2095;
|
||
$confirm = 1;
|
||
$deleted = 0;
|
||
/* if($client['G'] && (int)$client['G'] > 0){
|
||
$deleted = 1;
|
||
/*if((int)$client['C'] == 10){
|
||
$confirm = 10;
|
||
} */
|
||
/* }
|
||
//$denial = 0;
|
||
/*if($client['D']){
|
||
$denial = (int)$client['D'];
|
||
} */
|
||
|
||
|
||
|
||
|
||
|
||
|
||
$sqlr = "INSERT INTO requisitions SET client_id={$client_id}, object_id={$objectId}, name='{$fioReq}', description='{$opis}',
|
||
user_id={$user_id}, who_work={$who_work}, type_id={$type_id}, confirm={$confirm}, funnel_id={$funnel_id_req},
|
||
deleted='{$deleted}', stage=1, source='{$source_id}', integration=103";
|
||
if($date_add != 0){
|
||
$sqlr .= ", created_at='{$date_add}'";
|
||
}
|
||
|
||
/* if($deleted > 0){
|
||
$sqlr .= ", who_delete ='{$user_id}'";
|
||
}
|
||
echo "****";*/
|
||
echo $sqlr."\n";
|
||
|
||
// $pdo->query($sqlr);
|
||
// $req_id = $pdo->insert_id();
|
||
|
||
/*if($client['D']){
|
||
$step_id = (int)$client['D'];
|
||
$next_step_id = (int)$client['C'];
|
||
if($step_id > 0){
|
||
$sql_step = "INSERT INTO `clients_funnel_step`(`step_id`, `req_id`, `next_id`, `prev_id`) VALUES
|
||
({$step_id}, {$req_id}, {$next_step_id}, {$step_id})";
|
||
$pdo->query($sql_step);
|
||
}
|
||
}*/
|
||
if($req_id>0 && $funnel_id_req > 0){
|
||
$Requisitions = new Requisitions();
|
||
$Requisitions->get_class_etap($req_id, $funnel_id_req);
|
||
}
|
||
|
||
if($activities_ids && !empty($activities_ids)){
|
||
foreach($activities_ids as $activities_id){
|
||
$sql_a = "INSERT INTO `requisitions_activities` (`activity_id`, `req_id`) VALUES ({$activities_id}, {$req_id})";
|
||
echo $sql_a;
|
||
// $pdo->query($sql_a);
|
||
}
|
||
}
|
||
|
||
/* if($deleted > 0){
|
||
|
||
$sql_del = "INSERT INTO `events_clients`(`user_id`, `req_id`, `from_id`, `event`, `dop_text`, `send_telegramm`, `read`, `viewed`, `funnel_type`) VALUES
|
||
({$user_id}, {$req_id}, {$user_id}, 'delete', '', 0, 1, 0, 'main')";
|
||
$pdo->query($sql_del);
|
||
|
||
}*/
|
||
/*$arr_data = array();
|
||
|
||
if(!empty($client['G']) && $client['G'] !== '-'){
|
||
$value = $client['G'];
|
||
$arr_data[] = "({$req_id}, 380, 1, '\"{$value}\"')";
|
||
}
|
||
var_dump($client['H']);
|
||
if(!empty($client['H']) && $client['H'] !== '-'){
|
||
$value = date('d.m.Y',$client['H']);
|
||
$arr_data[] = "({$req_id}, 381, 1, '\"{$value}\"')";
|
||
}
|
||
if(!empty($client['I']) && $client['I'] !== '-'){
|
||
$value = $client['I'];
|
||
$arr_data[] = "({$req_id}, 382, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['J']) && $client['J'] !== '-'){
|
||
$value = $client['J'];
|
||
$arr_data[] = "({$req_id}, 383, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['K']) && $client['K'] !== '-'){
|
||
$value = $client['K'];
|
||
$arr_data[] = "({$req_id}, 384, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['L']) && $client['L'] !== '-'){
|
||
$value = $client['L'];
|
||
$arr_data[] = "({$req_id}, 385, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['M']) && $client['M'] !== '-'){
|
||
$value = $client['M'];
|
||
$arr_data[] = "({$req_id}, 386, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['N']) && $client['N'] !== '-'){
|
||
$value = $client['N'];
|
||
$arr_data[] = "({$req_id}, 387, 1, '{$value}')";
|
||
}
|
||
|
||
if(!empty($client['O']) && $client['O'] !== '-'){
|
||
$value = $client['O'];
|
||
$arr_data[] = "({$req_id}, 408, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['P']) && $client['P'] !== '-'){
|
||
$value = $client['P'];
|
||
$arr_data[] = "({$req_id}, 409, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['Q']) && $client['Q'] !== '-'){
|
||
$value = $client['Q'];
|
||
$arr_data[] = "({$req_id}, 412, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AB']) && $client['AB'] !== '-'){
|
||
$value = $client['AB'];
|
||
$arr_data[] = "({$req_id}, 413, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
/*if(!empty($client['O']) && $client['O'] !== '-'){
|
||
$value = $client['O'];
|
||
$arr_data[] = "({$req_id}, 311, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['P']) && $client['P'] !== '-'){
|
||
$value = $client['P'];
|
||
$arr_data[] = "({$req_id}, 312, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['Q']) && $client['Q'] !== '-'){
|
||
$value = $client['Q'];
|
||
$arr_data[] = "({$req_id}, 313, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['R']) && $client['R'] !== '-'){
|
||
$value = $client['R'];
|
||
$arr_data[] = "({$req_id}, 314, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['S']) && $client['S'] !== '-'){
|
||
$value = $client['S'];
|
||
$arr_data[] = "({$req_id}, 315, 1,'\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['T']) && $client['T'] !== '-'){
|
||
$value = $client['T'];
|
||
$arr_data[] = "({$req_id}, 316, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['U']) && $client['U'] !== '-'){
|
||
$value = $client['U'];
|
||
$arr_data[] = "({$req_id}, 317, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['V']) && $client['V'] !== '-'){
|
||
$value = $client['V'];
|
||
$arr_data[] = "({$req_id}, 318, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['W']) && $client['W'] !== '-'){
|
||
$value = $client['W'];
|
||
$arr_data[] = "({$req_id}, 319, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['X']) && $client['X'] !== '-'){
|
||
$value = $client['X'];
|
||
$arr_data[] = "({$req_id}, 320, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['Y']) && $client['Y'] !== '-'){
|
||
$value = $client['Y'];
|
||
$arr_data[] = "({$req_id}, 321, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['Z']) && $client['Z'] !== '-'){
|
||
$value = $client['Z'];
|
||
$arr_data[] = "({$req_id}, 325, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AA']) && $client['AA'] !== '-'){
|
||
$value = $client['AA'];
|
||
$arr_data[] = "({$req_id}, 322, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AB']) && $client['AB'] !== '-'){
|
||
$value = $client['AB'];
|
||
$arr_data[] = "({$req_id}, 323, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AC']) && $client['AC'] !== '-'){
|
||
$value = $client['AC'];
|
||
$arr_data[] = "({$req_id}, 324, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AE']) && $client['AE'] !== '-'){
|
||
$value = $client['AE'];
|
||
$arr_data[] = "({$req_id}, 307, 1, '\"{$value}\"')";
|
||
}
|
||
|
||
if(!empty($client['AF']) && $client['AF'] !== '-'){
|
||
$value = $client['AF'];
|
||
$arr_data[] = "({$req_id}, 308, 1, '\"{$value}\"')";
|
||
} */
|
||
|
||
|
||
/* if(!empty($arr_data)){
|
||
$sql_data = "INSERT INTO requisition_data (`req_id`, `field_id`, `type`, `value`) VALUES ".implode(',' , $arr_data);
|
||
}
|
||
var_dump($arr_data);
|
||
echo $sql_data."\n";
|
||
|
||
$pdo->query($sql_data); */
|
||
/* $number++; */
|
||
}
|
||
|
||
/* if($client_id > 0){
|
||
$sql_dop = "SELECT * FROM `clients_dop_info` WHERE client_id = {$client_id}";
|
||
$q_dop = mysql_query($sql_dop);
|
||
if(mysql_num_rows($q_dop) > 0){
|
||
$seter = array();
|
||
if(!empty($client['T']) && $client['Т'] == 'женский'){
|
||
$seter[] = 'persone_gender=1';
|
||
}
|
||
if(!empty($client['U'])){
|
||
$seter[] = "persone_nationality='{$client['U']}'";
|
||
}
|
||
if(!empty($client['V'])){
|
||
$number = $client['V'].'/'.$client['W'];
|
||
$seter[] = "passport='{$number}'";
|
||
}
|
||
if(!empty($client['X'])){
|
||
|
||
$seter[] = "passport_issued_by='{$client['X']}'";
|
||
}
|
||
if(!empty($client['Y'])){
|
||
$d = date('d.m.Y', $client['Y']);
|
||
$seter[] = "date_of_issue_passport='{$d}'";
|
||
}
|
||
if(!empty($client['Z'])){
|
||
|
||
$seter[] = "persone_kod_podrazdelenia='{$client['Z']}'";
|
||
}
|
||
if(!empty($client['AA'])){
|
||
|
||
$seter[] = "registration_address='{$client['AA']}'";
|
||
}
|
||
|
||
if(!empty($seter)){
|
||
$sql_up = "UPDATE clients_dop_info SET ".implode(',', $seter)." WHERE client_id = {$client_id}";
|
||
echo $sql_up."\n";
|
||
$pdo->query($sql_up);
|
||
}
|
||
|
||
} else {
|
||
$keys = [];
|
||
$seter = array();
|
||
if(!empty($client['T']) && $client['T'] == 'женский'){
|
||
$keys[] = 'persone_gender';
|
||
$seter[] = '1';
|
||
}
|
||
if(!empty($client['U'])){
|
||
$keys[] = 'persone_nationality';
|
||
$seter[] = "'{$client['U']}'";
|
||
}
|
||
if(!empty($client['V'])){
|
||
$number_pas = $client['V'].'/'.$client['W'];
|
||
$keys[] = "passport";
|
||
$seter[] = "'{$number_pas}'";
|
||
}
|
||
if(!empty($client['X'])){
|
||
$keys[] = "passport_issued_by";
|
||
$seter[] = "'{$client['X']}'";
|
||
}
|
||
if(!empty($client['Y'])){
|
||
$d = date('d.m.Y', $client['Y']);
|
||
$keys[] = "date_of_issue_passport";
|
||
$seter[] = "'{$d}'";
|
||
}
|
||
if(!empty($client['Z'])){
|
||
$keys[] = "persone_kod_podrazdelenia";
|
||
$seter[] = "'{$client['Z']}'";
|
||
}
|
||
if(!empty($client['AA'])){
|
||
$keys[] = "registration_address";
|
||
$seter[] = "'{$client['AA']}'";
|
||
}
|
||
|
||
if(!empty($seter) && !empty($keys)){
|
||
$keys[] = "client_id";
|
||
$seter[] = $client_id;
|
||
$keys[] = "persone_no_ip";
|
||
$seter[] = 0;
|
||
|
||
$sql_in = "INSERT INTO clients_dop_info (".implode(',', $keys).") VALUES (".implode(',',$seter).")";
|
||
echo $sql_in."\n";
|
||
$pdo->query($sql_in);
|
||
}
|
||
}
|
||
}*/
|
||
|
||
|
||
$number++;
|
||
// if($number > 0) break;
|
||
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
}
|
||
|
||
//}
|
||
echo $number;
|
||
?>
|