dev-shop #51
@ -57,7 +57,7 @@ class Nick extends User
|
||||
*/
|
||||
public function full($showInvisibility = 0):string
|
||||
{
|
||||
if ($showInvisibility && $this->getInvisibilityStatus()) {
|
||||
if (!$showInvisibility && $this->getInvisibilityStatus()) {
|
||||
return INVIS;
|
||||
}
|
||||
return $this->getAlignToNickname().$this->getClanToNickname().sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a>', $this->login, $this->level, $this->login);
|
||||
|
@ -7,6 +7,7 @@ use Battles\Database\DBPDO;
|
||||
class Shop
|
||||
{
|
||||
public const GENERAL_SHOP = 1;
|
||||
public const BARTER_SHOP = 2;
|
||||
public const CATEGORY_SALE_ITEMS = -1;
|
||||
public static Shop $current;
|
||||
public int $categoryType = 0;
|
||||
@ -20,14 +21,19 @@ class Shop
|
||||
{
|
||||
if ($this->categoryType) {
|
||||
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
|
||||
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null and item_type = ?', $this->categoryType);
|
||||
} else {
|
||||
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
|
||||
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null');
|
||||
}
|
||||
|
||||
$iteminfo = [];
|
||||
foreach ($stmt as $item) {
|
||||
$iteminfo[] = new ShopItem($item, 'buyshop');
|
||||
}
|
||||
foreach ($stmt2 as $item) {
|
||||
$iteminfo[] = new ShopItem($item, 'buymarket');
|
||||
}
|
||||
return $this->strFromArr($iteminfo);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Battles;
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
use Battles\Models\PresentsModel;
|
||||
use Exceptions\GameException;
|
||||
|
||||
class ShopItem extends Item
|
||||
@ -13,7 +14,7 @@ class ShopItem extends Item
|
||||
private const BUTTON = [
|
||||
'setmarket' => 'Сдать в магазин',
|
||||
'unsetmarket' => 'Снять с продажи',
|
||||
'buymarket' => 'Совершить обмен',
|
||||
'buymarket' => 'Купить с рук',
|
||||
'sellshop' => 'Продать',
|
||||
'buyshop' => 'Купить',
|
||||
];
|
||||
@ -53,6 +54,7 @@ SQL;
|
||||
public static string $status = '';
|
||||
private ?string $jsonBarterList;
|
||||
private int $offerId;
|
||||
private int $ownerId = 0;
|
||||
|
||||
public function __construct($row, $operationType = null)
|
||||
{
|
||||
@ -63,9 +65,12 @@ SQL;
|
||||
$this->price = $row->price ?? null;
|
||||
$this->shop_item_quantity = $row->shop_item_quantity ?? null;
|
||||
$this->item_id = $row->item_id ?? $row->id;
|
||||
if ($operationType === 'buyshop') {
|
||||
$this->offerId = $row->offer_id; // Ид позиции в магазине.
|
||||
$this->jsonBarterList = $row->barter_items_list_json;
|
||||
if ($operationType === 'buyshop' || $operationType === 'buymarket') {
|
||||
$this->offerId = $row->offer_id ?? 0; // Ид позиции в магазине.
|
||||
$this->jsonBarterList = $row->barter_items_list_json ?? null;
|
||||
}
|
||||
if ($operationType === 'buymarket') {
|
||||
$this->ownerId = $row->owner_id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,6 +84,10 @@ SQL;
|
||||
if ($this->optype === 'sellshop') {
|
||||
$str .= $this->getTextBasedOnPrice();
|
||||
}
|
||||
if ($this->optype === 'buymarket') {
|
||||
$str .= $this->getBarterList();
|
||||
$str .= '<br><br>Продавец: ' . Nick::id($this->ownerId)->full(1);
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
@ -247,6 +256,9 @@ SQL;
|
||||
return '';
|
||||
}
|
||||
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
|
||||
if ($this->optype === 'buymarket' && $this->ownerId === User::$current->getId()) {
|
||||
$this->optype = 'unsetmarket';
|
||||
}
|
||||
$hiddenValue = $this->optype === 'buyshop' ? $this->offerId : $this->item_id;
|
||||
$button_name = self::BUTTON[$this->optype];
|
||||
return <<<FORM
|
||||
|
4
shop.php
4
shop.php
@ -25,6 +25,10 @@ if (!empty($_POST['buyshop'])) {
|
||||
ShopItem::buyItem($_POST['itemId'], User::$current);
|
||||
}
|
||||
|
||||
if (!empty($_POST['buymarket'])) {
|
||||
ShopItem::$status = 'попытка купить с рук предмет id: ' . $_POST['itemId'];
|
||||
}
|
||||
|
||||
Template::header('Магазин');
|
||||
?>
|
||||
<link href='/css/shop.css' rel='stylesheet'>
|
||||
|
Loading…
Reference in New Issue
Block a user