Из shop уехали все запросы в класс. Теперь он только отображает.
This commit is contained in:
@@ -49,6 +49,7 @@ SQL;
|
||||
private $optype;
|
||||
private ?int $shop_item_quantity;
|
||||
private ?int $price;
|
||||
public static string $status = '';
|
||||
|
||||
public function __construct($row, $operationType = null)
|
||||
{
|
||||
@@ -61,11 +62,12 @@ SQL;
|
||||
$this->item_id = $row->item_id ?? $row->id;
|
||||
}
|
||||
|
||||
public function printInfo()
|
||||
public function printInfo(): string
|
||||
{
|
||||
$this->printAllInfo();
|
||||
//$this->printAllInfo();
|
||||
$str = $this->getAllInfo();
|
||||
if ($this->optype === 'buyshop' && $this->shop_item_quantity > 0 && $this->shop_item_quantity < 20) {
|
||||
echo "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
|
||||
$str .= "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
|
||||
}
|
||||
if ($this->optype === 'sellshop') {
|
||||
if ($this->getSellPriceMean() < 50) {
|
||||
@@ -79,36 +81,37 @@ SQL;
|
||||
} else {
|
||||
$goods = 'это превосходное изделие';
|
||||
}
|
||||
echo "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
|
||||
$str .= "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function printImage()
|
||||
public function printImage(): string
|
||||
{
|
||||
if (!$this->image) {
|
||||
$this->image = 'noitem.png';
|
||||
}
|
||||
echo "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
||||
return "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
|
||||
}
|
||||
|
||||
//todo наличка после покупки отображается с задержкой.
|
||||
public static function buyItem($id, User $buyer): string
|
||||
public static function buyItem($id, User $buyer)
|
||||
{
|
||||
$db = new DBPDO();
|
||||
$check = $db->ofetch("select * from trade_offers where shop_item_id = ?", $id);
|
||||
if (empty($check->shop_item_quantity) || empty($check->shop_item_id)) {
|
||||
return self::NO_ITEMS_IN_STOCK;
|
||||
self::$status = self::NO_ITEMS_IN_STOCK;
|
||||
}
|
||||
|
||||
// TODO БАРТЕР!
|
||||
if (isset($check->barter_item_list_json)) {
|
||||
echo "Работаем по бартеру!";
|
||||
self::$status = "Работаем по бартеру!";
|
||||
}
|
||||
|
||||
$db->execute(self::BUY_QUERY, [$buyer->getId(), $check->shop_item_id]);
|
||||
$item = $db->ofetch("select item_id, name, price from inventory where item_id = ?", $db->lastInsertId());
|
||||
if (empty($item->item_id) || empty($item->name)) {
|
||||
return 'Запрос в базу не прошёл.';
|
||||
self::$status = 'Запрос в базу не прошёл.';
|
||||
} else {
|
||||
$user = new User($_SESSION['uid']);
|
||||
// Если не хватает налички, снимаем с банка с комиссией.
|
||||
@@ -117,14 +120,12 @@ SQL;
|
||||
$bank = new Bank($buyer->getId());
|
||||
$bank->withdrawMoney($item->price);
|
||||
} catch (GameException $e) {
|
||||
echo 'Банковская ошибка!';
|
||||
return self::NO_MONEY;
|
||||
self::$status = 'Банковская ошибка! ' . self::NO_MONEY;
|
||||
}
|
||||
} else {
|
||||
$user->setMoney($user->getMoney() - $item->price);
|
||||
$user->saveMoney();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($check->shop_item_quantity != -1) {
|
||||
@@ -133,10 +134,10 @@ SQL;
|
||||
|
||||
$deloText = $buyer->getLogin() . " купил товар «" . $item->name . "» id:(" . $item->item_id . ") в магазине за " . $item->price . ".";
|
||||
GameLogs::addUserLog($buyer->getId(), $deloText);
|
||||
return "Предмет " . $item->name . " куплен за " . $item->price . ".";
|
||||
self::$status = "Предмет " . $item->name . " куплен за " . $item->price . ".";
|
||||
}
|
||||
|
||||
public static function sellItem($id, User $seller, $bankTrade = 0): string
|
||||
public static function sellItem($id, User $seller, $bankTrade = 0)
|
||||
{
|
||||
$db = new DBPDO();
|
||||
$item = $db->ofetch('select * from inventory where item_id = ?', $id);
|
||||
@@ -154,11 +155,10 @@ SQL;
|
||||
$deloText = "{$seller->getLogin()} продал товар «{$sellingItemName}» id:($id) в магазине за $sellingPrice кр.";
|
||||
GameLogs::addUserLog($seller->getId(), $deloText);
|
||||
if ($sellingPrice == 0) {
|
||||
$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
|
||||
self::$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
|
||||
} else {
|
||||
$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
|
||||
self::$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/** Подчсчёт средней суммы продажи.
|
||||
@@ -177,18 +177,19 @@ SQL;
|
||||
/**
|
||||
* Для кнопок управления под картинкой предмета в зависимости от ситуации.
|
||||
*/
|
||||
public function printControls()
|
||||
public function printControls(): string
|
||||
{
|
||||
if (in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
|
||||
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
|
||||
$button_name = self::BUTTON[$this->optype];
|
||||
echo <<<FORM
|
||||
if (!in_array($this->optype, ['setmarket', 'unsetmarket', 'buymarket', 'sellshop', 'buyshop',])) {
|
||||
return '';
|
||||
}
|
||||
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
|
||||
$button_name = self::BUTTON[$this->optype];
|
||||
return <<<FORM
|
||||
<form method="post">$str
|
||||
<input type="hidden" name="itemId" value="$this->item_id">
|
||||
<br><input type="submit" name="$this->optype" value="$button_name">
|
||||
</form>
|
||||
FORM;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user