['min_range' => 1]]);
$itemId = (int)filter_input(INPUT_GET, 'n', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$returningItemId = (int)filter_input(INPUT_GET, 'back', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$puttingItemPrice = (int)filter_input(INPUT_POST, 'cost', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
//if (isset($_GET['kredit'])) $itemCost = checkIntInRange($_GET['kredit']);
//if (isset($_GET['n'])) $itemId = checkIntInRange($_GET['n']);
//if (isset($_GET['back'])) $returningItemId = checkIntInRange($_GET['back']);
if ($itemCost && $itemId) {
$commission = ceil($itemCost / 10); # 10% от суммы с округлением вверх.
if ($user['money'] > $commission) {
$dress = db::c()->query('SELECT `name`,`duration`,`maxdur` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i', $itemId, $_SESSION['uid'])->fetch_assoc();
if (db::c()->getAffectedRows()) {
$deloText = "{$user['login']} выставил товар: «{$dress['name']}» id:({$itemId}) [{$dress['duration']}/{$dress['maxdur']}] на продажу в комиссионку за {$itemCost} кр. ";
addToDelo($deloText);
db::c()->query('UPDATE `inventory` SET `setsale` = ?i WHERE `id` = ?i', $itemCost, $itemId);
db::c()->query('UPDATE `users` SET `money` = `money` - ?i WHERE `id` = ?i', $commission, $_SESSION['uid']);
$status = "Вы сдали в магазин «{$dress['name']}» за {$itemCost} кр. Вычтено за услуги магазина: {$commission} кр.";
} else $status = "Предмет не найден в инвентаре!";
} else $status = "У вас не хватает " . $commission - $user['money'] . " кр. чтобы оплатить комиссию!";
}
if ($returningItemId) {
$dress = db::c()->query('SELECT `name`,`duration`,`maxdur` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `id` = ?i AND `owner` = ?i', $returningItemId, $_SESSION['uid'])->fetch_assoc();
if (db::c()->getAffectedRows()) {
$deloText = "{$user['login']} забрал свой товар: «{$dress['name']}» id:({$returningItemId}) [{$dress['duration']}/{$dress['maxdur']}] из комиссионки.";
addToDelo($deloText);
db::c()->query('UPDATE `inventory` SET `setsale` = 0 WHERE `id` = ?i', $returningItemId);
$status = "Вы забрали из магазина ваш «{$dress['name']}».";
} else $status = "Предмет не найден на полках магазина!";
}
if (isset($_POST['puttomarket']) AND $puttingItemPrice) echo "
WHOA!
";
if ($_GET['set']) {
if (!$_POST['count'] || !is_numeric($_POST['count']) || $_POST['count'] <= 0) {
$_POST['count'] = 1;
}
if (is_numeric($set) && $set > 0) {
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `inventory` WHERE `dressed`=0 AND `id` = '{$set}' and `owner`!='" . $user['id'] . "' AND `setsale` > 0"));
$userfrom = mysql_fetch_array(mysql_query("SELECT `login`,`id` FROM `users` WHERE `id` = '" . $dress['owner'] . "' LIMIT 1;"));
$d = mysql_fetch_array(mysql_query("SELECT sum(`massa`) FROM `inventory` WHERE `owner` = '{$_SESSION['uid']}' AND `dressed` = 0 AND `setsale` = 0 ; "));
if ($userfrom['id'] && $dress['id']) {
if (($dress['massa'] + $d[0]) > (get_meshok())) {
echo "Недостаточно места в рюкзаке.";
} elseif ($user['money'] >= $dress['setsale']) {
if (mysql_query("UPDATE `inventory` SET `owner` = '{$user['id']}', `setsale` = 0 WHERE `id` = '{$set}' AND `setsale` > '0' LIMIT 1;")) {
$good = 1;
} else {
$good = 0;
}
if ($good) {
//mysql_query("UPDATE `shop` SET `count`=`count`-{$_POST['count']} WHERE `id` = '{$set}' LIMIT 1;");
echo "Вы купили \"" . $dress['name'] . "\".";
$moneyto = round($dress['setsale'] * 0.90, 2);
$komiss = round($dress['setsale'] * 0.10, 2);
mysql_query("UPDATE `users` set `money` = `money`- '" . $dress['setsale'] . "' WHERE id = {$_SESSION['uid']}");
mysql_query("UPDATE `users` set `money` = `money`+ '" . $moneyto . "' WHERE id = {$userfrom['id']}");
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$_SESSION['uid']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] от \"" . $userfrom['login'] . "\" за " . $dress['setsale'] . " кр. в комиссионке ',5,'" . time() . "');");
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$userfrom['id']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] от \"" . $userfrom['login'] . "\" за " . $dress['setsale'] . " кр. в комиссионке ',5,'" . time() . "');");
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$_SESSION['uid']}','\"" . $user['login'] . "\" купил товар: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] за " . $dress['setsale'] . " кр. в комиссионке ',1,'" . time() . "');");
mysql_query("INSERT INTO `delo` (`id` , `author` ,`pers`, `text`, `type`, `date`) VALUES ('','0','{$userfrom['id']}','\"" . $userfrom['login'] . "\" получил " . $moneyto . " кр. за продажу товара: \"" . $dress['name'] . "\" id:(cap" . $dress['id'] . ") [" . $dress['duration'] . "/" . $dress['maxdur'] . "] через комиссионку ',1,'" . time() . "');");
$user['money'] = $user['money'] - $dress['setsale'];
$us = mysql_fetch_array(mysql_query("select `id` from `online` WHERE `date` >= " . (time() - 60) . " AND `id` = '{$userfrom['id']}' LIMIT 1;"));
if ($us[0]) {
addchp('Внимание! Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ', '{[]}' . $userfrom['login'] . '{[]}');
} else {
// если в офе
mysql_query("INSERT INTO `telegraph` (`receiver`,`date`,`text`) values ('" . $userfrom['id'] . "','','" . 'Внимание! Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ' . "');");
}
}
} else {
echo "Недостаточно денег или нет вещей в наличии.";
}
} else {
echo "Вещь не найдена в магазине";
}
} else {
echo "Не надо так делать";
}
}
if ($get === 'sale') {
$data = db::c()->query('SELECT `inventory`.*,
`magic`.`name` AS `magic_name`,
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` = 0 AND `dressed` = 0 AND `present` = "?s" AND `owner` = ?i ORDER BY `update` DESC ', '', $_SESSION['uid']);
$iteminfo = [];
while ($row = $data->fetch_assoc()) {
$iteminfo[] = new ShopItem($row);
}
}
if ($get === 'unsale') {
$data = db::c()->query('SELECT `inventory`.*,
`magic`.`name` AS `magic_name`,
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` > 0 AND `dressed` = 0 AND `owner` = ?i ORDER BY `update` DESC', $_SESSION['uid']);
$iteminfo = [];
while ($row = $data->fetch_assoc()) {
$iteminfo[] = new ShopItem($row);
}
}
$shopCategoryTypeNumber = empty($_GET['otdel']) ?: $_GET['otdel'];
switch ($shopCategoryTypeNumber) {
default:
$shopCategoryType = "Предметы в инвентаре";
$saleItems = true;
break;
case 1:
$shopCategoryType = "Кинжалы";
break;
case 11:
$shopCategoryType = "Топоры";
break;
case 12:
$shopCategoryType = "Дубины";
break;
case 13:
$shopCategoryType = "Мечи";
break;
case 2:
$shopCategoryType = "Сапоги";
break;
case 21:
$shopCategoryType = "Перчатки";
break;
case 22:
$shopCategoryType = "Легкая броня";
break;
case 23:
$shopCategoryType = "Тяжелая броня";
break;
case 24:
$shopCategoryType = "Шлемы";
break;
case 3:
$shopCategoryType = "Щиты";
break;
case 4:
$shopCategoryType = "Серьги";
break;
case 41:
$shopCategoryType = "Ожерелья";
break;
case 42:
$shopCategoryType = "Кольца";
break;
case 5:
$shopCategoryType = "Заклинания: нейтральные";
break;
case 51:
$shopCategoryType = "Заклинания: боевые и защитные";
break;
case 6:
$shopCategoryType = "Амуниция";
break;
}
?>
Отдел ""
query('SELECT * FROM `inventory` WHERE `dressed` = 0 AND `name` LIKE "?S" AND `setsale` > 0 ORDER BY `setsale` ASC', $_REQUEST['max'] . '%');
while ($row = $data->fetch_assoc()) {
$row['cost'] = $row['setsale'];
?>