BaseOrderTaxFee.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\frontend\modules\order\taxFee;
  3. use app\frontend\modules\order\models\PreOrder;
  4. abstract class BaseOrderTaxFee
  5. {
  6. /**
  7. * @var PreOrder
  8. */
  9. protected $order;
  10. /**
  11. * 税费名称
  12. * @var string
  13. */
  14. protected $name;
  15. /**
  16. * 展示选项名
  17. * @var string
  18. */
  19. protected $show_name;
  20. /**
  21. * 税费标识
  22. * @var
  23. */
  24. protected $code;
  25. /**
  26. * 税费金额(优惠的话就负数,要额外加钱就正数)
  27. * @var float
  28. */
  29. private $amount;
  30. public function __construct(PreOrder $order)
  31. {
  32. $this->order = $order;
  33. }
  34. /**
  35. * 是否开启
  36. * @return bool
  37. */
  38. public function enable()
  39. {
  40. return true;
  41. }
  42. public function getCode()
  43. {
  44. return $this->code;
  45. }
  46. public function getName()
  47. {
  48. return $this->name;
  49. }
  50. public function getShowName()
  51. {
  52. return $this->show_name;
  53. }
  54. public function getRate()
  55. {
  56. return null;
  57. }
  58. /**
  59. * 是否显示
  60. * @return bool
  61. */
  62. public function isShow()
  63. {
  64. return true;
  65. }
  66. /**
  67. * 获取总金额
  68. * @return float
  69. */
  70. public function getAmount()
  71. {
  72. if (!isset($this->amount)) {
  73. $this->amount = $this->_getAmount();
  74. }
  75. return $this->amount;
  76. }
  77. /**
  78. * 是否选中使用
  79. * @return bool
  80. */
  81. public function isChecked()
  82. {
  83. $checkedFee = $this->order->getParams('tax_fee')?:[];
  84. if (in_array($this->getCode(), $checkedFee)) {
  85. return true;
  86. }
  87. return false;
  88. }
  89. abstract protected function _getAmount();
  90. }