2022-12-11 13:55:49 +05:00
|
|
|
|
<?php
|
2023-03-11 21:03:29 +05:00
|
|
|
|
ini_set( 'display_errors', 1 );
|
|
|
|
|
|
2023-07-12 20:02:20 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendZakazOnEmail($id){
|
|
|
|
|
require_once "api/php/sendmail.php";
|
|
|
|
|
//получаем данные о магазине
|
|
|
|
|
$org_id=\core::getSettings("main_org");
|
|
|
|
|
$email=DB::getValue("SELECT `email` FROM `org` WHERE `id`=?", $org_id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
send_mime_mail($_SERVER['SERVER_NAME'], // имя отправителя.
|
|
|
|
|
|
|
|
|
|
$email, // email отправителя.
|
|
|
|
|
|
|
|
|
|
"Вы", // имя получателя.
|
|
|
|
|
|
|
|
|
|
$email, // email получателя.
|
|
|
|
|
|
|
|
|
|
"UTF-8", // кодировка переданных данных.
|
|
|
|
|
|
|
|
|
|
"Windows-1251", // кодировка письма.
|
|
|
|
|
|
|
|
|
|
"Новый заказ с сайта " . $_SERVER['SERVER_NAME'], // тема письма.
|
|
|
|
|
|
|
|
|
|
'Номер заказа - #' . $id // текст письма.
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-12-24 21:12:23 +05:00
|
|
|
|
switch( @$_POST['act'] ) {
|
2023-07-12 20:02:20 +05:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
24.06.2023
|
|
|
|
|
Лигат - добавление заказа для юр или физ лица + адрес доставки
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
case 'zak-auth':
|
|
|
|
|
if (!$_SESSION['user_id'])die("403");
|
|
|
|
|
//Проверяем, что корзина не пуста
|
|
|
|
|
$check=\DB::getValue("SELECT `id` FROM `cart` WHERE `user_id`=? AND `order` IS NULL", $_SESSION['user_id']);
|
|
|
|
|
if (!$check)die(0);
|
|
|
|
|
|
|
|
|
|
$id=\DB::add("INSERT INTO `orders` (`t`, `user_id`, `org_id`, `adres_dostavki`) VALUES (?, ?, ?, ?)", array(
|
|
|
|
|
time(),
|
|
|
|
|
$_SESSION['user_id'],
|
|
|
|
|
$_POST['o'],
|
|
|
|
|
$_POST['d']
|
|
|
|
|
));
|
|
|
|
|
\DB::set("UPDATE `cart` SET `order`=? WHERE `user_id`=? AND `order` IS NULL", array(
|
|
|
|
|
$id, $_SESSION['user_id']
|
|
|
|
|
));
|
|
|
|
|
echo $id;
|
|
|
|
|
sendZakazOnEmail($id);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-24 21:12:23 +05:00
|
|
|
|
case 'change-kolvo':
|
|
|
|
|
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
|
|
|
|
|
\DB::set( "UPDATE `cart` SET `kolvo`=? WHERE `id`=? AND `user_id`=?", array( $_POST['kolvo'], $_POST['id'], $session_id ) ) ;
|
|
|
|
|
$res=\core::getCart();
|
|
|
|
|
echo $res['summ'];
|
2022-12-11 13:55:49 +05:00
|
|
|
|
break;
|
|
|
|
|
|
2022-12-24 21:12:23 +05:00
|
|
|
|
case 'del-from-cart':
|
|
|
|
|
$session_id = ( $_SESSION['user_id'] ) ? $_SESSION['user_id'] : session_id();
|
|
|
|
|
\DB::set( "DELETE FROM `cart` WHERE `id`=? AND `user_id`=?", array( $_POST['id'], $session_id ) ) ;
|
|
|
|
|
$res=\core::getCart();
|
|
|
|
|
echo $res['summ'];
|
2022-12-11 13:55:49 +05:00
|
|
|
|
break;
|
2022-12-24 21:12:23 +05:00
|
|
|
|
|
2023-03-11 21:03:29 +05:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
06.03.2023
|
|
|
|
|
Простое оформление заказа на зарегистрированного физ лица
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
case 'zakazFz':
|
|
|
|
|
if (!$_SESSION['user_id'])die("403");
|
|
|
|
|
//Создаем заказ
|
|
|
|
|
$insert_id=\DB::add("INSERT INTO `orders` (`user_id`, `status`, `t`) VALUES (?, ?, ?)", array($_SESSION['user_id'], 0, time()));
|
|
|
|
|
//обновляем данные в корзине
|
|
|
|
|
\DB::set("UPDATE `cart` SET `order`=? WHERE `user_id`=? AND `order` IS NULL", array($insert_id, $_SESSION['user_id']));
|
|
|
|
|
break;
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
|
11.03.2023
|
|
|
|
|
Простое оформление заказа на НЕ зарегистрированного физ лица
|
|
|
|
|
---------------------------------------------------------------------- */
|
|
|
|
|
case 'zakazFzAnonim':
|
|
|
|
|
$user=\core::checkMe();
|
|
|
|
|
if ( $db['type'] == 'mysql' ) \DB::alterTable( "ALTER TABLE `orders` ADD `email` varchar(254) COLLATE 'utf8_general_ci' NULL" );
|
|
|
|
|
if ( $db['type']=='sqlite3' ) \DB::alterTable( "ALTER TABLE `orders` ADD `email` TEXT" );
|
|
|
|
|
//Создаем заказ
|
|
|
|
|
$insert_id=\DB::add("INSERT INTO `orders` (`user_id`, `status`, `t`, `fio`, `tel`, `email`) VALUES (?, ?, ?, ?, ?, ?)", array($user, 0, time(), $_POST['fio'], $_POST['tel'], $_POST['email'] ));
|
|
|
|
|
//обновляем данные в корзине
|
|
|
|
|
\DB::set("UPDATE `cart` SET `order`=? WHERE `user_id`=? AND `order` IS NULL", array($insert_id, $user));
|
|
|
|
|
break;
|
2022-12-11 13:55:49 +05:00
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
?>
|