more buy item fixes

This commit is contained in:
Igor Barkov [iwork] 2019-01-14 19:40:14 +02:00
parent 378633b720
commit 872e200ac8

View File

@ -41,17 +41,16 @@ if ($sellItemId && is_numeric($sellItemId)) {
$deloText = "\"" . $user['login'] . "\" продал в магазин товар : \"" . $dress['name'] . "\" $kols id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $allcost . " кр. "; $deloText = "\"" . $user['login'] . "\" продал в магазин товар : \"" . $dress['name'] . "\" $kols id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $allcost . " кр. ";
db::c()->query('UPDATE `users` SET `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']); db::c()->query('UPDATE `users` SET `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']);
db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i)', $user['id'], $deloText, time()); db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i)', $user['id'], $deloText, time());
echo "<b style='color: red;'>Вы продали \"{$dress['name']}\" $kols за " . $allcost . " кр.</b>"; $status = "Вы продали \"{$dress['name']}\" $kols за " . $allcost . " кр.";
} }
if (!empty($_GET['buy'])) { if (!empty($_GET['buy'])) {
$dress = db::c()->query('SELECT * FROM `shop` WHERE `id`=?i', $_GET['buy'])->fetch_assoc(); $dress = db::c()->query('SELECT * FROM `shop` WHERE `id`=?i', $_GET['buy'])->fetch_assoc();
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `setsale` = 0', $_SESSION['uid'])->fetch_assoc();
if (($dress['massa'] + $itemWeight['m']) > (get_meshok())) $status = 'Недостаточно места в рюкзаке.';
if (($dress['massa'] + $itemWeight['m']) > (get_meshok())) { elseif ($user['money'] >= $dress['cost'] AND ($dress['count'] > 0 OR $dress['count'] == -1)) {
err('Недостаточно места в рюкзаке.');
} elseif ($user['money'] >= $dress['cost'] AND ($dress['count'] > 0 OR $dress['count'] == -1)) {
$newItem = [ $newItem = [
'prototype' => $dress['id'], 'prototype' => $dress['id'],
@ -111,24 +110,19 @@ if (!empty($_GET['buy'])) {
db::c()->query('INSERT INTO `inventory` SET ?A[?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,"?s",?i,?i,"?s",?i,?i]', $newItem); db::c()->query('INSERT INTO `inventory` SET ?A[?i,?i,"?s",?i,?i,?i,"?s",?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,?i,"?s",?i,?i,"?s",?i,?i]', $newItem);
if ($dress['count'] != -1) db::c()->query('UPDATE `shop` SET `count` = `count` - ?i WHERE `id` = ?i', $count, $set); $inventoryItemId = db::c()->getLastInsertId();
echo "<b style='color: red'>Вы купили {$count} шт. \"{$dress['name']}\".</b>"; if ($dress['count'] != -1) db::c()->query('UPDATE `shop` SET `count` = `count` - 1 WHERE `id` = ?i', $_GET['buy']);
$user['money'] -= $count * $dress['cost']; $status = "Вы купили \"{$dress['name']}\".";
db::c()->query('UPDATE `users` set `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']); db::c()->query('UPDATE `users` set `money` = ?i WHERE `id` = ?i', $dress['cost'], $_SESSION['uid']);
$invdb = db::c()->query('SELECT `id` FROM `inventory` WHERE `name` = "?s" ORDER BY `id` DESC LIMIT ?i', $dress['name'], $count);
$dressinv = $invdb->fetch_assoc(); $deloText = "\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . " id:(" . $inventoryItemId . ") [0/" . $dress['maxdur'] . "] за " . $dress['cost'] . " кр.";
$dressid = "cap" . $dressinv['id'];
$deloText = "\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . " id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $dress['cost'] . " кр.";
db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i', $user['id'], $deloText, time()); db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i', $user['id'], $deloText, time());
} else { } else {
echo "<b style='color: red;'>Недостаточно денег или нет вещей в наличии.</b>"; $status = "Недостаточно денег или нет вещей в наличии.";
} }
} }
$itemWeight = db::c()->query('SELECT sum(`massa`) AS `m` FROM `inventory` WHERE `owner` = ?i AND `dressed` = 0 AND `setsale` = 0', $user['id'])->fetch_assoc();
$shopCategoryType = empty($_POST['sale']) ?: $_POST['sale']; $shopCategoryType = empty($_POST['sale']) ?: $_POST['sale'];
$shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel']; $shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel'];
switch ($shopCategoryTypeNumber) { switch ($shopCategoryTypeNumber) {
@ -200,7 +194,7 @@ $shopItems = db::c()->query('SELECT `shop`.*,
FROM `shop` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `count` > 0 AND `cost` > 0 AND `razdel` = ?i ORDER by `nlevel` ASC, `id` ASC', $shopCategoryTypeNumber); FROM `shop` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `count` > 0 AND `cost` > 0 AND `razdel` = ?i ORDER by `nlevel` ASC, `id` ASC', $shopCategoryTypeNumber);
$iteminfo =[]; $iteminfo = [];
while ($row = $shopItems->fetch_assoc()) { while ($row = $shopItems->fetch_assoc()) {
$iteminfo[] = new ShopItem($row); $iteminfo[] = new ShopItem($row);
} }
@ -232,6 +226,7 @@ while ($row = $shopItems->fetch_assoc()) {
<body> <body>
<h1>Государственный магазин</h1> <h1>Государственный магазин</h1>
<a href=# onclick=leave()> ← выйти на Центральную площадь</a> <a href=# onclick=leave()> ← выйти на Центральную площадь</a>
<div><?php if (!empty($status)) err($status); ?></div>
<TABLE width=100% cellspacing="0" cellpadding="4"> <TABLE width=100% cellspacing="0" cellpadding="4">
<TR> <TR>
<TD valign=top align=left> <TD valign=top align=left>