12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- declare(strict_types=1);
- namespace mcard;
- class amount_card extends card
- {
- public function usable(): bool
- {
- $state = $this->state();
- if ($state === STATE_OVER) {
- return false;
- }
- elseif ($state === STATE_USING)
- {
- $left = intval($this->left_amount() * 100);
- if ($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];
- }
- }
|