period_card.php 723 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. declare(strict_types=0);
  3. namespace mcard;
  4. class period_card extends card
  5. {
  6. public function usable(): bool
  7. {
  8. $state = $this->state();
  9. if ($state === STATE_OVER) {
  10. return false;
  11. }
  12. elseif ($state === STATE_USING)
  13. {
  14. if ($this->end_time() < time()) {
  15. return false;
  16. } else {
  17. return true;
  18. }
  19. }
  20. else {
  21. return true;
  22. }
  23. }
  24. public function deduct(int $cent)
  25. {
  26. return [$cent, false];
  27. }
  28. public function calc(int $cent)
  29. {
  30. $price = round($cent * (1 - $this->discount()) / 100, 2);
  31. return [$cent, false,$price];
  32. }
  33. }