101 lines
2.7 KiB
PHP
101 lines
2.7 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
|
|
|
|
set_time_limit(590);
|
|
error_reporting(E_ALL);
|
|
ini_set('display_errors', 1);
|
|
|
|
?>
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Очистка звонков по запросу</title>
|
|
</head>
|
|
|
|
<body>
|
|
<?php
|
|
|
|
$start = time();
|
|
|
|
$dbpg = new MysqlPdo(hstpg, ndbpg, userpg, passpg, false, '5432', true);
|
|
|
|
$sqlAgencyIds = "select distinct agency_id from mango_calls WHERE line_number = 'megafon'";
|
|
$resAgencyIds = $dbpg->query($sqlAgencyIds);
|
|
|
|
$idsFromPg = [];
|
|
|
|
while($row = $dbpg->fetch_assoc($resAgencyIds)){
|
|
$idsFromPg[] = $row['agency_id'];
|
|
}
|
|
|
|
if (count($idsFromPg) == 0) {
|
|
exit("Нет агентств");
|
|
}
|
|
|
|
$sqlAgency = "SELECT id, email, phone, fio, agency_name, last_name, first_name, date_reg, last_auth, date_tarif from users where id in (" . implode(',', $idsFromPg) . ") and (now() >= DATE_ADD(date_tarif, INTERVAL (select t.period+60 FROM tariffs t where t.id=id_tarif LIMIT 1) DAY)) and agency = 1 and manager = 1 ORDER BY id LIMIT 1";
|
|
$resAgency = mysql_query($sqlAgency);
|
|
|
|
$countAll = 0;
|
|
|
|
$result = SelectelApi::getTokenAndUrl();
|
|
|
|
$token = $result[0];
|
|
$storageUrl = $result[1];
|
|
|
|
while($agency = mysql_fetch_assoc($resAgency)) {
|
|
|
|
echo " Удаляем звонки агентства ".$agency['id'] . " <br/>";
|
|
|
|
$count = 0;
|
|
|
|
$sqlCalls = "SELECT * FROM mango_calls WHERE line_number = 'megafon' and agency_id = $agency[id] LIMIT 1";
|
|
|
|
$rezCalls = $dbpg->query($sqlCalls);
|
|
|
|
while ($call = $dbpg->fetch_assoc($rezCalls)) {
|
|
|
|
echo " Удаляем звонок ".$call['id'] . " <br/>";
|
|
|
|
$allDelete = true;
|
|
|
|
if ($call['records']) {
|
|
|
|
$records = json_decode($call['records']);
|
|
|
|
if(!empty($records)) {
|
|
foreach ($records as $record) {
|
|
if (!empty($record)) {
|
|
|
|
//удаляем Селектел
|
|
if (SelectelApi::deleteMp3File($storageUrl, $token, "/mega/" . $record . ".mp3")) {
|
|
echo " Selectel file " . "/mega/" . $record . ".mp3" . " deleted<br>";
|
|
} else {
|
|
echo " Selectel file " . "/mega/" . $record . ".mp3" . " NOT deleted<br>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($allDelete) {
|
|
$sql = "DELETE FROM mango_calls WHERE id=$call[id]";
|
|
$dbpg->query($sql);
|
|
}
|
|
|
|
$count++;
|
|
$countAll++;
|
|
|
|
if(((time() - $start) > 580)) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
echo "Агентство ".$agency['id'] . " удалено " . $count . " звонков <br/>";
|
|
}
|
|
|
|
echo "Удалено " . $countAll . " звонков <br/>";
|
|
|
|
?>
|
|
</body>
|
|
</html>
|