Файл: app/shop/moneyback.php
Строк: 27
<?php
if (!$user->isAuth()) {
redirect('/');
exit;
}
$id = abs(intval($_GET['id']));
$shop = $db->prepare('SELECT * FROM `shop` WHERE `id` = ? and `user` = ?');
$shop -> execute([$id,$user->get()->user_id]);
$shop = $shop -> fetch(PDO :: FETCH_ASSOC);
if(!isset($shop['id'])){
header('Location: /?'.$id);
exit;
}
if(isset($_POST['money'])){
$money = abs($_POST['money']);
if($shop['money'] < $money){
Notif :: error('Не достаточно средств','/shop/moneyback?id='.$shop['id']);
exit;
}
if($money < 1){
Notif :: error('Минимум 1 руб. для вывода с площадки','/shop/moneyback?id='.$shop['id']);
exit;
}
$history = $db->prepare('insert into history (money,type,user,text,time) values (?,?,?,?,?)');
$history -> execute([$money,1,$user->get()->user_id,'Вывод средств с кассы '.$shop['name'],time()]);
$minus = $db->prepare('UPDATE `shop` SET `money` = ? WHERE `id` = ?');
$minus -> execute([$shop['money']-$money,$id]);
$plus = $db->prepare('UPDATE `users` SET `money` = ? WHERE `user_id` = ?');
$plus -> execute([$user->get()->money+$money,$user->get()->user_id]);
Notif :: message('Средства успешно переведены на личный счет','/shop');
exit;
}
echo $template->render('shop.moneyback', ['shop' => $shop]);