Файл: wenr.online/app/game/constantino_buy.php
Строк: 46
<?php
if (!$user->isAuth()) {
redirect('/');
exit;
}
$potion = $db->prepare('select * from `potion` where `id` = ?');
$potion -> execute([Clean :: int($_GET['id'])]);
$potion = $potion -> fetch(PDO :: FETCH_OBJ);
if(!isset($potion->id)){
redirect('/constantino');
exit;
}
if(isset($_GET['ok'])){
if($user->get()->gold < $potion->price){
Notif :: error('Не хватает золота для покупки зелья «'.$potion->name.'»','/constantino/buy?id='.$potion->id);
exit;
}
$sql = $db->prepare('insert into `bag` (`name`,`user`,`img`,`type`,`'.$potion->type.'`) values (?,?,?,?,?)');
$sql -> execute([$potion->name,$user->get()->user_id,$potion->type,'potion',$potion->plus]);
$update = $db->prepare('update `users` set `gold` = ? where `user_id` = ?');
$update -> execute([$user->get()->gold-$potion->price,$user->get()->user_id]);
Notif :: message('Вы успешно купили зелье «'.$potion->name.'»','/constantino/buy?id='.$potion->id);
exit;
}
function type_potion($type){
$array = ['hp'=>'Здоровье','mana'=>'Мана','force'=>'Сила'];
return $array[$type];
}
echo $template->render('game.constantino_buy', ['potion' => $potion]);