150 lines
7.2 KiB
PHP
150 lines
7.2 KiB
PHP
|
|
<?php
|
|||
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|||
|
|
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');
|
|||
|
|
|
|||
|
|
$pdo = new MysqlPdo(hst, ndb, user, pass);
|
|||
|
|
|
|||
|
|
$sql = "SET NAMES 'utf8'";
|
|||
|
|
|
|||
|
|
$pdo->query($sql);
|
|||
|
|
$clients = array();
|
|||
|
|
|
|||
|
|
/* $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=14; $num<=15; $num++){
|
|||
|
|
$filepath = $_SERVER['DOCUMENT_ROOT']."/upload/clients_trend/portal.xlsx";
|
|||
|
|
echo $filepath."\n";
|
|||
|
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/engine/classes/phpexcel/Classes/PHPExcel/IOFactory.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();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// var_dump($clients[2]);
|
|||
|
|
|
|||
|
|
|
|||
|
|
$agency_id = 12061;
|
|||
|
|
/*if(isset($phone) && !empty($phone)){
|
|||
|
|
$sql_client = "SELECT * FROM clients WHERE phone='{$phone}' AND (id_agent in (select id from users where id=$user_id or id_manager=$user_id or id_manager in
|
|||
|
|
(select id from users where id_manager=$user_id or id_manager in
|
|||
|
|
(select id from users where id_manager=$user_id))) or who_work in (select id from users where id=$user_id or id_manager=$user_id or id_manager in
|
|||
|
|
(select id from users where id_manager=$user_id or id_manager in
|
|||
|
|
(select id from users where id_manager=$user_id))))";
|
|||
|
|
//echo $sql_client."\n";
|
|||
|
|
$q_client=mysql_query($sql_client);
|
|||
|
|
if(mysql_num_rows($q_client) > 0){*/
|
|||
|
|
//Все клиенты
|
|||
|
|
$allClients = array();
|
|||
|
|
$allUsers = array();
|
|||
|
|
$sql_client = "SELECT * FROM clients WHERE (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))))";
|
|||
|
|
$q_client = $pdo->query($sql_client);
|
|||
|
|
while($r_client = $pdo->fetch_assoc($q_client)){
|
|||
|
|
$allClients[$r_client['phone']] = $r_client;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
$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";
|
|||
|
|
/* echo $sql_u."\n";
|
|||
|
|
$q_u = $pdo->query($sql_u);
|
|||
|
|
while($r_u = $pdo->fetch_assoc($q_u)){
|
|||
|
|
$allUsers[$r_u['phone']] = $r_u;
|
|||
|
|
}*/
|
|||
|
|
|
|||
|
|
|
|||
|
|
//var_dump($clients);
|
|||
|
|
|
|||
|
|
/* if(!empty($clients)){
|
|||
|
|
foreach($clients as $key => $client){
|
|||
|
|
// echo $key." ";
|
|||
|
|
if($key> 1){
|
|||
|
|
$fio = $client['A'];
|
|||
|
|
$phone = "+".$client['B'];
|
|||
|
|
$email = $client['C'];
|
|||
|
|
$opis = $client['G'];
|
|||
|
|
|
|||
|
|
if(!isset($allClients[$phone])){
|
|||
|
|
// $client_id = $allClients[$phone]['id'];
|
|||
|
|
// if($client_id > 0){
|
|||
|
|
$user_id = 0;
|
|||
|
|
$who_delete = 0;
|
|||
|
|
if(isset($allUsers['+'.$client['F']])){
|
|||
|
|
$user_id = $allUsers['+'.$client['F']]['id'];
|
|||
|
|
$who_work = $allUsers['+'.$client['F']]['id'];
|
|||
|
|
}
|
|||
|
|
if(empty($user_id)) {
|
|||
|
|
$user_id = $agency_id;
|
|||
|
|
$who_work = $agency_id;
|
|||
|
|
}
|
|||
|
|
// $opis = $client['F'];
|
|||
|
|
$deleted = 0;
|
|||
|
|
if(trim($client['E']) == "Закрыт"){
|
|||
|
|
$deleted = 1;
|
|||
|
|
$who_delete = $who_work;
|
|||
|
|
}
|
|||
|
|
$role = "["Покупатель"]";
|
|||
|
|
|
|||
|
|
/* $confirm=1;
|
|||
|
|
$insetrC = "INSERT INTO clients SET phone='{$phone}', fio='{$fio}', email='{$email}', id_agent={$user_id}, who_work={$who_work}, date_add=NOW(), opis='{$opis}', confirm={$confirm}, who_delete={$who_delete}, deleted='{$deleted}', role='{$role}', stage=1, integration=5";
|
|||
|
|
//echo $insetrC."\n";
|
|||
|
|
$pdo->query($insetrC);
|
|||
|
|
$client_id = $pdo->insert_id();
|
|||
|
|
|
|||
|
|
if($deleted > 0 && $client_id>0){
|
|||
|
|
$sql_dop = "INSERT INTO `events_clients` (`user_id`, `client_id`, `from_id`, `event`, `dop_text`, `send_telegramm`, `read`, `date`)
|
|||
|
|
VALUES ('{$who_work}', '{$client_id}', '{$who_work}', 'delete', '', '0', '1', NOW())";
|
|||
|
|
$pdo->query($sql_dop);
|
|||
|
|
}*/
|
|||
|
|
|
|||
|
|
/* $funnel_id_req = 573;
|
|||
|
|
$sqlr = "INSERT INTO requisitions SET client_id={$client_id}, name='Подбор объекта для {$fio}', description='{$opis}', user_id={$user_id}, who_work={$who_work}, type_id=1, confirm=1, deleted='{$deleted}', funnel_id={$funnel_id_req}, stage=1, integration=3";
|
|||
|
|
// echo $sqlr."\n";
|
|||
|
|
// $pdo->query($sqlr);
|
|||
|
|
/*$req_id = $pdo->insert_id();
|
|||
|
|
|
|||
|
|
if($req_id>0 && $funnel_id_req > 0){
|
|||
|
|
$Requisitions = new Requisitions();
|
|||
|
|
$Requisitions->get_class_etap($req_id, $funnel_id_req);
|
|||
|
|
}
|
|||
|
|
$role = "["Продавец"]";
|
|||
|
|
$insetrC = "UPDATE clients SET role = '{$role}' WHERE id={$client_id}";
|
|||
|
|
$pdo->query($insetrC);
|
|||
|
|
//echo $insetrC;
|
|||
|
|
$number++;*/
|
|||
|
|
//}
|
|||
|
|
/* } else {
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
// if($key == 2) break;
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//}
|
|||
|
|
echo $number;
|
|||
|
|
?>
|