query($sqlAgencyIds); $idsFromPg = []; while($row = $dbpg->fetch_assoc($resAgencyIds)){ $idsFromPg[] = $row['agency_id']; } if (count($idsFromPg) == 0) { exit("Нет агентств"); } else { var_dump($idsFromPg); } $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'] . "
"; $count = 0; $sqlCalls = "SELECT * FROM mango_calls WHERE line_number = 'telphin' and agency_id = $agency[id] LIMIT 1"; $rezCalls = $dbpg->query($sqlCalls); while ($call = $dbpg->fetch_assoc($rezCalls)) { echo " Удаляем звонок ".$call['id'] . "
"; $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, "/telphin/" . $record . ".mp3")) { echo " Selectel file " . "/telphin/" . $record . ".mp3" . " deleted
"; } else { echo " Selectel file " . "/telphin/" . $record . ".mp3" . " NOT deleted
"; } } } } } 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 . " звонков
"; } echo "Удалено " . $countAll . " звонков
"; ?>