room['file'] != 'shop_') {
return;
}
$shopId = null;
$status = '';
$itmAllSee = '';
$actionSale = false;
$actionGifts = false;
$buyItemId = 0;
$buyEkrItemId = 0;
$buyVoinItemId = 0;
$sellItemId = 0;
$uc = null;
$giftsvars = [];
$otdel = 1;
if ((int)$u->info['room'] === 10) {
$shopId = Shop::MAIN;
}
if ((int)$u->info['room'] === 368) {
$shopId = Shop::SHOP_2;
}
if ((int)$u->info['room'] === 13) {
$shopId = Shop::BEREZKA;
}
if ($_SERVER["REQUEST_METHOD"] === "GET") { //неясно почему, $_GET вызывается буквалльно всегда, даже на пустом месте.
$actionSale = (bool)$_GET['sale'];
$actionGifts = (bool)$_GET['gifts'];
$buyItemId = intval($_GET['buy']);
$buyEkrItemId = intval($_GET['buyEkr']);
$buyVoinItemId = intval($_GET['buyVn']);
$sellItemId = intval($_GET['item']);
$otdel = $_GET['otdel'] ??= 1;
}
if (isset($_POST['itemgift'])) {
$present = new \DTO\Present();
$present->sender = $u->info['login'];
$present->receiver = $_POST['to_login'];
$present->textTitle = $_POST['podarok2'];
$present->text = $_POST['txt'];
if (intval($_POST['from']) === 1) {
$present->anonymousSender = true;
} elseif (intval($_POST['from'] === 2) && $u->info['clan'] > 0) {
$present->clanSender = true;
}
$sendPresent = new Present($present);
$status = $sendPresent->getStatus();
}
$shop = new Shop($shopId, $otdel);
$shopName = Db::getValue('select name from room where id = ?', [$u->info['room']]);
if ($buyItemId) {
$status = $shop->buy($buyItemId);
} elseif ($buyEkrItemId) {
$status = $shop->buyEkr($buyEkrItemId);
} elseif ($buyVoinItemId) {
$status = $shop->buyVn($buyVoinItemId);
}
if ($actionSale) {
$itmAll = $u->genInv(2, '`iu`.`uid`="' . $u->info['id'] . '" AND `iu`.`delete`=0 AND `iu`.`inOdet`=0 AND `iu`.`inShop`=0 AND `iu`.`data` NOT LIKE "%fromshop=2%" ORDER BY `lastUPD` DESC');
if ($itmAll[0] == 0) {
$itmAllSee = '
ПУСТО |
';
} else {
$itmAllSee = $itmAll[2];
}
if ($sellItemId) {
$item = ItemsModel::getOwnedItemById($sellItemId, User::start()->info['id']);
$itemData = Conversion::dataStringToArray($item['data']);
$status = $item['gift'] ? 'Подарки не продаются!' : '';
$status = $itemData['nosale'] ? 'Предмет не для продажи!' : '';
if (!$status && $sellItemId) {
$sellprice = $item['1price'] - $item['1price'] * 0.1;
ItemsModel::delete($item['id']);
$u->addKr($sellprice);
$status = "Вы успешно продали предмет «{$item['name']}» за $sellprice кр.";
Delo::add(2, 'shopid:' . $shopId, $u->info['id'], "Предмет «{$item['name']}» [id:{$item['id']}] продан за $sellprice кр.", -$sellprice);
}
}
}
if ($actionGifts) {
$uc = new Clan($u->info);
$imgsrc = Config::img();
$sp = Db::getRow('select * from users_gifts where uid = ?', [$u->info['id']]);
foreach ($sp as $pl) {
$giftsvars[] = [
'img' => $imgsrc . '/i/items/' . $pl['img'],
'jsvalue' => 1000000000000 + $pl['id'],
'money' => $pl['money'],
'linkname' => $pl['name'],
];
}
$itmAll = $u->genInv(3, '`iu`.`uid`="' . $u->info['id'] . '" AND `iu`.`delete`=0 AND `iu`.`inOdet`=0 AND `iu`.`inShop`=0 AND `im`.`type` in (28,38,63,64,37) AND (`iu`.`gift` = "" OR `iu`.`gift` = 1) ORDER BY `lastUPD` DESC');
if ($itmAll[0] == 0) {
$itmAllSee = 'У вас нет подходящих предметов |
';
} else {
$itmAllSee = $itmAll[2];
}
}
/** @var string $goLis инициализируется в файле из которого вызван этот. Отрисовка датчика задержки смены локации. */
/** @var string $code инициализируется в файле из которого вызван этот. Хеш-строка против кеширования. */
$renderArgs = [
'shopName' => $shopName,
'status' => $status,
'actionSale' => $actionSale,
'actionGifts' => $actionGifts,
'otdel' => $otdel,
'u' => $u,
'uc' => $uc,
'giftsvars' => $giftsvars,
'itmAllSee' => $itmAllSee,
'shop' => $shop,
'goLis' => $goLis,
'code' => $code,
'shopId' => $shopId,
'otdels' => $shop->getUsedOtdels(),
'i' => 1,
];
View::render('Locations/Shop.php', $renderArgs);