65 lines
2.7 KiB
PHP
65 lines
2.7 KiB
PHP
|
<?php
|
|||
|
|
|||
|
require_once('/home/cloud/core/api/php/db.php');
|
|||
|
require_once('/home/cloud/core/api/php/json.php');
|
|||
|
DB::$type='sqlite3';
|
|||
|
DB::$path='/home/cloud/core/bd/tk-ligat.ru.db';
|
|||
|
|
|||
|
function generate_password($number){
|
|||
|
$arr = array('a','b','c','d','e','f', 'g','h','i','j','k','l','m','n','o','p','r','s','t','u','v','x','y','z','1','2','3','4','5','6','7','8','9','0');
|
|||
|
$pass = "";
|
|||
|
for($i = 0; $i < $number; $i++){
|
|||
|
$index = rand(0, count($arr) - 1);
|
|||
|
$pass .= $arr[$index];
|
|||
|
}
|
|||
|
return $pass;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$current=file_get_contents('../goods_sur102215_dcc93d1672486819.xml');
|
|||
|
$xml = simplexml_load_string($current, "SimpleXMLElement", LIBXML_NOCDATA);
|
|||
|
$json = json_encode($xml);
|
|||
|
$array = json_decode($json,TRUE);
|
|||
|
|
|||
|
$tovar=$array['Товар'];
|
|||
|
|
|||
|
for ($i=0; $i<count($tovar); $i++){
|
|||
|
$insert['code']=$tovar[$i]['@attributes']['код'];
|
|||
|
$insert['artikul']=@$tovar[$i]['Артикул'];
|
|||
|
$insert['title']=$tovar[$i]['Наименование'];
|
|||
|
$insert['txt']='<p>' . @$tovar[$i]['Описание'] . '</p><p>' . @$tovar[$i]['РасширенноеОписание'] . '</p>';
|
|||
|
$check=DB::getValue("SELECT `id` FROM `tovar` WHERE `code`=? LIMIT 1", $insert['code']);
|
|||
|
if (!$check){
|
|||
|
DB::add("INSERT INTO `tovar` (`code`, `artikul`, `title`, `txt`) VALUES (?, ?, ?, ?)", array( $insert['code'], $insert['artikul'], $insert['title'], $insert['txt'] ));
|
|||
|
$tovar_id=DB::getValue("SELECT `id` FROM `tovar` WHERE `code`=? LIMIT 1", $insert['code']);
|
|||
|
//Берем картинки
|
|||
|
$fotos=$tovar[$i]['Фотографии']['Фото1500'];
|
|||
|
for ($j=0; $j<count($fotos); $j++){
|
|||
|
$filename=generate_password(30);
|
|||
|
exec("wget " . $fotos[$j] . " -O /home/cloud/core/img/tk-ligat.ru/tovar/" . $filename . ".jpg");
|
|||
|
DB::add("INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?)", array( $filename, $tovar_id ) );
|
|||
|
}
|
|||
|
$cena=round ( $tovar[$i]['Цена']*1.5 );
|
|||
|
$t=time();
|
|||
|
$massiv[0]['tovar_id']=$tovar_id;
|
|||
|
$massiv[0]['cena']=$cena;
|
|||
|
$json=json::to_j($massiv);
|
|||
|
DB::add( "INSERT INTO `docs` (`t`, `tip`, `json`, `status`, `comment`) VALUES('" . $t . "', 'pereocenka', ?, 1, 'Документ создан из публичной карточки товара')", $json );
|
|||
|
$doc_id=DB::getValue("SELECT `id` FROM `docs` WHERE `json`=? AND `t`=? LIMIT 1", array( $json, $t ) );
|
|||
|
if ($doc_id) DB::add( "INSERT INTO `tovar_price_history` (`t`, `tovar_id`, `status`, `cena`, `docs_id`) VALUES(?, ?, ?, ?, ?)", array( $t, $tovar_id, '1', $cena, $doc_id ) );
|
|||
|
//print_r($insert);
|
|||
|
unset($insert);
|
|||
|
unset($tovar_id);
|
|||
|
unset($id);
|
|||
|
unset($fotos);
|
|||
|
unset($cena);
|
|||
|
unset($check);
|
|||
|
unset($doc_id);
|
|||
|
unset($massiv);
|
|||
|
unset($json);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
?>
|