Joywork/cron/clearMp3Tele2Sql.php

84 lines
2.5 KiB
PHP
Raw Normal View History

2026-05-22 20:21:54 +02:00
<?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();
$sqlAgency = "SELECT id, email, phone, fio, agency_name, last_name, first_name, date_reg, last_auth, date_tarif from users where id in (select distinct agency_id from mango_calls WHERE line_number = 'tele2') 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)) {
$count = 0;
$sqlCalls = "SELECT * FROM mango_calls WHERE line_number = 'tele2' and agency_id = $agency[id] LIMIT 1";
$rezCalls = mysql_query($sqlCalls);
while ($call = mysql_fetch_assoc($rezCalls)) {
$date = date("Ymd", $call['start']);
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, "/tele2/" . $agency['id'] . "/" . $date . "/" . $record . ".mp3")) {
echo " Selectel file " . "/tele2/" . $agency['id'] . "/" . $date . "/" . $record . ".mp3" . " deleted<br>";
} else {
echo " Selectel file " . "/tele2/" . $agency['id'] . "/" . $date . "/" . $record . ".mp3" . " NOT deleted<br>";
}
}
}
}
}
if ($allDelete) {
$sql = "DELETE FROM mango_calls WHERE id=$call[id]";
mysql_query($sql);
}
$count++;
$countAll++;
if(((time() - $start) > 580)) {
break;
}
}
echo "Агентство ".$agency['id'] . " удалено " . $count . " звонков <br/>";
}
echo "Удалено " . $countAll . " звонков <br/>";
?>
</body>
</html>