n_geocode (n_houses)
вар 2
<? require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); CModule::IncludeModule("nikaverro.gservice"); $gs = GameService::getInstance(); $lastId = 0; $arResult = $gs->QueryFetch("select * from geocode where id>21044 LIMIT 1000;"); global $DB; foreach ($arResult as $arFields) { $lastId = $arFields['id']; $arInsert = $DB->PrepareInsert("n_geocode", $arFields); $strSql = "INSERT INTO n_geocode (".$arInsert[0].") VALUES (".$arInsert[1].")"; //echo $strSql; $DB->Query($strSql, false, $err_mess.__LINE__); if (strlen($strError)<=0){ $DB->Commit(); //сохранить последние изменения в базе и закрыть транзакцию } else{ echo $strError; $DB->Rollback(); //откатить изменения и закрыть транзакцию } } echo $lastId;?> |
CModule::IncludeModule("crm"); CModule::IncludeModule("nikaverro.gservice"); $gs = GameService::getInstance(); $lastId= 1140109; $arResult = $gs->QueryFetch("select id,ls,fio,tel,org from clients where id<".$lastId." order by id desc limit 300;"); $arLs = []; foreach ($arResult as $key => $arItem) { $arLs[] = $arItem["ls"]; } echo "<pre>"; if(!empty($arLs)){ $arFilter = array( "UF_CID"=>$arLs, //выбираем определенную компанию по ls "CHECK_PERMISSIONS"=>"N" //не проверять права доступа текущего пользователя ); $arSelect = array( "ID", "UF_CID" ); $res = CCrmCompany::GetList(Array(), $arFilter, $arSelect); $arComps = []; while($row = $res->Fetch()){ $arComps[$row["UF_CID"]] = $row["ID"]; } $options = array('CURRENT_USER'=>1); //из под админа $company = new \CCrmCompany( false ); $fieldMulti = new CCrmFieldMulti(); foreach ($arResult as $key => $arItem) { $lastId = $arItem["id"]; if(isset($arComps[$arItem["ls"]])){ echo "найден"; print_r($arItem); //break; } else{ //print_r($arItem); $name = $arItem["ls"]; if(!empty($arItem["fio"])){ if(!empty($arItem["org"]) && ($arItem["fio"] != $arItem["org"])){//организация $name .= " ".$arItem["org"]; } else{ //частник $name .= " ".$arItem["fio"]; } } //вар1 $arFields = [ "TITLE"=>$name, "UF_CID" =>$arItem["ls"] ]; $companyId = $company->Add($arFields); if(($companyId>0) && !empty($arItem["tel"])){ $arTels = explode(" ", $arItem["tel"]); foreach($arTels as $tel){ //echo $tel; $fieldMulti->Add([ 'ELEMENT_ID' => $companyId, 'ENTITY_ID' => "COMPANY", //"CONTACT","LEAD","DEAL" 'TYPE_ID' => "PHONE", //"EMAIL", 'VALUE' => $tel, 'VALUE_TYPE' => 'WORK', ]); } } ///// } } } echo $lastId; //print_r($arResult); echo "</pre>"; |
$arFields = [ "TITLE"=>$name, "UF_CID" =>$arItem["ls"], "FM" => ["PHONE"=>[]] ]; $i = 0; $arTels = explode(" ", $arItem["tel"]); foreach($arTels as $tel){ //echo $tel; $s = "n".$i; $arFields["FM"]["PHONE"][$s] = [ 'VALUE' => $tel, 'VALUE_TYPE' => 'WORK' ]; } $companyId = $company->Add($arFields); |