OrderDiscountPriceNode.php 831 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2019/1/23
  6. * Time: 10:40 AM
  7. */
  8. namespace app\frontend\modules\order\discount;
  9. use app\frontend\modules\order\models\PreOrder;
  10. use app\frontend\modules\order\PriceNode;
  11. class OrderDiscountPriceNode extends PriceNode
  12. {
  13. private $discount;
  14. private $order;
  15. public function __construct(PreOrder $order, BaseDiscount $discount, $weight)
  16. {
  17. $this->order = $order;
  18. $this->discount = $discount;
  19. parent::__construct($weight);
  20. }
  21. function getKey()
  22. {
  23. return $this->discount->getCode();
  24. }
  25. /**
  26. * @return mixed
  27. * @throws \app\common\exceptions\AppException
  28. */
  29. function getPrice()
  30. {
  31. return max($this->order->getPriceBefore($this->getKey()) - $this->discount->getAmount(),0);
  32. }
  33. }