battles/comission.php

341 lines
19 KiB
PHP
Raw Normal View History

2018-01-28 16:40:49 +00:00
<?php
2019-01-18 19:56:07 +00:00
session_start();
if ($_SESSION['uid'] == null) header("Location: index.php");
require_once 'functions.php';
2018-01-28 16:40:49 +00:00
2019-01-18 19:56:07 +00:00
if ($user['level'] < 1) {
header("Location: main.php");
die();
2018-01-28 16:40:49 +00:00
}
2019-01-18 19:56:07 +00:00
if ($user['room'] != 25) {
header("Location: main.php");
die();
}
if ($user['battle'] != 0) {
header('location: fbattle.php');
die();
2018-01-28 16:40:49 +00:00
}
2019-01-18 19:56:07 +00:00
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
2018-01-28 16:40:49 +00:00
2019-02-15 14:11:58 +00:00
if (isset($_GET['kredit'])) $itemCost = checkIntInRange($_GET['kredit']);
if (isset($_GET['n'])) $itemId = checkIntInRange($_GET['n']);
if (isset($_GET['back'])) $returningItemId = checkIntInRange($_GET['back']);
2019-02-13 13:28:06 +00:00
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);
2019-02-13 13:28:06 +00:00
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'] . " кр. чтобы оплатить комиссию!";
}
2019-02-13 13:28:06 +00:00
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 = "Предмет не найден на полках магазина!";
2018-01-28 16:40:49 +00:00
}
2019-02-15 14:30:03 +00:00
if (isset($_POST['puttomarket'])) echo "<h1>WHOA!</h1>";
2018-01-28 16:40:49 +00:00
2019-02-15 14:11:58 +00:00
if ($_GET['set']) {
2019-01-18 19:56:07 +00:00
if (!$_POST['count'] || !is_numeric($_POST['count']) || $_POST['count'] <= 0) {
$_POST['count'] = 1;
}
if (is_numeric($set) && $set > 0) {
2019-02-15 14:11:58 +00:00
$dress = mysql_fetch_array(mysql_query("SELECT * FROM `inventory` WHERE `dressed`=0 AND `id` = '{$set}' and `owner`!='" . $user['id'] . "' AND `setsale` > 0"));
2019-01-18 19:56:07 +00:00
$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 "<font color=red><b>Недостаточно места в рюкзаке.</b></font>";
} 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;
}
2018-01-28 16:40:49 +00:00
2019-01-18 19:56:07 +00:00
if ($good) {
//mysql_query("UPDATE `shop` SET `count`=`count`-{$_POST['count']} WHERE `id` = '{$set}' LIMIT 1;");
echo "<font color=red><b>Вы купили \"" . $dress['name'] . "\".</b></font>";
$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('<font color=red>Внимание!</font> Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ', '{[]}' . $userfrom['login'] . '{[]}');
} else {
// если в офе
mysql_query("INSERT INTO `telegraph` (`receiver`,`date`,`text`) values ('" . $userfrom['id'] . "','','" . '<font color=red>Внимание!</font> Успешно продан предмет "' . $dress['name'] . '" за ' . $dress['setsale'] . ' кр. Комиссия составила ' . $komiss . ' кр. Вам перечислено от комиссионного магазина ' . $moneyto . ' кр. ' . "');");
}
}
} else {
echo "<font color=red><b>Недостаточно денег или нет вещей в наличии.</b></font>";
}
} else {
echo "<font color=red><b>Вещь не найдена в магазине</b></font>";
}
} else {
echo "<font color=red><b>Не надо так делать</b></font>";
}
2018-01-28 16:40:49 +00:00
}
2019-02-15 14:11:58 +00:00
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);
}
}
2019-02-15 12:16:40 +00:00
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);
}
}
2019-01-18 19:56:07 +00:00
$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;
}
2018-01-28 16:40:49 +00:00
?>
2019-01-18 19:56:07 +00:00
<HTML>
<HEAD>
<link rel=stylesheet href="css/main.css">
<script src="js/main.js"></script>
<meta charset="utf-8">
<SCRIPT LANGUAGE="JavaScript">
function sale(name, txt, n, kr) {
var s = prompt("Сдать в магазин \"" + txt + "\". Укажите цену:", kr);
if ((s != null) && (s !== '')) {
2019-02-14 11:04:26 +00:00
location.href = "?sale=" + name + "&kredit=" + s + "&n=" + n;
2019-01-18 19:56:07 +00:00
}
}
</SCRIPT>
</HEAD>
<body>
<div style="float: right;">
<button onclick="hrefToFrame('?sale')">Сдать вещи в магазин</button>
<button onclick="hrefToFrame('?unsale')">Забрать вещи из магазина</button>
<button onclick="hrefToFrame('city.php?cp=1')">Вернуться</button>
</div>
<TABLE width=100% cellspacing="0" cellpadding="4">
<TR>
<TD valign=top align=left>
<!--Комиссионный Магазин-->
<TABLE width=100% cellspacing="0" cellpadding="0" bgcolor="#A5A5A5">
<TR>
<TD align=center>
<B>Отдел "<?php
2019-02-14 11:04:26 +00:00
if ($get === 'sale') echo "Сдать вещи";
elseif ($get === 'unsale') echo "Забрать вещи";
else echo $shopCategoryType; ?>"</B>
2019-01-18 19:56:07 +00:00
</TD>
</TR>
<TR>
<TD><!--Рюкзак-->
<TABLE BORDER=0 WIDTH=100% CELLSPACING="1" CELLPADDING="2" BGCOLOR="#A5A5A5">
<?php
if ($_REQUEST['max']) {
$data = db::c()->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()) {
2019-01-18 19:56:07 +00:00
$row['cost'] = $row['setsale'];
?>
<TR>
<TD align=center style="width:150px"><IMG SRC="i/sh/<?= $row['img'] ?>">
<BR> <A HREF="?otdel=<?= $_GET['otdel'] ?>&set=<?= $row['id'] ?>&sid=">купить</A>
</TD>
<TD valign=top>
<?php showitem($row); ?>
</TD>
</TR>
<?php
2019-01-18 19:56:07 +00:00
}
2019-02-14 10:59:00 +00:00
} elseif ($get === 'sale') {
echo "<TR bgcolor=#C7C7C7><th colspan=2>Комиссия за услуги магазина составляет 10% от цены, по которой вы предлагаете предмет.</th></TR>";
2019-02-15 14:11:58 +00:00
foreach ($iteminfo as $ii) {
echo "<tr><td style='width: 150px; text-align: center;'>";
$ii->printImage(); ?>
2019-02-15 14:30:03 +00:00
<form method="post">
<input placeholder="Цена" name="cost">
<br><input type="submit" name="puttomarket" value="ать в магазин">
</form>
<!-- <button onclick="sale(1, '--><?//= $iteminfo['name'] ?>//', '<?//= $iteminfo['id'] ?>//', '<?//= $iteminfo['cost'] ?>//')">ать в магазин</button>
2019-01-18 19:56:07 +00:00
<?php
2019-02-15 14:11:58 +00:00
echo "</td>";
echo "<td style='vertical-align: top;'>";
$ii->printInfo();
echo "</td></tr>";
2019-01-18 19:56:07 +00:00
}
2019-02-15 14:11:58 +00:00
2019-02-14 11:00:51 +00:00
} elseif ($get === 'unsale') {
2019-02-15 12:16:40 +00:00
foreach ($iteminfo as $ii) {
echo "<tr><td style='width: 150px; text-align: center;'>";
$ii->printImage();
2019-02-15 14:11:58 +00:00
$ii->printControls('marketgetback');
2019-02-15 12:16:40 +00:00
echo "</td>";
echo "<td style='vertical-align: top;'>";
$ii->printInfo();
echo "</td></tr>";
2019-01-18 19:56:07 +00:00
}
2019-02-15 12:16:40 +00:00
2019-01-18 19:56:07 +00:00
} else {
2019-02-13 14:10:18 +00:00
$data = db::c()->query('SELECT DISTINCT `img`, `name`, `nalign`, `massa` FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `present` = "?s" AND `otdel` = "?s" GROUP BY `img` ORDER BY `cost` ASC', '', $_GET['otdel']);
$replacements = ['+1','+2','+3','+4','+5',' (мф)'];
while ($row = $data->fetch_assoc()) {
$item_name = str_replace($replacements, '', $row['name']);
$item = db::c()->query('SELECT COUNT(`id`), MIN(`duration`), MIN(`maxdur`), MAX(`duration`), MAX(`maxdur`), MIN(`setsale`), MAX(`setsale`) FROM `inventory` WHERE `dressed` = 0 AND `setsale` > 0 AND `present` = "?s" AND `name` LIKE "?S"', '', $item_name.'%')->fetch_assoc();
2019-01-18 19:56:07 +00:00
?>
2019-02-13 14:10:18 +00:00
<TR>
<TD align=center>
<IMG SRC="i/sh/<?= $row['img'] ?>" ALT="">
2019-02-15 12:16:40 +00:00
<BR><A HREF="?max=<?= $item_name ?>">подробнее</A>
2019-02-13 14:10:18 +00:00
</TD>
<TD valign=top>
<?= $item_name ?> <img src="i/align_<?= $row['nalign'] ?>.gif">
2019-01-18 19:56:07 +00:00
(Масса: <?= $row['massa'] ?>) <BR>
<b>Цена: <?= round($item[5], 2) ?> - <?= round($item[6], 2) ?> кр.</b>
<small>(количество: <?= $item[0] ?>)</small>
2019-02-14 11:04:26 +00:00
<BR>Долговечность: <?= $item[1] ?>-<?= $item[2] ?>/<?= $item[3] ?> -<?= $item[4] ?><BR>
2019-01-18 19:56:07 +00:00
</TD>
</TR>
<?
}
}
?>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
<TD valign=top width=280>
<div style="MARGIN-LEFT:15px; MARGIN-TOP: 10px;">
<B>Масса всех ваших вещей: <?= getItemsMassaInfo() ?>
<BR>У вас в наличии: <span style="color: darkgreen;"><?= $user['money'] ?></span> кр.</B>
<hr>
<div style="text-align: center; font-weight: bold;">Отделы магазина</div>
<dl>
<dt><b>Оружие:</b></dt>
<dd><a href="?otdel=1&rnd=<?= mt_rand() ?>">кинжалы</a></dd>
<dd><a href="?otdel=11&rnd=<?= mt_rand() ?>">топоры</a></dd>
<dd><a href="?otdel=12&rnd=<?= mt_rand() ?>">дубины</a></dd>
<dd><a href="?otdel=13&rnd=<?= mt_rand() ?>">мечи</a></dd>
<dt><b>Одежда:</b></dt>
<dd><a href="?otdel=24&rnd=<?= mt_rand() ?>">шлемы</a></dd>
<dd><a href="?otdel=23&rnd=<?= mt_rand() ?>">тяжелая броня</a></dd>
<dd><a href="?otdel=22&rnd=<?= mt_rand() ?>">легкая броня</a></dd>
<dd><a href="?otdel=3&rnd=<?= mt_rand() ?>">щиты</a></dd>
<dd><a href="?otdel=21&rnd=<?= mt_rand() ?>">перчатки</a></dd>
<dd><a href="?otdel=2&rnd=<?= mt_rand() ?>">сапоги</a></dd>
<dt><b>Ювелирные товары:</b></dt>
<dd><a href="?otdel=4&rnd=<?= mt_rand() ?>">серьги</a></dd>
<dd><a href="?otdel=41&rnd=<?= mt_rand() ?>">ожерелья</a></dd>
<dd><a href="?otdel=42&rnd=<?= mt_rand() ?>">кольца</a></dd>
<dt><b>Магия:</b></dt>
<dd><a href="?otdel=51&rnd=<?= mt_rand() ?>">боевые</a></dd>
<dd><a href="?otdel=5&rnd=<?= mt_rand() ?>">разные</a></dd>
<dt><b>Разное:</b></dt>
<dd><a href="?otdel=6&rnd=<?= mt_rand() ?>">амуниция</a></dd>
</dl>
</div>
<div id="hint3" class="ahint"></div>
</TD>
</TR>
2018-01-28 16:40:49 +00:00
</TABLE>
</BODY>
</HTML>