topcard.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace mtopcard;
  3. class topcard
  4. {
  5. private $mCardItem;
  6. public function __construct($item)
  7. {
  8. $this->mCardItem = $item;
  9. }
  10. public function topcard_id(): int
  11. {
  12. return intval($this->mCardItem['topcard_id']);
  13. }
  14. public function member_id(): int
  15. {
  16. return intval($this->mCardItem['member_id']);
  17. }
  18. public function card_no(): string
  19. {
  20. return $this->mCardItem['card_no'];
  21. }
  22. public function card_type(): int
  23. {
  24. return intval($this->mCardItem['card_type']);
  25. }
  26. public function add_time(): int
  27. {
  28. return intval($this->mCardItem['add_time']);
  29. }
  30. public function total_amount(): float
  31. {
  32. return round(floatval($this->mCardItem['total_amount']), 2);
  33. }
  34. public function month_total()
  35. {
  36. $stamp = month_stamp();
  37. if ($this->month_stamp() != $stamp) {
  38. return 0.00;
  39. } else {
  40. return round(doubleval($this->mCardItem['month_amount']), 2);
  41. }
  42. }
  43. public function month_stamp(): int
  44. {
  45. return intval($this->mCardItem['month_stamp']);
  46. }
  47. public function can_edit() {
  48. $amount = $this->total_amount();
  49. return intval($amount) == 0 ? 1 : 0;
  50. }
  51. public function format()
  52. {
  53. $ret = [];
  54. $ret['topcard_id'] = $this->topcard_id();
  55. $ret['card_no'] = $this->card_no();
  56. $ret['card_type'] = $this->card_type();
  57. $ret['car_desc'] = $this->car_desc();
  58. $ret['total_amount'] = $this->total_amount();
  59. $ret['month_total'] = $this->month_total();
  60. $ret['add_time'] = $this->add_time();
  61. $ret['can_edit'] = $this->can_edit();
  62. return $ret;
  63. }
  64. private function car_desc() {
  65. switch ($this->card_type()) {
  66. case PetroChinaCard: return '中石油' ;
  67. case SinopecCard: return '中石化' ;
  68. case PhoneCard: return '电话卡' ;
  69. }
  70. return '未知卡类型';
  71. }
  72. }