all(); foreach($orgs as $org) { foreach($org->emails as $email) { fwrite($f, $email->email.";".$org->name.";".$org->inn."\n"); } } fclose($f); } public function actionNew() { $f = fopen(\Yii::getAlias('@runtime').'/new-calls.txt', 'a+'); $calls = Call::find()->where(["status" => ["no-answer", "timeout"]])->all(); foreach($calls as $call) { fwrite($f, $call->phone."\n"); } } public function actionCheck($file) { $fp = fopen(\Yii::getAlias('@runtime').'/new-phones.txt', 'a+'); $fe = fopen(\Yii::getAlias('@runtime').'/new-emails.txt', 'a+'); $data = file_get_contents($file); $rows = preg_split("/\n/", $data); foreach($rows as $phone) { $ch = curl_init("http://ssd.nomer.io/api/".$phone."?token=d131BpdeqbFJMasdfaVYJU6ydeyhgX"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($httpCode == 200) { // Все ок, берем данные $response = Json::decode($response); foreach ($response as $r) { if(isset($r["type"])) { switch ($r["type"]) { case "phone": fwrite($fp, $phone.";".$r["data"]."\n"); break; case "email": if (strpos($r["data"], '@') !== false) { fwrite($fe, $phone.";".$r["data"]."\n"); } break; } } } } } fclose($fe); fclose($fp); } public function actionExportPhones() { $f = fopen(\Yii::getAlias('@runtime').'/phones.txt', 'a+'); $phones = OrganizationPhone::find()->all(); foreach($phones as $phone) { fwrite($f, $phone->phone."\n"); } fclose($f); } public function actionExportEmails() { $f = fopen(\Yii::getAlias('@runtime').'/emails.txt', 'a+'); $emails = OrganizationEmail::find()->all(); foreach($emails as $email) { fwrite($f, $email->email."\n"); } fclose($f); } protected function getOrgsPage($page) { $ch = curl_init('https://crmbg.su/actions.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Cookie: PHPSESSID=6mu3svdm2bgl3tpgr3oihc5k36' ]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'action' => 'tender_search', 'page' => $page, 'protocol' => 'undefined', 'sort' => 'id:DESC', 'price' => 0, 'online' => 0, 'type' => 1, 'first' => 'undefined', 'onlyone' => 'undefined', 'contact' => '30.06.2017' ]); $response = curl_exec($ch); curl_close($ch); return $response; } protected function getCardPage($id) { $ch = curl_init('https://crmbg.su/actions.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Cookie: PHPSESSID=6mu3svdm2bgl3tpgr3oihc5k36' ]); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, [ 'action' => 'get_card_info', 'id' => $id, ]); $response = curl_exec($ch); curl_close($ch); return $response; } public function actionOrgs($from = 1, $to = 22) { for ($i = $from; $i <= $to; $i++) { echo 'Получаем организации со страницы ' . $i . PHP_EOL; $response = $this->getOrgsPage($i); preg_match('/(
\s+Телефон\s+<\/td> | (.*?)<\/td>/s', $response, $mainPhone); $mainPhone = $mainPhone[1]; preg_match('/ | \s+Email\s+<\/td> | (.*?)<\/td>/s', $response, $mainEmail);
$mainEmail = $mainEmail[1];
$orgPhone = new OrganizationPhone();
$orgPhone->org_id = $org->id;
$orgPhone->name = 'main';
$orgPhone->phone = $mainPhone;
$orgPhone->save();
$orgEmail = new OrganizationEmail();
$orgEmail->org_id = $org->id;
$orgEmail->name = 'main';
$orgEmail->email = $mainEmail;
$orgEmail->save();
preg_match_all('/( |