core/api/modules/tovar_show/index.php

207 lines
10 KiB
PHP
Raw Normal View History

2022-12-11 13:55:49 +05:00
<?php
2022-12-17 18:15:09 +05:00
ini_set( 'display_errors', 0 );
2023-01-02 21:33:36 +05:00
@mkdir( 'img/' . $_SERVER['SERVER_NAME'] . '/cert', 0700 );
@mkdir( 'img/' . $_SERVER['SERVER_NAME'] . '/tovar/square', 0700 );
2023-03-05 20:22:21 +05:00
if (!$_SESSION['user_id'])$smarty -> caching = false;
2023-01-02 21:33:36 +05:00
$smarty -> cache_lifetime = 86400;
2023-02-28 21:22:24 +05:00
2023-03-05 20:22:21 +05:00
/* ----------------------------------------------------------------------
01.03.2023
Получаем историю просмотров
---------------------------------------------------------------------- */
$tovarHistory=\DB::getAll( "SELECT `id`, `title`, `akccena` FROM `tovar` WHERE `id` IN ( SELECT `tovar_id` FROM `tovar_history` WHERE `session_id`=? ORDER BY RAND()) AND `status`=1 LIMIT 20", \core::checkMe() );
for ( $i=0; $i < count( $tovarHistory ); $i++ ){
$tovarHistory[$i]['cena'] = \DB::getValue ( "SELECT `cena` FROM `tovar_price_history` WHERE `status`=1 AND `tovar_id`=? ORDER BY `t` DESC", $tovarHistory[$i]['id'] );
$tovarHistory[$i]['img'] = \DB::getValue ( "SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1", $tovarHistory[$i]['id']);
}
$smarty -> assign( 'tovarHistory', $tovarHistory );
2023-02-28 21:22:24 +05:00
/* ----------------------------------------------------------------------
28.02.2023
Получаем коментарии
---------------------------------------------------------------------- */
$comments = \DB::getAll( "SELECT * FROM `tovar_otzyv` WHERE `tovar_id`=? AND `status`=1 ORDER BY `t` DESC", $_GET['id'] );
for ( $i=0; $i < count($comments); $i++ ) $comments[$i]['fio'] = \DB::getValue( "SELECT `fio` FROM `users` WHERE `id`=?", $comments[$i]['user_id'] );
$smarty -> assign( 'comments', $comments );
$smarty -> assign( 'inc_comments', 'api/modules/tovar_show/comments.html' );
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12.2022
Получаем данные о товаре
---------------------------------------------------------------------- */
2023-01-07 18:55:55 +05:00
$page = \DB::getAll( "SELECT * FROM `tovar` WHERE `id`=? LIMIT 1", $_GET['id'] );
2022-12-17 18:15:09 +05:00
$page[0]['date'] = date( 'd.m.Y', @$page[0]['t'] );
2022-12-24 21:12:23 +05:00
2023-03-05 20:22:21 +05:00
/* ----------------------------------------------------------------------
03.03.2023
Смотрим есть ли цена из таблицы товаров в регистре цен, если нет -
переносим данные туда и убираем из товара
---------------------------------------------------------------------- */
$tmpCena=\DB::getValue("SELECT `cena` FROM `tovar_price_history` WHERE `tovar_id`=? AND `status`=1 ORDER BY `t` DESC LIMIT 1", $_GET['id']);
if ($page[0]['cena']!=$tmpCena && $page[0]['cena']){
//Создаем документ
$jsonDoc[0]['tovar_id']=$_GET['id'];
$jsonDoc[0]['cena']=$page[0]['cena'];
$docID=\DB::add("INSERT INTO `docs` (`t`, `tip`, `json`, `status`, `comment`) VALUES(?, 'pereocenka', ?, 1, ?)", array( time(), \json::to_j($jsonDoc), 'Документ создан из публичной карточки товара' ));
\DB::add("INSERT INTO `tovar_price_history` (`status`, `tovar_id`, `cena`, `docs_id`, `t`) VALUES (1, ?, ?, ?, ?)", array( $_GET['id'], $page[0]['cena'], $docID, time() ));
\DB::set("UPDATE `tovar` SET `cena`=NULL WHERE `id`=?", $_GET['id']);
}
2023-01-07 18:55:55 +05:00
/* ----------------------------------------------------------------------
03.01.2023
Хлебные крошки
---------------------------------------------------------------------- */
$smarty->assign('Breadcrumb', \core::getBreadcrumb( 'tovar_category', $page[0]['category'] ) );
/* ----------------------------------------------------------------------
03.01.2023
Получаем картинку категории
---------------------------------------------------------------------- */
$smarty->assign('catImg', \DB::getValue( "SELECT `filename` FROM `tovar_category_img` WHERE `tovar_category_id`=?", $page[0]['category'] ) );
2022-12-24 21:12:23 +05:00
/* ----------------------------------------------------------------------
17.12.2022
Получаем данные о последней цене на товар
---------------------------------------------------------------------- */
2023-01-02 21:33:36 +05:00
$cena=\DB::getAll ( "SELECT `cena`, `t` FROM `tovar_price_history` WHERE `status`=1 AND `tovar_id`=? ORDER BY `t` DESC", $_GET['id']);
2023-02-25 22:58:56 +05:00
if ( $page[0]['partner']=='samson'){ //Берем цену с сайта партнера
2023-01-02 21:33:36 +05:00
$curl = curl_init('https://api.samsonopt.ru/v1/sku/' . $page[0]['code'] . '/?api_key=4e2ef85d3ec9e27cc2a148c74a47d804');
$arHeaderList = array();
$arHeaderList[] = 'Accept: application/json';
$arHeaderList[] = 'User-Agent: 4e2ef85d3ec9e27cc2a148c74a47d804';
$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');
$result2 = \json::from_j(curl_exec($curl));
curl_close($curl);
//\DB::set( "UPDATE `tovar` SET `json`=? WHERE `id`=?", array( $result2, $_GET['id'] ) );
//print_r($result2['data'][0]);
//Сохраняем штрих код
$barcode=$result2['data'][0]['barcode'];//str
if ($barcode){
$id_barcode=\DB::getValue("SELECT `id` FROM `tovar_barcode` WHERE `barcode`=? AND `tovar_id`=? LIMIT 1", array( $barcode, $_GET['id'] ) );
if (!$id_barcode)\DB::add("INSERT INTO `tovar_barcode` (`barcode`, `tovar_id`) VALUES (?, ?)", array( $barcode, $_GET['id'] ));
}
$brand=$result2['data'][0]['brand'];//str
if($brand){
$id_brand=\DB::getValue("SELECT `id` FROM `tovar_brand` WHERE `brand`=? AND `tovar_id`=? LIMIT 1", array( $brand, $_GET['id'] ) );
if (!$id_brand)\DB::add("INSERT INTO `tovar_brand` (`brand`, `tovar_id`) VALUES (?, ?)", array( $brand, $_GET['id'] ));
}
2023-02-25 22:58:56 +05:00
}
2023-01-02 21:33:36 +05:00
/*
//Загружаем правильные картинки
if ($page[0]['check_img']!=1){
$images=$result2['data'][0]['photo_list'];//array
$old_img=\DB::getAll("SELECT * FROM `tovar_img` WHERE `tovar_id`=?", $_GET['id']);
for ($i=0; $i<count($old_img); $i++) unlink( 'img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $old_img[$i]['filename'] . '.jpg');
if ($images)\DB::set("DELETE FROM `tovar_img` WHERE `tovar_id`=?", $_GET['id']);
$count_img=count($images);
for ($i=0; $i<$count_img; $i++){
$rndname=\core::genpassword(30);
exec ("wget " . foolImg($images[$i]) . " -O img/" . $_SERVER['SERVER_NAME'] . "/tovar/" . $rndname . ".jpg");
\DB::add("INSERT INTO `tovar_img` (`filename`, `tovar_id`) VALUES (?, ?)", array( $rndname, $_GET['id'] ) );
\DB::set("UPDATE `tovar` SET `check_img`=1 WHERE `id`=?", $_GET['id']);
}
}
$hars_list=$result2['data'][0]['facet_list'];//array
//print_r($hars_list);
//}
*/
$page[0]['cena'] = ( $partner_cena ) ? $partner_cena : $cena[0]['cena'];
2022-12-24 21:12:23 +05:00
2022-12-17 18:15:09 +05:00
$smarty -> assign( 'page', $page );
2022-12-11 13:55:49 +05:00
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12.2022
Получаем картинки
---------------------------------------------------------------------- */
$imagesTovar = \DB::getAll( "SELECT * FROM `tovar_img` WHERE `tovar_id`=?", $_GET['id'] );
2023-01-02 21:33:36 +05:00
if ($_SERVER['SERVER_NAME']=='v.yurecnt.ru'){
2023-03-11 21:03:29 +05:00
for ($i=0; $i<count($imagesTovar); $i++){
if (!file_exists('img/' . $_SERVER['SERVER_NAME'] . '/tovar/square/' . $imagesTovar[$i]['filename'] . '.jpg')) \core::imgPreview('img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $imagesTovar[$i]['filename'] . '.jpg', 'img/' . $_SERVER['SERVER_NAME'] . '/tovar/square/' . $imagesTovar[$i]['filename'] . '.jpg');
}
/*require_once('api/php/thumbs/thumbs.php');
for ($i=0; $i<count($imagesTovar); $i++){
//Проверяем сущетсование картинки.....
if (!file_exists('img/' . $_SERVER['SERVER_NAME'] . '/tovar/square/' . $imagesTovar[$i]['filename'] . '.jpg')) {
$image = new Thumbs('img/' . $_SERVER['SERVER_NAME'] . '/tovar/' . $imagesTovar[$i]['filename'] . '.jpg');
$image->thumb(600, 400);
$image->save('img/' . $_SERVER['SERVER_NAME'] . '/tovar/square/' . $imagesTovar[$i]['filename'] . '.jpg');
unset ($image);
}
2023-03-11 21:03:29 +05:00
}*/
}
$smarty -> assign( 'imagesTovar', $imagesTovar );
2023-01-02 21:33:36 +05:00
$countImg=count($imagesTovar);
\DB::set("UPDATE `tovar` SET `countImg`=? WHERE `id`=?", array( $countImg, $_GET['id'] ) );
2022-12-17 18:15:09 +05:00
/* ----------------------------------------------------------------------
17.12.2022
Получаем характеристики из БД
---------------------------------------------------------------------- */
$har = \DB::getAll( "SELECT * FROM `tovar_har` WHERE `tovar_id`=?", $_GET['id'] );
2023-02-08 16:59:59 +05:00
for ( $i=0; $i < count( $har ); $i++ ) $har[$i]['opt']=\DB::getValue("SELECT `txt` FROM `tovar_har_sp` WHERE `id`=?", $har[$i]['tovar_har_sp_id']);
2022-12-17 18:15:09 +05:00
$smarty -> assign( 'har', $har );
/* ----------------------------------------------------------------------
17.12.2022
Пишем историю
---------------------------------------------------------------------- */
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
unset($id);
$id=\DB::getValue("SELECT `id` FROM `tovar_history` WHERE `tovar_id`=? AND `session_id`=?", array( $_GET['id'], $session_id ) );
if (!$id) \DB::add( "INSERT INTO `tovar_history` (`tovar_id`, `session_id`, `t`) VALUES (?, ?, ?)", array( $_GET['id'], $session_id, time() ) );
2022-12-11 13:55:49 +05:00
2022-12-17 18:15:09 +05:00
2022-12-11 13:55:49 +05:00
/* ----------------------------------------------------------------------
2023-02-08 16:59:59 +05:00
05.02.2023
ищем похожие товары - этой же категории, но рандомно
2022-12-11 13:55:49 +05:00
---------------------------------------------------------------------- */
2023-02-08 16:59:59 +05:00
$rndTovar=\DB::getAll("SELECT * FROM `tovar` WHERE `category`=? ORDER BY RAND() LIMIT 10", $page[0]['category']);
//print_r($rndTovar);
for ($i=0; $i<count($rndTovar); $i++){
$rndTovar[$i]['cena']=\DB::getValue('SELECT `cena` FROM `tovar_price_history` WHERE `status`=1 AND `tovar_id`=? ORDER BY `id` DESC LIMIT 1', $rndTovar[$i]['id']);
$rndTovar[$i]['img']=\DB::getValue('SELECT `filename` FROM `tovar_img` WHERE `tovar_id`=? LIMIT 1', $rndTovar[$i]['id']);
}
$smarty -> assign( 'rndTovar', $rndTovar );
2023-01-07 18:55:55 +05:00
//$smarty->assign('keywords', \core::getMeta( $_GET['mod'], $_GET['id'], 'keywords') );
//$smarty->assign('description', \core::getMeta( $_GET['mod'], $_GET['id'], 'description') );
2022-12-11 13:55:49 +05:00
?>