uid = $uid; $this->walletMoney = $money; $this->initBank(); } private function initBank() { $this->bank = new Bank($this->uid); } public function get(): int { return $this->walletMoney; } public function set(int $money) { $this->walletMoney = max($money, 0); } public function getBank(): int { return $this->bank->getMoney(); } public function modifyBank(int $money, string $logType = '') { $this->bank->modify($money, $logType); } private function save() { Db::getInstance()->execute('update users set money = ? where id = ?', [$this->walletMoney, $this->uid]); } /** Тратим деньги */ public function spend(int $value): bool { if ($this->walletMoney > $value && $value > 0) { $this->walletMoney -= $value; $this->save(); return true; } return false; } /** Получаем деньги */ public function earn(int $value): bool { if ($value <= 0) { return false; } $this->walletMoney += $value; $this->save(); return true; } }