otdel = intval($_GET['otdel']);
$this->itemId = intval($_GET['itmid']);
$this->shopId = $shopId;
$this->wares = Db::getRows('select * from
items_shop
left join items_main on items_shop.item_id = items_main.id
left join items_main_data on items_main_data.items_id = items_main.id
where sid = ? and r = ? and kolvo > 0 order by pos', [$this->shopId, $this->otdel]);
$this->buyer = new class {
private User $user;
public function __construct()
{
$this->user = User::start();
}
public function getId()
{
return $this->user->info['id'];
}
public function getCredits()
{
return $this->user->info['money1'];
}
public function getEuroCredits()
{
return $this->user->info['money2'];
}
public function getMoney3()
{
return $this->user->info['money3'];
}
public function getVoinstvennost()
{
return $this->user->rep['rep3'] - $this->user->rep['rep3_buy'];
}
public function getAlign()
{
return $this->user->info['align'];
}
public function getNextAct()
{
return $this->user->info['nextAct']; // что ты такое?!
}
public function isAdmin(): bool
{
return $this->user->info['admin'] > 0;
}
};
}
private function changeItemPositionByInt(int $modificator)
{
Db::sql('update items_shop set pos = pos + ? where sid = ? and r = ? and item_id = ? and kolvo > 0',
[$modificator, $this->shopId, $this->otdel, $this->itemId]);
}
private function itemUp()
{
$this->changeItemPositionByInt(-1);
}
private function itemDown()
{
$this->changeItemPositionByInt(1);
}
private function calculateMinimalPrice($basePrice, $shopPrice, $needItems)
{
if ($shopPrice < 0.01 && !$needItems) {
$shopPrice = $basePrice;
}
if ($shopPrice < 0) {
$shopPrice = 0;
}
return $shopPrice;
}
/**
* Если в первом параметре передаётся false, строка во втором параметре красится в красный цвет.
* @param bool $check
* @param $value
* @return string
*/
private function printColoredValue(bool $check, $value): string
{
$color = $check ? 'inherit' : 'red';
return sprintf('%s', $color, $value);
}
private function align($needAlign, $needAlignBs): string
{
if ($needAlignBs == '1') {
$align = '1.75';
} elseif ($needAlignBs == '3') {
$align = '3.01';
} elseif (!empty($needAlign) && empty($needAlignBs)) {
$align = $needAlign;
}
return !empty($align) ?
'' : '';
}
private function destiny($d): string
{
if (empty($d)) {
return '';
}
if ($d == 0) {
$str = 'первым, кто наденет его';
} elseif ($d == 1) {
$str = 'первым, кто возьмёт его';
} else {
$str = $d;
}
return '';
}
private function needItems(string $items): string
{
if (!$items || Config::get('noitembuy')) {
return '';
}
$result = '';
$trn = true;
$itemsArray = explode(',', $items);
foreach ($itemsArray as $keyvalue) {
list($key, $value) = explode('=', $keyvalue);
if (!empty($key) && !empty($value)) {
$neededItemName = Db::getValue('select name from items_main where id = ?', [$key]);
if ($neededItemName) {
$neededItemsInInventoryCount = Db::getValue(
'select count(*) from items_users where item_id = ? and inShop = 0 and inOdet = 0 and `delete` in (0,1000) and uid = ?',
[$key, $this->buyer->getId()]);
if ($neededItemsInInventoryCount < (int)$value) {
$trn = false;
}
$result .= '[' . $neededItemName . '] x' . $value . ', ';
}
}
}
return $this->printColoredValue($trn, '
Требует предмет: ' . rtrim($result, ', ') . ' ') . '
';
}
public function printWares(string $plu = '')
{
if ($this->buyer->isAdmin()) {
if (isset($_GET['itmup'])) {
$this->itemUp();
} elseif (isset($_GET['itmdown'])) {
$this->itemDown();
}
}
$cr = 'c8c8c8';
foreach ($this->wares as $pl) {
$cr = $cr == 'd4d4d4' ? 'c8c8c8' : 'd4d4d4';
$pl['price_1'] = $this->calculateMinimalPrice($pl['price1'], $pl['price_1'], $pl['tr_items']);
$pl['price_2'] = $this->calculateMinimalPrice($pl['price2'], $pl['price_2'], $pl['tr_items']);
if (empty($pl['data'])) {
$pl['data'] = '';
}
$itemData = ConversionHelper::dataStringToArray($pl['data']);
if ($this->shopId == self::SHOP_2) {
$itemData['icos'] = 'WL';
}
if (($pl['type'] >= 18 && $pl['type'] <= 24) || $pl['type'] == 26 || $pl['type'] == 27) {
//Зоны блока +
$itemData['zonb']++;
}
$is2 = '';
if ($pl['type'] == 71) {
$is1 = '
';
} else {
$is1 = '
';
}
if ($this->shopId == self::SHOP_2) {
$is1 .= '
купить';
} else {
if ($this->shopId == self::BEREZKA || $this->shopId == self::ARTEFACTS) {
$is1 .= 'купить ';
} else {
$is1 .= 'купить ';
}
}
//название
$pl['name'] = $this->align($itemData['tr_align'], $itemData['tr_align_bs']);
if (!empty($itemData['renameadd'])) {
$pl['name'] .= ' (Предмет: ' . $itemData['renameadd'] . ')';
}
if (!empty($itemData['icos'])) {
$pl['name'] = '' . $pl['name'] . ' ' . $itemData['icos'] . ' ';
}
$is2 .= '' . $pl['name'] . ' ';
if ($pl['massa'] > 0) {
$is2 .= '(Масса: ' . round($pl['massa'], 2) . ')';
}
if (isset($itemData['art'])) {
$is2 .= ' ';
}
$is2 .= $this->destiny($itemData['sudba']);
//цена
if ($this->buyer->isAdmin()) {
$is2 .= '