state(); if ($state === STATE_OVER) { return false; } elseif ($state === STATE_USING) { $left = intval($this->left_amount() * 100); if ($this->end_time() < time() || $left === 0) { return false; } else { return true; } } else { return true; } } public function deduct(int $cent) { $left_cent = intval($this->left_amount() * 100 + 0.5); if ($left_cent > $cent) { $amount = $cent; $useup = false; } else { $amount = $left_cent; $useup = true; } return [$amount, $useup]; } public function calc(int $cent) { $left_cent = intval($this->left_amount() * 100 + 0.5); if ($left_cent > $cent) { $amount = $cent; $useup = false; } else { $amount = $left_cent; $useup = true; } $price = round($amount * (1 - $this->discount()) / 100, 2); return [$amount, $useup,$price]; } }