more buy item fixes
This commit is contained in:
parent
378633b720
commit
872e200ac8
31
shop.php
31
shop.php
@ -41,17 +41,16 @@ if ($sellItemId && is_numeric($sellItemId)) {
|
||||
$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('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'])) {
|
||||
|
||||
$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())) {
|
||||
err('Недостаточно места в рюкзаке.');
|
||||
} elseif ($user['money'] >= $dress['cost'] AND ($dress['count'] > 0 OR $dress['count'] == -1)) {
|
||||
if (($dress['massa'] + $itemWeight['m']) > (get_meshok())) $status = 'Недостаточно места в рюкзаке.';
|
||||
elseif ($user['money'] >= $dress['cost'] AND ($dress['count'] > 0 OR $dress['count'] == -1)) {
|
||||
|
||||
$newItem = [
|
||||
'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);
|
||||
if ($dress['count'] != -1) db::c()->query('UPDATE `shop` SET `count` = `count` - ?i WHERE `id` = ?i', $count, $set);
|
||||
echo "<b style='color: red'>Вы купили {$count} шт. \"{$dress['name']}\".</b>";
|
||||
$user['money'] -= $count * $dress['cost'];
|
||||
db::c()->query('UPDATE `users` set `money` = ?i WHERE `id` = ?i', $user['money'], $user['id']);
|
||||
$invdb = db::c()->query('SELECT `id` FROM `inventory` WHERE `name` = "?s" ORDER BY `id` DESC LIMIT ?i', $dress['name'], $count);
|
||||
$inventoryItemId = db::c()->getLastInsertId();
|
||||
if ($dress['count'] != -1) db::c()->query('UPDATE `shop` SET `count` = `count` - 1 WHERE `id` = ?i', $_GET['buy']);
|
||||
$status = "Вы купили \"{$dress['name']}\".";
|
||||
db::c()->query('UPDATE `users` set `money` = ?i WHERE `id` = ?i', $dress['cost'], $_SESSION['uid']);
|
||||
|
||||
$dressinv = $invdb->fetch_assoc();
|
||||
$dressid = "cap" . $dressinv['id'];
|
||||
|
||||
$deloText = "\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . " id:(" . $dressid . ") [0/" . $dress['maxdur'] . "] за " . $dress['cost'] . " кр.";
|
||||
$deloText = "\"" . $user['login'] . "\" купил товар : \"" . $dress['name'] . " id:(" . $inventoryItemId . ") [0/" . $dress['maxdur'] . "] за " . $dress['cost'] . " кр.";
|
||||
db::c()->query('INSERT INTO `delo` (`pers`, `text`, `type`, `date`) VALUES (?i, "?s", 1, ?i', $user['id'], $deloText, time());
|
||||
|
||||
|
||||
} 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'];
|
||||
$shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel'];
|
||||
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);
|
||||
|
||||
$iteminfo =[];
|
||||
$iteminfo = [];
|
||||
while ($row = $shopItems->fetch_assoc()) {
|
||||
$iteminfo[] = new ShopItem($row);
|
||||
}
|
||||
@ -232,6 +226,7 @@ while ($row = $shopItems->fetch_assoc()) {
|
||||
<body>
|
||||
<h1>Государственный магазин</h1>
|
||||
<a href=# onclick=leave()> ← выйти на Центральную площадь</a>
|
||||
<div><?php if (!empty($status)) err($status); ?></div>
|
||||
<TABLE width=100% cellspacing="0" cellpadding="4">
|
||||
<TR>
|
||||
<TD valign=top align=left>
|
||||
|
Loading…
Reference in New Issue
Block a user