query($sql); while($r = $pdo->fetch_assoc($q)){ if($r['company_id'] > 0){ if(!in_array($r['company_id'], $agencys)){ $agencys[] = (int)$r['company_id']; } } else { if(!in_array($r['id'], $agencys)){ $agencys[] = (int)$r['id']; } } } /** * Поиск записей для отправки */ //$cr_ids = array(); if(!empty($agencys)){ $sql = "SELECT * FROM `webhook_logs` WHERE agency_id in (".implode(',', $agencys).") AND response_status <> 200 AND retry_count < 3 LIMIT 100"; $q = $pdo->query($sql); while($r = $pdo->fetch_assoc($q)){ $cron_ids[] = (int)$r['id']; if($r['agency_id'] > 0 && (int)$r['entity_id'] > 0){ $dataWhook = array('action'=>$r['event_type']); $dataWhook['user_id'] = $r['initiator_user_id']; $dataWhook['agency_id'] = $r['agency_id']; $dataWhook['section'] = $r['entity_type']; if($r['entity_type'] == 'object'){ $dataWhook['object_id'] = (int)$r['entity_id']; } else if($r['entity_type'] == 'requisition'){ $dataWhook['req_id'] = (int)$r['entity_id']; } else if($r['entity_type'] == 'client'){ $dataWhook['client_id'] = (int)$r['entity_id']; } $dataWhook['retry_id'] = (int)$r['id']; $w_in = new WebHookIn(null, $r['agency_id']); $w_in->check_send($dataWhook); } } }