105 lines
3.8 KiB
PHP
105 lines
3.8 KiB
PHP
|
<?php
|
||
|
|
||
|
$_SERVER['SERVER_NAME']='tk-ligat.ru';
|
||
|
require_once('/home/cloud/core/set/tk-ligat.ru.php');
|
||
|
require_once('/home/cloud/core/api/php/db.php');
|
||
|
require_once('/home/cloud/core/api/php/json.php');
|
||
|
/*
|
||
|
|
||
|
$curl = curl_init('https://api.samsonopt.ru/v1/category/?api_key=4e2ef85d3ec9e27cc2a148c74a47d804');
|
||
|
$arHeaderList = array();
|
||
|
$arHeaderList[] = 'Accept: application/json';
|
||
|
$arHeaderList[] = 'User-Agent: string';
|
||
|
$arHeaderList[] = 'Accept-Encoding: gzip';
|
||
|
|
||
|
|
||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $arHeaderList);
|
||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||
|
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
|
||
|
$result = curl_exec($curl);
|
||
|
$list=json::from_j($result)['data'];
|
||
|
print_r($list);
|
||
|
for ($i=0; $i<count($list); $i++){
|
||
|
|
||
|
//$id=$list[$i]['id'];
|
||
|
//$name=$list[$i]['name'];
|
||
|
//$parent=$list[$i]['parent'];
|
||
|
//$img=$list[$i]['photo_list'];
|
||
|
echo $img[0];
|
||
|
|
||
|
DB::add("INSERT INTO `samson` (`id`, `name`, `parent`, `img`) VALUES (?, ?, ?, ?)", array($list[$i]['id'], $list[$i]['name'], $list[$i]['parent_id'], $img[0]));
|
||
|
|
||
|
unset($img);
|
||
|
|
||
|
}
|
||
|
|
||
|
curl_close($curl);
|
||
|
*/
|
||
|
|
||
|
$cats=DB::getAll("SELECT * FROM `samson` WHERE `parent`=0");
|
||
|
for ($i=0; $i<count($cats); $i++){
|
||
|
unset($r);
|
||
|
$r=DB::getValue("SELECT `id` FROM `tovar_category` WHERE `title`=? AND `category`=0", $cats[$i]['name']);
|
||
|
if (!$r)DB::add("INSERT INTO `tovar_category` (`title`, `code`, `code_p`, `partner`) VALUES(?, ?, ?, 'samson')", array($cats[$i]['name'], $cats[$i]['id'], $cats[$i]['parent']));
|
||
|
}
|
||
|
unset($cats);
|
||
|
unset($r);
|
||
|
$samson=DB::getAll("SELECT * FROM `samson` WHERE `parent`<>0");
|
||
|
for ($i=0; $i<count($samson); $i++){
|
||
|
//узнаем есть ли вообще это в нужной табле
|
||
|
$id=DB::getValue("SELECT `id` FROM `tovar_category` WHERE `title`=? AND `code`=? LIMIT 1", array($samson[$i]['name'], $samson[$i]['id']));
|
||
|
//если категории нет - думаем дальше...
|
||
|
if (!$id){
|
||
|
$up_cat_id=DB::getValue("SELECT `id` FROM `tovar_category` WHERE `code`=?", $samson[$i]['parent']);
|
||
|
DB::add("INSERT INTO `tovar_category` (`title`, `code`, `code_p`, `category`, `partner`) VALUES (?, ?, ?, ?, 'samson')",
|
||
|
array(
|
||
|
$samson[$i]['name'],
|
||
|
$samson[$i]['id'],
|
||
|
$samson[$i]['parent'],
|
||
|
$up_cat_id
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getCategory($code){
|
||
|
$curl = curl_init('https://api.samsonopt.ru/v1/sku/' . $code . '/?api_key=4e2ef85d3ec9e27cc2a148c74a47d804');
|
||
|
$arHeaderList = array();
|
||
|
$arHeaderList[] = 'Accept: application/json';
|
||
|
$arHeaderList[] = 'User-Agent: string';
|
||
|
$arHeaderList[] = 'Accept-Encoding: gzip';
|
||
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $arHeaderList);
|
||
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
|
||
|
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
|
||
|
$result = curl_exec($curl);
|
||
|
curl_close($curl);
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
//Херачим товар....
|
||
|
$tovar=DB::getAll("SELECT * FROM `tovar` WHERE `partner`='samson' AND `json` IS NULL ORDER BY RAND() LIMIT 1000");
|
||
|
$count=count($tovar);
|
||
|
for ($i=0; $i<$count; $i++){
|
||
|
echo 'Счетчик: ' . $count-- . "\n";
|
||
|
unset($code);
|
||
|
$j=getCategory($tovar[$i]['code']);
|
||
|
$m=json::from_j($j);
|
||
|
$code=@$m['data'][0]['category_list'];
|
||
|
for ($sss=0; $sss<@count($code); $sss++){
|
||
|
$id=DB::getValue("SELECT `id` FROM `tovar_category` WHERE `code`=? LIMIT 1", $code[$sss]);
|
||
|
if (@$id) @$txt = @$txt . "--" . $id . "--";
|
||
|
}
|
||
|
if (@$txt)
|
||
|
DB::set("UPDATE `tovar` SET `category`=?, `json`=?, `status`=1 WHERE `id`=?", array($txt, $j, $tovar[$i]['id']));
|
||
|
else
|
||
|
DB::set("UPDATE `tovar` SET `status`=0 WHERE `id`=?", $tovar[$i]['id']);
|
||
|
|
||
|
unset($code2);
|
||
|
echo @$txt . "\n";
|
||
|
unset($txt);
|
||
|
unset($id);
|
||
|
sleep(1);
|
||
|
}
|
||
|
?>
|