Linux unitednationsplay.com 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
nginx/1.20.1
Server IP : 188.130.139.92 & Your IP : 18.189.3.134
Domains :
Cant Read [ /etc/named.conf ]
User : web
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
home /
www /
unp /
app /
Models /
Delete
Unzip
Name
Size
Permission
Date
Action
Country.php
1.52
KB
-rw-r--r--
2021-03-18 11:35
Impacts.php
1.58
KB
-rw-r--r--
2021-03-29 14:13
Positions.php
1.6
KB
-rw-r--r--
2021-03-18 11:35
Products.php
1.58
KB
-rw-r--r--
2021-03-18 11:35
Signings.php
1.76
KB
-rw-r--r--
2022-08-25 20:53
apiREST.php
58.04
KB
-rw-r--r--
2021-03-02 12:40
Save
Rename
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Backpack\CRUD\CrudTrait; use App\Models\Sites; use DB; class apiREST extends Model { use CrudTrait; public function GetSectionsListAll($site_id='') { $arResult = array(); if (intval($site_id)>0) { $sites = Sites::where('id', '=', $site_id)->get(); if (!$sites[0]->autodealer) { //if ($sites[0]->id == 3) //$JSON = file_get_contents('http://' . $sites[0]->address . '/rest/getSectionsListAll.php'); //else $JSON = file_get_contents('https://' . $sites[0]->address . '/rest/getSectionsListAll.php'); if ($JSON) $arResult = json_decode($JSON); } else { } //dd($arResult); //dd($sites[0]); } return $arResult; } public function updateQuantityOnSites($unique_id, $orig_id = '', $arData ) { $arResult = array(); if (!empty($arData)) { $sites = Sites::where('autodealer', '=', '0')->get(); foreach ($sites as $site) { $JSON = ''; if (!empty($arData[$site->id]) AND !empty($arData[$site->id]["data"]) ) { $unique_id = $arData[$site->id]["data"]["unique_id"]; $arDataToSend["unique_id"] = $arData[$site->id]["data"]["unique_id"]; $arDataToSend["quant_north"] = $arData[$site->id]["data"]["quant_north"]; $arDataToSend["quant_south"] = $arData[$site->id]["data"]["quant_south"]; if (!$unique_id OR $unique_id==0) $arDataToSend["id"] = $orig_id; $data = serialize($arDataToSend); /* if ($site->id == 3) { $data_url = http_build_query($arDataToSend); $ch = curl_init('http://' . $site->address .'/rest/updateElement.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $JSON = curl_exec($ch); curl_close($ch); } else {*/ $data_url = http_build_query($arDataToSend); $ch = curl_init('https://' . $site->address .'/rest/updateElement.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $JSON = curl_exec($ch); curl_close($ch); //} $arPreResult[$site->name] = json_decode($JSON); } } $ok = $error = $error_mess = ''; foreach ($arPreResult as $k=>$res) { if (!empty($res)) { if ($res->STATUS=="OK") $ok = 1; if ($res->STATUS=="ERROR") { $error = 1; $error_mess .= $k.": ".$res->MESSAGE."\n\r"; } } } if ($ok) { $arResult["STATUS"] = "OK"; $arResult["MESSAGE"] = "Успешно обновлено"; } else { if (!$error) { $arResult["STATUS"] = "ERROR"; $arResult["MESSAGE"] = "Ни один из сайтов не обновлен"; } else { $arResult["STATUS"] = "MESSAGE"; $arResult["MESSAGE"] = $error_mess; } } } return $arResult; } public function uploadGoodToSites($unique_id, $orig_id = '', $arData, $with_autodealer = '', $arDealer = array() ) { if (!$with_autodealer) { if (!empty($arData)) { $sites = Sites::where('autodealer', '=', '0')->get(); foreach ($sites as $site) { unset($arDataToSend); $JSON=''; if (!empty($arData[$site->id]) AND !empty($arData[$site->id]["common"]) AND !empty($arData[$site->id]["artikuls"])) { foreach ($arData[$site->id]["common"] as $common) { $unique_id = $common->unique_id; $arDataToSend["unique_id"] = $unique_id; } if (!empty($arData[$site->id]["brand"])) { $arDataToSend["brand"] = $arData[$site->id]["brand"]; } if (!empty($arData[$site->id]["artikuls"]->name)) { $arDataToSend["name"] = $arData[$site->id]["artikuls"]->name; } if (!empty($arData[$site->id]["artikuls"]->active)) { $arDataToSend["active"] = $arData[$site->id]["artikuls"]->active; } if (!empty($arData[$site->id]["artikuls"])) { $arDataToSend["artikul"] = $arData[$site->id]["artikuls"]->artikul; } if (!empty($arData[$site->id]["prices"])) { $arDataToSend["prices"]["price"] = $arData[$site->id]["prices"]->price; $arDataToSend["prices"]["price_currency"] = $arData[$site->id]["prices"]->price_currency; $arDataToSend["prices"]["discount"] = $arData[$site->id]["prices"]->discount; $arDataToSend["prices"]["discount_currency"] = $arData[$site->id]["prices"]->discount_currency; $arDataToSend["prices"]["install"] = $arData[$site->id]["prices"]->install; $arDataToSend["prices"]["install_currency"] = $arData[$site->id]["prices"]->install_currency; } if (!empty($arData[$site->id]["metas"])) { $arDataToSend["meta"]["title"] = $arData[$site->id]["metas"]->title; $arDataToSend["meta"]["description"] = $arData[$site->id]["metas"]->description; $arDataToSend["meta"]["keywords"] = $arData[$site->id]["metas"]->keywords; } if (!empty($arData[$site->id]["texts"])) { $arDataToSend["text"] = $arData[$site->id]["texts"]->preview; } if (!$unique_id OR $unique_id==0) $arDataToSend["id"] = $orig_id; $data = serialize($arDataToSend); /* if ($site->id == 3) { $data_url = http_build_query($arDataToSend); $ch = curl_init('http://' . $site->address .'/rest/updateElement.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $JSON = curl_exec($ch); curl_close($ch); } else {*/ $data_url = http_build_query($arDataToSend); $ch = curl_init('https://' . $site->address .'/rest/updateElement.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $JSON = curl_exec($ch); curl_close($ch); //} $arPreResult[$site->id] = json_decode($JSON); $fp = fopen('/home/bitrix/www/nimda/public/uploadGoodToSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s").": unique_id: ".$unique_id.", orig_id: ".$orig_id.", arData: ".serialize($arData).", with_autodealer: ".$with_autodealer.", arDealer: ".serialize($arDealer).", result: ".$JSON."\r\n"); fclose($fp); } } $ok = $error = $error_mess = ''; if (!empty($arPreResult)) { foreach ($arPreResult as $k => $res) { if (!empty($res)) { if ($res->STATUS == "OK") $ok = 1; if ($res->STATUS == "ERROR") { $error = 1; $error_mess .= $k . ": " . $res->MESSAGE . "\n\r"; } if ($res->STATUS == "OFFER") { $ok = 1; if (!empty($arData[$k]["common"][0]->brand_id)) { $brand = $arData[$k]["common"][0]->brand_id; if (!empty($res->OFFERS)) { foreach ($res->OFFERS as $offer) { DB::table('goods')->where('unique_id', $offer)->update(['brand_id' => $brand]); } } } } } } } if ($ok) { $arResult["STATUS"] = "OK"; $arResult["MESSAGE"] = "Успешно обновлено"; } else { if (!$error) { $arResult["STATUS"] = "ERROR"; $arResult["MESSAGE"] = "Ни один из сайтов не обновлен"; } else { $arResult["STATUS"] = "MESSAGE"; $arResult["MESSAGE"] = $error_mess; } } //dd($arPreResult); //if ($JSON) $arResult = json_decode($JSON); } } else { //dd($arDealer); $sites = Sites::where('autodealer', '=', '1')->get(); foreach ($sites as $site) { if (!empty($arDealer[$site->id]) AND !empty($arDealer[$site->id]["price"])) { if ($site->id == 6) { try { $firebird_north = DB::connection('firebird_north'); } catch (\PDOException $e) { $firebird_north_gone = 1; } } elseif ($site->id == 7) { try { $firebird_south = DB::connection('firebird_south'); } catch (\PDOException $e) { $firebird_south_gone = 1; } } if (!isset($firebird_north_gone) AND $site->id == 6) { $arPreResult[$site->name] = (object)array(); $arResCon = $firebird_north->select('select current_connection from rdb$database'); $USER_CONNECTION_ID_NORTH = $arResCon[0]->CURRENT_CONNECTION; $firebird_north->delete("delete from USER_CONNECTION where USER_ID='16'"); $arResConn = $firebird_north->select("SELECT * FROM USER_CONNECTION WHERE USER_ID='16'"); if (empty($arResConn)) { $firebird_north->insert("insert into USER_CONNECTION (USER_CONNECTION_ID,USER_ID,STARTTIME) values (".($USER_CONNECTION_ID_NORTH).",16,'".date("Y-m-d H:i:s")."')"); } $good = DB::table('goods')->where('id', $arDealer[$site->id]["goods_id"])->get(); if (!empty($good[0])) { if (isset($good[0]->approve)) { $artikuls = DB::table('artikuls')->where(['goods_id'=>$arDealer[$site->id]["goods_id"],'sites_id'=>$site->id])->get(); if (!empty($artikuls[0])) { $brands_old = DB::table('brands')->where('id', $good[0]->brand_id)->get(); $brand_old = 0; $arResProd = $firebird_north->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$brands_old[0]->name). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_old = $item->PRODUCER_ID; } } $PRODUCER_ID_OLD = ''; if (isset($brand_old) AND intval($brand_old)>0) $PRODUCER_ID_OLD = " AND PRODUCER_ID='" . $brand_old . "'"; $arRes = $firebird_north->select("SELECT SHOP_NOMENCLATURE_ID, DIRECTORY_REGISTRY_ID, SHOP_NOMENCLATURE_TREE_ID, SHORTNAME, FULLNAME, CODE, NUMBER_MANUFACTURE, NUMBER_ORIGINAL, PRODUCER_ID, DEFAULT_COST FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE='".$artikuls[0]->artikul."' ".$PRODUCER_ID_OLD); $brand_id = 0; $arResProd = $firebird_north->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$arDealer[$site->id]["brand"]). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_id = $item->PRODUCER_ID; } } $PRODUCER_ID = ''; if (isset($brand_id) AND intval($brand_id)>0) $PRODUCER_ID = " PRODUCER_ID='" . $brand_id . "',"; //FULLNAME='" . $arDealer[$site->id]["name"] . "',PRODUCER_ID='" . $brand_id . "', if (!empty($arRes)) { foreach ($arRes as $item) { $firebird_north->update("update SHOP_NOMENCLATURE set DEFAULT_COST='" . $arDealer[$site->id]["price"] . "', FULLNAME='" . substr( addslashes( iconv("UTF-8","windows-1251",$arDealer[$site->id]["name"]) ),0,96) . "', ".$PRODUCER_ID." NUMBER_MANUFACTURE='" . $arDealer[$site->id]["artikul"] . "', DIRECTORY_REGISTRY_ID='".$item->DIRECTORY_REGISTRY_ID."' WHERE SHOP_NOMENCLATURE_ID='" . $item->SHOP_NOMENCLATURE_ID . "'"); $arPreResult[$site->name]->STATUS = "OK"; } } else { $arPreResult[$site->name]->STATUS = "ERROR"; } } } else { if ($good[0]->orig_id) { $arRes = $firebird_north->select("SELECT SHOP_NOMENCLATURE_ID, DIRECTORY_REGISTRY_ID, SHOP_NOMENCLATURE_TREE_ID, SHORTNAME, FULLNAME, CODE, NUMBER_MANUFACTURE, NUMBER_ORIGINAL, PRODUCER_ID, DEFAULT_COST FROM SHOP_NOMENCLATURE WHERE SHOP_NOMENCLATURE_ID='".$good[0]->orig_id."'"); $brand_id = 0; $arResProd = $firebird_north->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$arDealer[$site->id]["brand"]). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_id = $item->PRODUCER_ID; } } $PRODUCER_ID = ''; if (isset($brand_id) AND intval($brand_id)>0) $PRODUCER_ID = " PRODUCER_ID='" . $brand_id . "',"; if (!empty($arRes)) { foreach ($arRes as $item) { $firebird_north->update("update SHOP_NOMENCLATURE set DEFAULT_COST='" . $arDealer[$site->id]["price"] . "', FULLNAME='" . substr( addslashes( iconv("UTF-8","windows-1251",$arDealer[$site->id]["name"]) ),0,96) . "', ".$PRODUCER_ID." NUMBER_MANUFACTURE='" . $arDealer[$site->id]["artikul"] . "', DIRECTORY_REGISTRY_ID='".$item->DIRECTORY_REGISTRY_ID."' WHERE SHOP_NOMENCLATURE_ID='" . $item->SHOP_NOMENCLATURE_ID . "'"); $arPreResult[$site->name]->STATUS = "OK"; } } } else { $arPreResult[$site->name]->STATUS="ERROR"; } } } $fp = fopen('/home/bitrix/www/nimda/public/uploadGoodToSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s")." ad sever: unique_id: ".$unique_id.", orig_id: ".$orig_id.", arData: ".serialize($arData).", with_autodealer: ".$with_autodealer.", arDealer: ".serialize($arDealer).", result: ".serialize($arPreResult[$site->name])."\r\n"); fclose($fp); //$firebird_north->delete("delete from USER_CONNECTION where USER_ID='16'"); //$firebird_north->disconnect(); } if (!isset($firebird_south_gone) AND $site->id == 7) { $arPreResult[$site->name] = (object)array(); $arResCon = $firebird_south->select('select current_connection from rdb$database'); $USER_CONNECTION_ID_SOUTH = $arResCon[0]->CURRENT_CONNECTION; $firebird_south->delete("delete from USER_CONNECTION where USER_ID='8'"); $arResConn = $firebird_south->select("SELECT * FROM USER_CONNECTION WHERE USER_ID='8'"); if (empty($arResConn)) { $firebird_south->insert("insert into USER_CONNECTION (USER_CONNECTION_ID,USER_ID,STARTTIME) values (".($USER_CONNECTION_ID_SOUTH).",8,'".date("Y-m-d H:i:s")."')"); } $good = DB::table('goods')->where('id', $arDealer[$site->id]["goods_id"])->get(); if (!empty($good[0])) { if (isset($good[0]->approve)) { $artikuls = DB::table('artikuls')->where(['goods_id'=>$arDealer[$site->id]["goods_id"],'sites_id'=>$site->id])->get(); if (!empty($artikuls[0])) { $brands_old = DB::table('brands')->where('id', $good[0]->brand_id)->get(); $brand_old = 0; $arResProd = $firebird_south->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$brands_old[0]->name). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_old = $item->PRODUCER_ID; } } $PRODUCER_ID_OLD = ''; if (isset($brand_old) AND intval($brand_old)>0) $PRODUCER_ID_OLD = " AND PRODUCER_ID='" . $brand_old . "'"; $arRes = $firebird_south->select("SELECT SHOP_NOMENCLATURE_ID, DIRECTORY_REGISTRY_ID, SHOP_NOMENCLATURE_TREE_ID, SHORTNAME, FULLNAME, CODE, NUMBER_MANUFACTURE, NUMBER_ORIGINAL, PRODUCER_ID, DEFAULT_COST FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE='".$artikuls[0]->artikul."' ".$PRODUCER_ID_OLD ); $brand_id = 0; $arResProd = $firebird_south->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$arDealer[$site->id]["brand"]). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_id = $item->PRODUCER_ID; } } $PRODUCER_ID = ''; if (isset($brand_id) AND intval($brand_id)>0) $PRODUCER_ID = " PRODUCER_ID='" . $brand_id . "',"; if (!empty($arRes)) { foreach ($arRes as $item) { $firebird_south->update("update SHOP_NOMENCLATURE set DEFAULT_COST='" . $arDealer[$site->id]["price"] . "', FULLNAME='" . substr( addslashes( iconv("UTF-8","windows-1251",$arDealer[$site->id]["name"]) ),0,96) . "', ".$PRODUCER_ID." NUMBER_MANUFACTURE='" . $arDealer[$site->id]["artikul"] . "', DIRECTORY_REGISTRY_ID='".$item->DIRECTORY_REGISTRY_ID."' WHERE SHOP_NOMENCLATURE_ID='" . $item->SHOP_NOMENCLATURE_ID . "'"); $arPreResult[$site->name]->STATUS="OK"; } } else { $arPreResult[$site->name]->STATUS="ERROR"; } } } else { if ($good[0]->orig_id) { $brand_id = 0; $arResProd = $firebird_south->select("SELECT * FROM PRODUCER WHERE NAME='" .iconv("UTF-8","windows-1251",$arDealer[$site->id]["brand"]). "'"); if (!empty($arResProd)) { foreach ($arResProd as $item) { $brand_id = $item->PRODUCER_ID; } } $PRODUCER_ID = ''; if (isset($brand_id) AND intval($brand_id)>0) $PRODUCER_ID = " PRODUCER_ID='" . $brand_id . "',"; $arRes = $firebird_south->select("SELECT SHOP_NOMENCLATURE_ID, DIRECTORY_REGISTRY_ID, SHOP_NOMENCLATURE_TREE_ID, SHORTNAME, FULLNAME, CODE, NUMBER_MANUFACTURE, NUMBER_ORIGINAL, PRODUCER_ID, DEFAULT_COST FROM SHOP_NOMENCLATURE WHERE SHOP_NOMENCLATURE_ID='".$good[0]->orig_id."'"); if (!empty($arRes)) { foreach ($arRes as $item) { $firebird_south->update("update SHOP_NOMENCLATURE set DEFAULT_COST='" . $arDealer[$site->id]["price"] . "', FULLNAME='" . substr( addslashes( iconv("UTF-8","windows-1251",$arDealer[$site->id]["name"]) ),0,96) . "', ".$PRODUCER_ID." NUMBER_MANUFACTURE='" . $arDealer[$site->id]["artikul"] . "', DIRECTORY_REGISTRY_ID='".$item->DIRECTORY_REGISTRY_ID."' WHERE SHOP_NOMENCLATURE_ID='" . $item->SHOP_NOMENCLATURE_ID . "'"); $arPreResult[$site->name]->STATUS = "OK"; } } } else { $arPreResult[$site->name]->STATUS="ERROR"; } } } $fp = fopen('/home/bitrix/www/nimda/public/uploadGoodToSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s")." ad south: unique_id: ".$unique_id.", orig_id: ".$orig_id.", arData: ".serialize($arData).", with_autodealer: ".$with_autodealer.", arDealer: ".serialize($arDealer).", result: \r\n"); fclose($fp); //$firebird_south->delete("delete from USER_CONNECTION where USER_ID='8'"); //$firebird_south->disconnect(); } } } $arResult["STATUS"] = "OK"; $arResult["MESSAGE"] = "Успешно обновлено"; } return $arResult; } public function manualApprove($arGoods) { $goods_count = DB::table('goods')->orderBy('unique_id', 'desc')->limit(1)->get(); $unique_id = $goods_count[0]->unique_id+1; $sites = DB::table('sites')->orderBy('id', 'asc')->get(); foreach ($sites as $site) { $arSites[$site->id] = $site; if ($site->id == 6) { try { $firebird_north = DB::connection('firebird_north'); } catch (\PDOException $e) { $firebird_north_gone = 1; } } elseif ($site->id == 7) { try { $firebird_south = DB::connection('firebird_south'); } catch (\PDOException $e) { $firebird_south_gone = 1; } } } $goods = DB::table('goods')->whereIn('id',$arGoods)->get(); foreach ($goods as $k=>$item) { $artikuls = DB::table('artikuls')->where('goods_id', $item->id)->orderBy('id', 'asc')->get(); foreach ($artikuls as $art) { if (!$arSites[$art->sites_id]->autodealer) { $brand_name = ''; $JSON = ''; $arJSON = array(); if ($item->brand_id) { $brands = DB::table('brands')->where('id', $item->brand_id)->orderBy('id', 'asc')->get(); if (!empty($brands)) { $brand_name = $brands[0]->name; } } $JSON = file_get_contents('http://' . $arSites[$art->sites_id]->address . '/rest/setUniqueId.php?artikul=' . urlencode($art->artikul) . '&unique_id=' . $unique_id . '&brand=' . urlencode($brand_name). '&approve=1'); $arJSON = json_decode($JSON); if ($arJSON->STATUS == "ERROR") $arResult[] = $arJSON; } } } if (!isset($firebird_north_gone)) { $arResNorth = $firebird_north->select("SELECT * FROM ATTRIBUTE_DESCRIPTION "); foreach ($arResNorth as $val) { if ($val->FIELD_CAPTION=="UID" AND $val->METATABLE_ID==17) $firebird_north_uid = $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION=="APPROVE" AND $val->METATABLE_ID==17) $firebird_north_approve = $val->ATTRIBUTE_DESCRIPTION_ID; } //$firebird_north->disconnect(); $arArtikuls = array(); //$firebird_north = DB::connection('firebird_north'); //$firebird_north->beginTransaction(); $goods = DB::table('goods')->whereIn('id',$arGoods)->get(); foreach ($goods as $k => $item) { $artikuls = DB::table('artikuls')->where('goods_id', $item->id)->orderBy('id', 'asc')->get(); foreach ($artikuls as $art) { if ($art->sites_id == 6) { $arArtikuls[$art->artikul] = $art->artikul; /*if (count($arResNorthArtikul[$art->artikul]) == 1) { }*/ } } } /* try { $firebird_north = DB::connection('firebird_north'); } catch (\PDOException $e) { dd($e); } */ if (!empty($arArtikuls)) { $arResNorth = $firebird_north->select("SELECT * FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE IN ('" . iconv("UTF-8", "cp1251", implode("','", $arArtikuls)) . "')"); foreach ($arResNorth as $val) { $arResNorthArtikul[iconv("cp1251", "UTF-8", $val->NUMBER_MANUFACTURE)][] = $val; } foreach ($arArtikuls as $art) { if (!empty($arResNorthArtikul[$art])) { if (count($arResNorthArtikul[$art]) == 1) { foreach ($arResNorthArtikul[$art] as $res) { $firebird_north->update("update SHOP_NOMENCLATURE_ATTRIBUTE set FIELD_" . $firebird_north_uid . "='" . $unique_id . "', FIELD_" . $firebird_north_approve . "='1' WHERE DIRECTORY_REGISTRY_ID='" . $res->DIRECTORY_REGISTRY_ID . "'"); } } } } } $firebird_north->disconnect(); } if (!isset($firebird_south_gone)) { $arResSouth = $firebird_south->select("SELECT * FROM ATTRIBUTE_DESCRIPTION "); foreach ($arResSouth as $val) { if ($val->FIELD_CAPTION == "UID" AND $val->METATABLE_ID == 17) $firebird_south_uid = $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "APPROVE" AND $val->METATABLE_ID == 17) $firebird_south_approve = $val->ATTRIBUTE_DESCRIPTION_ID; } /*$arResSouth = $firebird_south->select("SELECT * FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE IN ('".implode("','",$arGoods)."') "); foreach ($arResSouth as $val) { $arResSouthArtikul[iconv("cp1251", "UTF-8", $val->NUMBER_MANUFACTURE)][] = $val; }*/ //$firebird_south->disconnect(); /* try { $firebird_south = DB::connection('firebird_south'); } catch (\PDOException $e) { //dd($firebird_south); }*/ $arArtikuls = array(); $firebird_south = DB::connection('firebird_south'); //$firebird_south->beginTransaction(); $goods = DB::table('goods')->whereIn('id',$arGoods)->get(); foreach ($goods as $k => $item) { $artikuls = DB::table('artikuls')->where('goods_id', $item->id)->orderBy('id', 'asc')->get(); foreach ($artikuls as $art) { if ($art->sites_id == 7) { $arArtikuls[$art->artikul] = $art->artikul; /* if (count($arResSouthArtikul[$art->artikul]) == 1) { foreach ($arResSouthArtikul[$art->artikul] as $res) { $firebird_south->select("update SHOP_NOMENCLATURE_ATTRIBUTE set FIELD_" . $firebird_south_uid . "='" . $unique_id . "', FIELD_" . $firebird_south_approve . "='1' WHERE DIRECTORY_REGISTRY_ID='" . $res->DIRECTORY_REGISTRY_ID . "'"); } } */ } } } if (!empty($arArtikuls)) { //dd("SELECT * FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE IN ('" . iconv("UTF-8", "cp1251", implode("','", $arArtikuls)) . "')"); $arResSouth = $firebird_south->select("SELECT * FROM SHOP_NOMENCLATURE WHERE NUMBER_MANUFACTURE IN ('" . iconv("UTF-8", "cp1251", implode("','", $arArtikuls)) . "')"); foreach ($arResSouth as $val) { $arResSouthArtikul[iconv("cp1251", "UTF-8", $val->NUMBER_MANUFACTURE)][] = $val; } foreach ($arArtikuls as $art) { if (count($arResSouthArtikul[$art]) == 1) { foreach ($arResSouthArtikul[$art] as $res) { $firebird_south->update("update SHOP_NOMENCLATURE_ATTRIBUTE set FIELD_" . $firebird_south_uid . "='" . $unique_id . "', FIELD_" . $firebird_south_approve . "='1' WHERE DIRECTORY_REGISTRY_ID='" . $res->DIRECTORY_REGISTRY_ID . "'"); } } } } $firebird_south->disconnect(); } $goods = DB::table('goods')->whereIn('id',$arGoods)->get(); foreach ($goods as $key=>$item) { //DB::table('goods')->where('id', $item->id)->update(['unique_id' => $unique_id, 'approve'=>'1']); if ($key == 0) { $main_id = $item->id; DB::table('goods')->where('id', $main_id)->update(['unique_id' => $unique_id, 'approve' => 1]); } else { //$unique_id++; DB::table('metas')->where('goods_id', $item->id)->update(['goods_id' => $main_id]); DB::table('prices')->where('goods_id', $item->id)->update(['goods_id' => $main_id]); DB::table('texts')->where('goods_id', $item->id)->update(['goods_id' => $main_id]); DB::table('artikuls')->where('goods_id', $item->id)->update(['goods_id' => $main_id]); DB::table('goods')->where('id', $item->id)->delete(); } } $fp = fopen('/home/bitrix/www/nimda/public/manualApprove.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s").": arGoods: ".serialize($arGoods)."\r\n"); fclose($fp); } public function updateGoodFromSites($good_id, $unique_id, $with_autodealer = '') { if (!$with_autodealer) { if (isset($good_id)) { $JSON = ''; $no_unique = ''; if (!$unique_id OR $unique_id==0) { $no_unique = 1; $goods = DB::table('goods')->where('id',$good_id)->get(); $orig_id = $goods[0]->orig_id; $site_id = $goods[0]->site_id; } $sites = Sites::where('autodealer', '=', '0')->get(); foreach ($sites as $site) { $JSON = ''; if ($no_unique) { if ($site_id==$site->id) { //if ($site->id == 3) //$JSON = file_get_contents('http://' . $site->address . '/rest/getElementByOrigId.php?id=' . $orig_id); //else $JSON = file_get_contents('https://' . $site->address . '/rest/getElementByOrigId.php?id=' . $orig_id); } } else { //if ($site->id == 3) //$JSON = file_get_contents('http://' . $site->address . '/rest/getElementByUniqueId.php?id=' . $unique_id); //else $JSON = file_get_contents('https://' . $site->address . '/rest/getElementByUniqueId.php?id=' . $unique_id); } if (isset($JSON)) $arResult[$site->id] = json_decode($JSON); $fp = fopen('/home/bitrix/www/nimda/public/updateGoodFromSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s").": unique_id: ".$unique_id.", good_id: ".$good_id.", with_autodealer: ".$with_autodealer.", result: ".$JSON."\r\n"); fclose($fp); } if (!empty($arResult)) { foreach ($arResult as $site_key=>$result) { if (!empty($result)) { if ($result->STATUS=="OK" AND !empty($result->MESSAGE)) { $arBrands = DB::table('brands')->where('name', $result->MESSAGE->brand)->get(); $arUpdate = array(); unset($arUpdate); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (!empty($arBrands[0])) { $arUpdate["brand_id"] = $arBrands[0]->id; } else { $brand_error = 1; } if (isset($result->MESSAGE->name)) $arUpdate["name"] = $result->MESSAGE->name; DB::table('goods')->where('id', $good_id)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->MESSAGE->artikul)) $arUpdate["artikul"] = $result->MESSAGE->artikul; if (isset($result->MESSAGE->name)) $arUpdate["name"] = $result->MESSAGE->name; if (isset($result->MESSAGE->active)) $arUpdate["active"] = $result->MESSAGE->active; DB::table('artikuls')->where('goods_id', $good_id)->where('sites_id', $site_key)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->MESSAGE->title)) $arUpdate["title"] = $result->MESSAGE->title; if (isset($result->MESSAGE->description)) $arUpdate["description"] = $result->MESSAGE->description; if (isset($result->MESSAGE->keywords)) $arUpdate["keywords"] = $result->MESSAGE->keywords; DB::table('metas')->where('goods_id', $good_id)->where('sites_id', $site_key)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->MESSAGE->price)) $arUpdate["price"] = $result->MESSAGE->price; if (isset($result->MESSAGE->price_currency)) $arUpdate["price_currency"] = $result->MESSAGE->price_currency; if (isset($result->MESSAGE->price_discount)) $arUpdate["discount"] = $result->MESSAGE->price_discount; if (isset($result->MESSAGE->price_discount_currency)) $arUpdate["discount_currency"] = $result->MESSAGE->price_discount_currency; if (isset($result->MESSAGE->price_install)) $arUpdate["install"] = $result->MESSAGE->price_install; if (isset($result->MESSAGE->price_install_currency)) $arUpdate["install_currency"] = $result->MESSAGE->price_install_currency; if (isset($result->MESSAGE->quantity)) $arUpdate["quantity"] = $result->MESSAGE->quantity; if (isset($result->MESSAGE->weight)) $arUpdate["weight"] = $result->MESSAGE->weight; if (isset($result->MESSAGE->width)) $arUpdate["width"] = $result->MESSAGE->width; if (isset($result->MESSAGE->length)) $arUpdate["length"] = $result->MESSAGE->length; if (isset($result->MESSAGE->height)) $arUpdate["height"] = $result->MESSAGE->height; DB::table('prices')->where('goods_id', $good_id)->where('sites_id', $site_key)->update($arUpdate); /* unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->MESSAGE->preview_text"])) $arUpdate["title"] = $result->MESSAGE->preview_text"]; if (isset($result->MESSAGE->detail_text"])) $arUpdate["description"] = $result->MESSAGE->detail_text"]; DB::table('texts')->where('goods_id', $good_id)->where('sites_id', $site_id)->update($arUpdate); */ } } } if (isset($brand_error)) { $arUpdate = array(); unset($arUpdate); $arUpdate["brand_id"] = 'null'; DB::table('goods')->where('id', $good_id)->update($arUpdate); $fp = fopen('/home/bitrix/www/nimda/public/updateGoodFromSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s")." brand_error: ".$brand_error." unique_id: ".$unique_id.", good_id: ".$good_id.", with_autodealer: ".$with_autodealer.", result: ".$JSON."\r\n"); fclose($fp); } } $sites = Sites::where('autodealer', '=', '1')->get(); foreach ($sites as $site) { $arSites[$site->id] = $site; if ($site->id == 6) { try { $firebird_north = DB::connection('firebird_north'); } catch (\PDOException $e) { $firebird_north_gone = 1; } } elseif ($site->id == 7) { try { $firebird_south = DB::connection('firebird_south'); } catch (\PDOException $e) { $firebird_south_gone = 1; } } } if (($no_unique)) { if (isset($site_id)) { if ($site_id != 6) $firebird_north_gone = 1; if ($site_id != 7) $firebird_south_gone = 1; } else { $firebird_north_gone = 1; $firebird_south_gone = 1; } } if (!isset($firebird_north_gone)) { if (isset($unique_id) AND intval($unique_id)>0) { $arResFire = $firebird_north->select("SELECT * FROM ATTRIBUTE_DESCRIPTION "); foreach ($arResFire as $val) { if ($val->FIELD_CAPTION == "UID") $firebird_uid = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "APPROVE") $firebird_approve = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "UPLOAD_to_NIMDA") $firebird_upl_nimda = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; } $arRes = $firebird_north->select("SELECT * FROM SHOP_NOMENCLATURE_ATTRIBUTE WHERE " . $firebird_uid . "='" . $unique_id . "' "); } else { $goods = DB::table('goods')->where('id',$good_id)->get(); //if ($goods[0]->orig_id) $arRes = $firebird_north->select("SELECT * FROM SHOP_NOMENCLATURE WHERE SHOP_NOMENCLATURE_ID='" . $goods[0]->orig_id . "' "); } if (!empty($arRes)) { if (count($arRes) > 0) { $DIRECTORY_REGISTRY_ID = $arRes[0]->DIRECTORY_REGISTRY_ID; $arResGood = $firebird_north->select("SELECT * FROM SHOP_NOMENCLATURE WHERE DIRECTORY_REGISTRY_ID='" . $DIRECTORY_REGISTRY_ID . "' "); if (!empty($arResGood)) { if (count($arResGood) > 0) { foreach ($arResGood as $val) { $fire_price = $val->DEFAULT_COST; $artikul = iconv("cp1251","UTF-8", $val->NUMBER_MANUFACTURE); $artikul_name = iconv("cp1251","UTF-8", $val->FULLNAME); $quantity = 0; $brand_id = 0; if (isset($val->PRODUCER_ID)) { $arResProd = $firebird_north->select("SELECT * FROM PRODUCER WHERE PRODUCER_ID='" . $val->PRODUCER_ID . "'"); if (!empty($arResProd)) { foreach ($arResProd as $itmProd) { $artikul_brand_name = iconv("windows-1251","UTF-8",$itmProd->NAME); $brands = DB::table('brands')->where('name', $artikul_brand_name)->get(); if (!empty($brands[0])) $artikul_brand = $brands[0]->id; } } } /*$arQuant = $firebird_north->select(" EXECUTE PROCEDURE GET_SHOP_NOMENCLATURE_REST '" . $val->SHOP_NOMENCLATURE_ID . "' "); if (!empty($arQuant)) { $quantity = $arQuant[0]->GOODS_COUNT_ACCESSIBLE; }*/ } } } unset($arUpdate); //if (isset($quantity)) $arUpdate["quantity"] = $quantity; if (isset($fire_price)) $arUpdate["price"] = $fire_price; if (!empty($arUpdate)) DB::table('prices')->where('goods_id', $good_id)->where('sites_id', 6)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($artikul)) $arUpdate["artikul"] = $artikul; if (isset($artikul_name)) $arUpdate["name"] = $artikul_name; if (!empty($arUpdate)) DB::table('artikuls')->where('goods_id', $good_id)->where('sites_id', 6)->update($arUpdate); unset($arUpdate); //if (isset($artikul_name)) $arUpdate["name"] = $artikul_name; // 10.10.2018 if (isset($artikul_brand)) $arUpdate["brand_id"] = $artikul_brand; if (!empty($arUpdate)) DB::table('goods')->where('id', $good_id)->update($arUpdate); $fp = fopen('/home/bitrix/www/nimda/public/updateGoodFromSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s")." ad sever: unique_id: ".$unique_id.", good_id: ".$good_id.", with_autodealer: ".$with_autodealer.", result: ".serialize($arRes)."\r\n"); fclose($fp); } } } if (!isset($firebird_south_gone)) { if (isset($unique_id) AND intval($unique_id)>0) { $arResFire = $firebird_south->select("SELECT * FROM ATTRIBUTE_DESCRIPTION "); foreach ($arResFire as $val) { if ($val->FIELD_CAPTION == "UID") $firebird_uid = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "APPROVE") $firebird_approve = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "UPLOAD_to_NIMDA") $firebird_upl_nimda = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; } $arRes = $firebird_south->select("SELECT * FROM SHOP_NOMENCLATURE_ATTRIBUTE WHERE ".$firebird_uid."='" . $unique_id . "' "); } else { $goods = DB::table('goods')->where('id',$good_id)->get(); //if ($goods[0]->orig_id) $arRes = $firebird_south->select("SELECT * FROM SHOP_NOMENCLATURE WHERE SHOP_NOMENCLATURE_ID='" . $goods[0]->orig_id . "' "); } if (!empty($arRes)) { if (count($arRes) > 0) { $DIRECTORY_REGISTRY_ID = $arRes[0]->DIRECTORY_REGISTRY_ID; $arResGood = $firebird_south->select("SELECT * FROM SHOP_NOMENCLATURE WHERE DIRECTORY_REGISTRY_ID='" . $DIRECTORY_REGISTRY_ID . "' "); if (!empty($arResGood)) { if (count($arResGood) > 0) { foreach ($arResGood as $val) { $fire_price = $val->DEFAULT_COST; $artikul = iconv("cp1251","UTF-8", $val->NUMBER_MANUFACTURE); $artikul_name = iconv("cp1251","UTF-8", $val->FULLNAME); $quantity = 0; if (isset($val->PRODUCER_ID)) { $arResProd = $firebird_south->select("SELECT * FROM PRODUCER WHERE PRODUCER_ID='" . $val->PRODUCER_ID . "'"); if (!empty($arResProd)) { foreach ($arResProd as $itmProd) { $artikul_brand_name = iconv("windows-1251","UTF-8",$itmProd->NAME); $brands = DB::table('brands')->where('name', $artikul_brand_name)->get(); if (!empty($brands[0])) $artikul_brand = $brands[0]->id; } } } /*$arQuant = $firebird_south->select(" EXECUTE PROCEDURE GET_SHOP_NOMENCLATURE_REST '" . $val->SHOP_NOMENCLATURE_ID . "' "); if (!empty($arQuant)) { $quantity = $arQuant[0]->GOODS_COUNT_ACCESSIBLE; }*/ } } } unset($arUpdate); //if (isset($quantity)) $arUpdate["quantity"] = $quantity; if (isset($fire_price)) $arUpdate["price"] = $fire_price; if (!empty($arUpdate)) DB::table('prices')->where('goods_id', $good_id)->where('sites_id', 7)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($artikul)) $arUpdate["artikul"] = $artikul; if (isset($artikul_name)) $arUpdate["name"] = $artikul_name; if (!empty($arUpdate)) DB::table('artikuls')->where('goods_id', $good_id)->where('sites_id', 7)->update($arUpdate); unset($arUpdate); //if (isset($artikul_name)) $arUpdate["name"] = $artikul_name; if (isset($artikul_brand)) $arUpdate["brand_id"] = $artikul_brand; if (!empty($arUpdate)) DB::table('goods')->where('id', $good_id)->update($arUpdate); $fp = fopen('/home/bitrix/www/nimda/public/updateGoodFromSites.txt', 'a'); fwrite($fp, date("d.m.Y H:i:s")." ad ug: unique_id: ".$unique_id.", good_id: ".$good_id.", with_autodealer: ".$with_autodealer.", result: ".serialize($arRes)."\r\n"); fclose($fp); } } } /* if (!$firebird_south_gone) { $arResFire = $firebird->select("SELECT * FROM ATTRIBUTE_DESCRIPTION "); foreach ($arResFire as $val) { if ($val->FIELD_CAPTION == "UID") $firebird_uid = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "APPROVE") $firebird_approve = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; if ($val->FIELD_CAPTION == "UPLOAD_to_NIMDA") $firebird_upl_nimda = "FIELD_" . $val->ATTRIBUTE_DESCRIPTION_ID; } } */ //dd($arResult); } } } public function updateAllGoodsFromSites($with_autodealer = '') { if (!$with_autodealer) { $sites = Sites::where('autodealer', '=', '0')->get(); foreach ($sites as $site) { $JSON = ''; //if ($site->id == 3) //$JSON = file_get_contents('http://' . $site->address . '/rest/getAllElements.php'); //else $JSON = file_get_contents('https://' . $site->address . '/rest/getAllElements.php'); if ($JSON) $arResult = json_decode($JSON); if (!empty($arResult)) { foreach ($arResult as $result) { if (isset($result->unique_id) AND intval($result->unique_id)>0) { $good_id = 0; $goods = DB::table('goods')->where('unique_id', $result->unique_id)->get(); $good_id = $goods[0]->id; $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->name)) $arUpdate["name"] = $result->name; if (isset($result->brand)) $arUpdate["brand_id"] = $result->brand; if (isset($result->auto_mark)) $arUpdate["auto_mark"] = $result->auto_mark; if (isset($result->auto_model)) $arUpdate["auto_model"] = $result->auto_model; if (isset($result->sections_id)) $arUpdate["sections_id"] = $result->sections_id; DB::table('goods')->where('id', $good_id)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->artikul)) $arUpdate["artikul"] = $result->artikul; DB::table('artikuls')->where('goods_id', $good_id)->where('sites_id', $site->id)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->title)) $arUpdate["title"] = $result->title; if (isset($result->description)) $arUpdate["description"] = $result->description; if (isset($result->keywords)) $arUpdate["keywords"] = $result->keywords; DB::table('metas')->where('goods_id', $good_id)->where('sites_id', $site->id)->update($arUpdate); unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->price)) $arUpdate["price"] = $result->price; if (isset($result->price_currency)) $arUpdate["price_currency"] = $result->price_currency; if (isset($result->price_discount)) $arUpdate["discount"] = $result->price_discount; if (isset($result->price_discount_currency)) $arUpdate["discount_currency"] = $result->price_discount_currency; if (isset($result->price_install)) $arUpdate["install"] = $result->price_install; if (isset($result->price_install_currency)) $arUpdate["install_currency"] = $result->price_install_currency; if (isset($result->quantity)) $arUpdate["quantity"] = $result->quantity; if (isset($result->weight)) $arUpdate["weight"] = $result->weight; if (isset($result->width)) $arUpdate["width"] = $result->width; if (isset($result->length)) $arUpdate["length"] = $result->length; if (isset($result->height)) $arUpdate["height"] = $result->height; DB::table('prices')->where('goods_id', $good_id)->where('sites_id', $site->id)->update($arUpdate); /* unset($arUpdate); $arUpdate = array(); $arUpdate["updated_at"] = date("Y-m-d H:i:s"); if (isset($result->preview_text"])) $arUpdate["title"] = $result->preview_text"]; if (isset($result->detail_text"])) $arUpdate["description"] = $result->detail_text"]; DB::table('texts')->where('goods_id', $good_id)->where('sites_id', $site_id)->update($arUpdate); */ } } } } } } }