Оплата через класс банка. Чистка кода.

This commit is contained in:
Igor Barkov (iwork) 2020-09-30 15:11:16 +03:00
parent a08ce17a40
commit dc47050b54
1 changed files with 42 additions and 23 deletions

View File

@ -22,36 +22,55 @@ function setProfession($name, $type, $needMoney, $needLevel)
{
global $user;
$profId = 0;
if (!in_array($name, ['оружейник', 'наёмник', 'лекарь'])) return 'Такой профессии не существует!';
if ($user['money'] < $needMoney) return 'Недостаточно денег!';
if ($user['level'] < $needLevel) return 'Ваш уровень ещё мал для этой профессии!';
if (!empty($user['prof1']) AND $type == 1) return 'Ошибка! У вас уже есть другая мирная профессия!';
if (!empty($user['prof2']) AND $type == 2) return 'Ошибка! У вас уже есть другая боевая профессия!';
if ($name == 'оружейник') $profId = 1;
if ($name == 'наёмник') $profId = 21;
if ($name == 'лекарь') $profId = 22;
if (!in_array($name, ['оружейник', 'наёмник', 'лекарь'])) {
return 'Такой профессии не существует!';
}
if ($user['money'] < $needMoney) {
return 'Недостаточно денег!';
}
if ($user['level'] < $needLevel) {
return 'Ваш уровень ещё мал для этой профессии!';
}
if (!empty($user['prof1']) && $type == 1) {
return 'Ошибка! У вас уже есть другая мирная профессия!';
}
if (!empty($user['prof2']) && $type == 2) {
return 'Ошибка! У вас уже есть другая боевая профессия!';
}
if ($name == 'оружейник') {
$profId = 1;
}
if ($name == 'наёмник') {
$profId = 21;
}
if ($name == 'лекарь') {
$profId = 22;
}
if (!empty($profId)) {
try {
db::c()->query('UPDATE `users` SET ?f = ?i, `money` = `money` - ?i WHERE `id` = ?i', 'prof' . $type, $profId, $needMoney, $_SESSION['uid']);
} catch (\Krugozor\Database\Mysql\Exception $e) {
}
$user->money -= $needMoney;
Bank::setWalletMoney($user->money, $user->id);
db::c()->query('UPDATE `users` SET ?f = ?i WHERE `id` = ?i', 'prof' . $type, $profId, $user->id);
$deloText = "{$user['login']} купил профессию «{$name}» в академии за {$needMoney} кр.";
addToDelo($deloText);
$user['prof'.$type] = true;
$user['money'] -= $needMoney;
return 'Вы получили профессию!';
} else return 'Что-то пошло не так...';
} else {
return 'Что-то пошло не так...';
}
}
if ($get == 'smith') $status = setProfession('оружейник', 1, 300, 3);
if ($get == 'mercenary') $status = setProfession('наёмник', 2, 700, 5);
if ($get == 'medic') $status = setProfession('лекарь', 2, 700, 5);
if ($get == 'smith') {
$status = setProfession('оружейник', 1, 300, 3);
}
if ($get == 'mercenary') {
$status = setProfession('наёмник', 2, 700, 5);
}
if ($get == 'medic') {
$status = setProfession('лекарь', 2, 700, 5);
}
if ($get == 'exit') {
try {
db::c()->query('UPDATE `users`,`online` SET `users`.`room` = 2702, `online`.`room` = 2702 WHERE `users`.`id` = ?i AND `online`.`id` = ?i', $_SESSION['uid'], $_SESSION['uid']);
} catch (\Krugozor\Database\Mysql\Exception $e) {
}
db::c()->query('UPDATE `users`,`online` SET `users`.`room` = 2702, `online`.`room` = 2702 WHERE `users`.`id` = ?i AND `online`.`id` = ?i', $user->id, $user->id);
header('Location: city.php');
}
?>
@ -71,8 +90,8 @@ if ($get == 'exit') {
<div><?php if (!empty($status)) err($status); ?></div>
<div class="appblock appblock-main">
<span class="legend">Информация</span>
<span class="wrap">Кредиты<span class="num"><?= $user['money'] ?></span></span>
<span class="wrap">Уровень персонажа<span class="num"><?= $user['level'] ?></span></span>
<span class="wrap">Кредиты<span class="num"><?= $user->money ?></span></span>
<span class="wrap">Уровень персонажа<span class="num"><?= $user->level ?></span></span>
</div>
<div class="appblock">
<span class="legend">Наёмник</span>