Всё ломалось, если цена = 1.

This commit is contained in:
lopar 2021-08-23 00:50:47 +03:00
parent 8f506dced2
commit 9adc63eae8
1 changed files with 4 additions and 3 deletions

View File

@ -156,7 +156,7 @@ class ShopItem extends Item
$item = $db->ofetch('select * from inventory where item_id = ?', $id); $item = $db->ofetch('select * from inventory where item_id = ?', $id);
$sellingItemName = $item->name; $sellingItemName = $item->name;
// Продажа за цену от нуля до половины стоимости. // Продажа за цену от нуля до половины стоимости.
$sellingPrice = mt_rand(0, $item->price / 2); $sellingPrice = $item->price > 1 ? mt_rand(0, $item->price / 2) : mt_rand(0, 1);
$db->execute('delete from inventory where item_id = ?', $id); $db->execute('delete from inventory where item_id = ?', $id);
if ($bankTrade) { if ($bankTrade) {
$bank = new Bank($seller->getId()); $bank = new Bank($seller->getId());
@ -180,11 +180,12 @@ class ShopItem extends Item
*/ */
private function getSellPriceMean(): ?int private function getSellPriceMean(): ?int
{ {
if ($this->price) { if ($this->price > 1) {
$arr = range(0, $this->price / 2); $arr = range(0, $this->price / 2);
return array_sum($arr) / count($arr); return array_sum($arr) / count($arr);
} else {
return $this->price == 1 ? 1 : null;
} }
return null;
} }
/** /**