OrderGoodsDiscountPriceNode.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2019/1/23
  6. * Time: 3:01 PM
  7. */
  8. namespace app\frontend\modules\orderGoods;
  9. use app\common\modules\orderGoods\models\PreOrderGoods;
  10. use app\frontend\modules\order\PriceNode;
  11. use app\frontend\modules\orderGoods\discount\BaseDiscount;
  12. use app\frontend\modules\orderGoods\price\option\BaseOrderGoodsPrice;
  13. class OrderGoodsDiscountPriceNode extends BaseOrderGoodsPriceNode
  14. {
  15. /**
  16. * @var BaseDiscount
  17. */
  18. private $discount;
  19. public function __construct(BaseOrderGoodsPrice $orderGoodsPrice, BaseDiscount $discount)
  20. {
  21. $this->discount = $discount;
  22. parent::__construct($orderGoodsPrice, $discount->getWeight());
  23. }
  24. function getKey()
  25. {
  26. return $this->discount->getCode();
  27. }
  28. /**
  29. * @return float|int|mixed
  30. * @throws \app\common\exceptions\AppException
  31. */
  32. function getPrice()
  33. {
  34. return $this->orderGoodsPrice->getPriceBefore($this->getKey()) - $this->discount->getAmount();
  35. }
  36. }