BaseOrderFee.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\frontend\modules\order\fee;
  3. use app\frontend\models\order\PreOrderFee;
  4. use app\frontend\modules\order\models\PreOrder;
  5. abstract class BaseOrderFee
  6. {
  7. /**
  8. * @var PreOrder
  9. */
  10. protected $order;
  11. /**
  12. * 优惠名
  13. * @var string
  14. */
  15. protected $name;
  16. /**
  17. * 优惠码
  18. * @var
  19. */
  20. protected $code;
  21. /**
  22. * @var float
  23. */
  24. private $amount;
  25. public function __construct(PreOrder $order)
  26. {
  27. $this->order = $order;
  28. }
  29. /**
  30. * 获取总金额
  31. * @return float
  32. */
  33. public function getAmount()
  34. {
  35. if (isset($this->amount)) {
  36. return $this->amount;
  37. }
  38. $this->amount = $this->_getAmount();
  39. if($this->amount){
  40. // 将手续费金额保存在订单手续费表中
  41. $preOrderFee = new PreOrderFee([
  42. 'fee_code' => $this->code,
  43. 'amount' => $this->amount,
  44. 'name' => $this->getName(),
  45. ]);
  46. $preOrderFee->setOrder($this->order);
  47. }
  48. return $this->amount;
  49. }
  50. public function getCode(){
  51. return $this->code;
  52. }
  53. public function getName(){
  54. return $this->name;
  55. }
  56. abstract protected function _getAmount();
  57. public function enable(){
  58. return true;
  59. }
  60. }