BaseOrderServiceFee.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/8/20
  6. * Time: 11:14
  7. */
  8. namespace app\frontend\modules\order\serviceFee;
  9. use app\frontend\modules\order\models\PreOrder;
  10. abstract class BaseOrderServiceFee
  11. {
  12. /**
  13. * @var PreOrder
  14. */
  15. protected $order;
  16. /**
  17. * 服务费名称
  18. * @var string
  19. */
  20. protected $name;
  21. /**
  22. * 服务费标识
  23. * @var
  24. */
  25. protected $code;
  26. /**
  27. * 服务费金额
  28. * @var float
  29. */
  30. private $amount;
  31. public function __construct(PreOrder $order)
  32. {
  33. $this->order = $order;
  34. }
  35. /**
  36. * 获取总金额
  37. * @return float
  38. */
  39. public function getAmount()
  40. {
  41. if (isset($this->amount)) {
  42. return $this->amount;
  43. }
  44. $this->amount = $this->_getAmount();
  45. return $this->amount;
  46. }
  47. public function getCode(){
  48. return $this->code;
  49. }
  50. public function getName(){
  51. return $this->name;
  52. }
  53. /**
  54. * 是否开启
  55. * @return bool
  56. */
  57. public function enable()
  58. {
  59. return true;
  60. }
  61. /**
  62. * 是否选中
  63. * @return bool
  64. */
  65. public function isChecked()
  66. {
  67. $checkedFee = $this->order->getParams('service_fee')?:[];
  68. if (in_array($this->getCode(), $checkedFee)) {
  69. return true;
  70. }
  71. return false;
  72. }
  73. /**
  74. * 是否显示
  75. */
  76. public function isShow()
  77. {
  78. if ($this->isChecked()) {
  79. return true;
  80. }
  81. return false;
  82. }
  83. abstract protected function _getAmount();
  84. }