From ae2357ae18ccc5fa04332ade54e2e6d257939493 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 29 Dec 2023 12:40:32 +0300 Subject: [PATCH] add missing file amo_sync_crm.php --- erp24/inc/amo/amo_sync_crm.php | 224 +++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 erp24/inc/amo/amo_sync_crm.php diff --git a/erp24/inc/amo/amo_sync_crm.php b/erp24/inc/amo/amo_sync_crm.php new file mode 100644 index 0000000..eb906d6 --- /dev/null +++ b/erp24/inc/amo/amo_sync_crm.php @@ -0,0 +1,224 @@ + $tag) { + if($i"id", + 647945=>"pol_name", + 657129=>"text_card", + 647947=>"pol_phone", + 774807=>"delivery_time", +//647937=>"delivery_time_old", + 647935 =>"delivery_date", + 774805 =>"delivery_time_extend", + 676231=>"delivery_oblast", + 647949=>"delivery_adress", + 676229=>"delivery_rayon", + 647931=>"pay", + 651887=>"payment_type_id", + 647927=>"delivery", + 647929=>"store_id", + 647929=>"store", + 647955=>"comment", + 661535=>"order_text", + 659607=>"toper", + 658099 =>"shariki", + 768387 =>"povod", + 647953 =>"istochnik", + 775235 =>"courier_id", + 775237 =>"courier", + 775239 =>"courier_zabor", + 775241 =>"courier_dostavil", + 775245 =>"florist_id", + 775247 =>"florist", + 775491 =>"florist_peredano", + 775289 =>"florist_zabor", + 775343 =>"florist_foto", + 775539 =>"dostavka_comment", + 775507 =>"price_dostavka", + 775495 =>"price_dostavka_zatrat", + 775513 =>"dostavka_povtor_tip", + 775505 =>"price_dostavka_povtor_zatrat", + 775509 =>"price_dostavka_povtor", + 658125 =>"otkaz_id", + 663239 =>"otkaz_text", + 775001 =>"otkaz_manager", + 775287 =>"otkaz_id_rop", + 775355 =>"client_comment_foto", + 775499 =>"client_adress_zamena", + 775501 =>"client_adress_zamena_cnt", + 775351 =>"client_ip", + 775357 =>"client_pravki_cnt", + 775349 =>"client_foro_prosmotr", + 774987 =>"uber_time", + 775545 =>"manager_time", + 775287 =>"otkaz_id_rop", + 776319 =>"manager_id", + 776321 =>"manager", + 776329 =>"phone_client", + 775955 =>"courier_gps", + 776259 =>"manager_courier_time", + 775365 =>"florist_sborka_night", + 795353 =>"products_json", +//786559 =>"brend", + 775083 =>"key_code", + ]; + + + /*if($ma["id"]==786559) $brend=trim($valuecustom); + if($ma["id"]==655357) $lid_id=$valuecustom; + $json_new["custom_".$ma["id"].""]=array("name"=>$ma["name"], "value"=>$valuecustom); + } + + $custom_brend=''; + if($brend=='') $brend='БазаЦветов24.ру'; + //$brend='Регион';$brend='ДомРоз24.ру';$brend='24-База-Цветов.ру'; + + $custom_brend = ', {"field_id": 786559, "values": [ {"value":"'.$brend.'"}]}';*/ + + + + $formapole=[ + "delivery_date"=>"date", + "florist_peredano"=>"datetime", + "florist_zabor"=>"datetime", + "florist_foto"=>"datetime", + "courier_zabor"=>"datetime", + "courier_dostavil"=>"datetime", + "manager_courier_time"=>"datetime", + + + ]; + + if (!function_exists('func_format')) { + function func_format($tip="datetime",$pole) { + + if($tip=="datetime") $pole=date("Y-m-d H:i:s",$pole); + if($tip=="date") $pole=date("Y-m-d",$pole); + return $pole; + + } + } + + + foreach($custom_fields as $if => $ma) { + if(!empty($massiv[$ma["field_id"]])) { + if(!empty($formapole[$massiv[$ma["field_id"]]])) $ma["values"][0]["value"]=func_format($formapole[$massiv[$ma["field_id"]]],$ma["values"][0]["value"]); + + $row[$massiv[$ma["field_id"]]]=$ma["values"][0]["value"]; + } + } + +//if($row["delivery_time"]==$row["delivery_time_old"]) $row["delivery_time_old"]=""; + if($row["delivery_time_extend"]==$row["delivery_time"]) $row["delivery_time_extend"]=""; + if($row["delivery_time_extend"]==$row["delivery_time_old"]) $row["delivery_time_extend"]=""; + +//foreach($row as $k => $v) echo"
$k => $v"; +//print'
';print_r($deal);echo'
'; + + $contact = amo_rest($ACCESS_TOKEN, '/api/v4/contacts/' . $id_contact, $method = 'GET', []); +//$arr = ['lead' => $deal, 'contact' => $contact]; + $phone=$contact["custom_fields_values"]["0"]["values"]["0"]["value"]; + $email=$contact["custom_fields_values"]["1"]["values"]["0"]["value"]; + $name=$contact["name"]; + $row["client"]=$name; + $row["phone"]=$phone; + $row["email"]=$email; + $row["amo_sync_time"]=date("Y-m-d H:i:s",time()); + + if(empty($row["phone"])) $row["phone"]=$row["phone_client"]; + + +//echo "id= ".$contact["id"]." $name phone =$phone $email"; + +//print_r($contact); + + + + $i=0; + $sql1 =""; $sql2 =""; + foreach($row as $n => $value) { + + $value=str_replace("'","",$value); + if($i>0) { $sql1 .=","; $sql2 .=","; } + $sql1 .=" $n "; + $sql2 .="'$value'"; + +//echo"
$n => $value "; + $i++; + } + + + if(!empty($row["id"])) { + + + $data_cnt=$db::getRows("SELECT id FROM orders_amo WHERE id=?",[$row["id"]]); + + if($update_amo==1 and count($data_cnt)>0) { + + echo"НЕ удаляем cтарую информацию"; + } else $db::sql("DELETE FROM orders_amo WHERE id=?",[$row["id"]]); + + + + if($row["status_id"]==142 or $row["status_id"]==143) $db::sql("DELETE FROM orders_amo WHERE id=?",[$row["id"]]); + + $s="INSERT INTO orders_amo ($sql1) VALUES ($sql2);"; echo $s; + $db::sql($s); + + $data=$db::getRows("SELECT id, adress_amo FROM city_store WHERE 1"); + foreach ($data as $row2) { + if(!empty($row2["id"])) $db::sql("UPDATE orders_amo SET store_id='".$row2["id"]."' WHERE store='".$row2["adress_amo"]."' AND store_id=''"); + } + +//file_put_contents('sunc_142.txt', ''.$s.' ', FILE_APPEND); + } + + +} -- 2.39.5