171 lines
7.0 KiB
PHP
171 lines
7.0 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');
|
|
|
|
|
|
$number=0;
|
|
//die();
|
|
// for($num=14; $num<=15; $num++){
|
|
$filepath = $_SERVER['DOCUMENT_ROOT']."/upload/clients_trend/source6.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() == 'B' && !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()]);
|
|
}
|
|
}
|
|
}
|
|
|
|
//var_dump($clients);
|
|
|
|
$agency_id = 19895;
|
|
$allClients = array();
|
|
$total = 0;
|
|
|
|
$CallEvents = new CallEvents();
|
|
$users = array_keys($CallEvents->getAllUserAgency($agency_id, $users));
|
|
|
|
foreach($clients as $key => $client) {
|
|
if($key > 1){
|
|
$source_name = trim($client['G']);
|
|
if(trim($client['H']) == "Горячие") $group_id = 290;
|
|
else if(trim($client['H']) == "Алгоритмы") $group_id = 288;
|
|
$sql_source = "SELECT * FROM advertising_sources WHERE source = '{$source_name}' AND group_id = {$group_id}";
|
|
$q_source = $pdo->query($sql_source, true);
|
|
|
|
if($pdo->num_rows($q_source) > 0){
|
|
$r_source = $pdo->fetch_assoc($q_source);
|
|
echo $source_name ." - ".$r_source['id']."\n";
|
|
} else {
|
|
|
|
$sql_in = "INSRT INTO advertising_sources (source, user_id, group_id) VALUES ('".$source_name."', 19895, {$group_id})";
|
|
|
|
$pdo->query($sql_in, true);
|
|
$source_id = $pdo->insert_id();
|
|
echo $source_name ." - ".$source_id."\n";
|
|
}
|
|
|
|
|
|
|
|
$source_id = (int)$client['P'];
|
|
$name_user = trim($client['N']);
|
|
if($source_id > 0 && !empty($name_user)){
|
|
//echo $source_id." --- ".$name_user."\n";
|
|
$sql_u = "SELECT * FROM users as u WHERE CONCAT(u.last_name, ' ', u.first_name, ' ', u.middle_name) = '{$name_user}'";
|
|
// echo $sql_u;
|
|
//$q_u = $pdo->query($sql_u);
|
|
while($r_u = $pdo->fetch_assoc($q_u)) {
|
|
|
|
|
|
if(in_array($r_u['id'], $users)){
|
|
//echo 'true'."\n";
|
|
$sql_who = "SELECT * FROM advertising_sources_who_work WHERE adv_id = {$source_id}";
|
|
if($pdo->num_rows($pdo->query($sql_who)) == 0){
|
|
$sql_in = "INSERT INTO advertising_sources_who_work (adv_id, who_work) VALUES ({$source_id}, {$r_u['id']})";
|
|
echo $sql_in."\n";
|
|
// $pdo->query($sql_in);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$domain = trim($client['Q']);
|
|
|
|
if($source_id > 0 && !empty($domain)){
|
|
$sql_d = "SELECT * FROM `advertising_sources_domain` WHERE domain = '{$domain}' and type = 1";
|
|
if($pdo->num_rows($pdo->query($sql_d)) == 0){
|
|
$sql_in = "INSERT INTO advertising_sources_domain (adv_id, domain, type) VALUES ({$source_id}, '{$domain}', 1)";
|
|
echo $sql_in."\n";
|
|
//$pdo->query($sql_in);
|
|
}
|
|
|
|
}
|
|
|
|
$url = parse_url(trim($client['D']));
|
|
$domain = $url['path'];
|
|
|
|
|
|
if($source_id > 0 && !empty($domain)){
|
|
$sql_d = "SELECT * FROM `advertising_sources_domain` WHERE domain = '{$domain}' and type = 2";
|
|
if($pdo->num_rows($pdo->query($sql_d)) == 0){
|
|
$sql_in = "INSERT INTO advertising_sources_domain (adv_id, domain, type) VALUES ({$source_id}, '{$domain}', 2)";
|
|
echo $sql_in."\n";
|
|
// $pdo->query($sql_in);
|
|
}
|
|
|
|
}
|
|
|
|
$tag = trim($client['R']);
|
|
if($source_id > 0 && !empty($tag)){
|
|
$sql_d = "SELECT * FROM `advertising_sources_tag` WHERE tag = '{$tag}'";
|
|
if($pdo->num_rows($pdo->query($sql_d)) == 0){
|
|
$sql_in = "INSERT INTO advertising_sources_tag (adv_id, tag) VALUES ({$source_id}, '{$tag}')";
|
|
echo $sql_in."\n";
|
|
//$pdo->query($sql_in);
|
|
}
|
|
|
|
}
|
|
|
|
$tag = trim($client['H']);
|
|
if($source_id > 0 && !empty($tag)){
|
|
$sql_d = "SELECT * FROM `activities` where `name` = '{$tag}' AND user_id=19895";
|
|
if($pdo->num_rows($pdo->query($sql_d, true)) == 0){
|
|
$sql_in = "INSERT INTO activities (name, user_id) VALUES ('{$tag}', 19895)";
|
|
|
|
echo $sql_in."\n";
|
|
// $pdo->query($sql_in, true);
|
|
$id_a = $pdo->insert_id();
|
|
} else {
|
|
$q_a = $pdo->query($sql_d, true);
|
|
$r_a = $pdo->fetch_assoc($q_a, true);
|
|
if($r_a['id']){
|
|
$id_a = (int)$r_a['id'];
|
|
}
|
|
}
|
|
if($id_a){
|
|
$sql_aa = "SELECT * FROM advertising_sources_activities WHERE source_id = $source_id AND activities_id = $id_a";
|
|
if($pdo->num_rows($pdo->query($sql_aa, true)) == 0){
|
|
$sql_in_aa = "INSERT INTO advertising_sources_activities (source_id, activities_id) VALUES ($source_id, $id_a)";
|
|
echo $sql_in_aa."\n";
|
|
//$pdo->query($sql_in_aa, true);
|
|
}
|
|
}
|
|
|
|
}
|
|
//$sql_user =
|
|
}
|
|
}
|
|
|
|
?>
|