OrderRestDeductionPriceNode.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\models\order\PreOrderDeduction;
  10. use app\frontend\modules\order\models\PreOrder;
  11. use app\frontend\modules\order\PriceNode;
  12. class OrderRestDeductionPriceNode extends PriceNode
  13. {
  14. private $preOrderDeduction;
  15. private $order;
  16. public function __construct(PreOrder $order, PreOrderDeduction $preOrderDeduction, $weight)
  17. {
  18. $this->order = $order;
  19. $this->preOrderDeduction = $preOrderDeduction;
  20. parent::__construct($weight);
  21. }
  22. function getKey()
  23. {
  24. return $this->preOrderDeduction->getCode() . 'RestDeduction';
  25. }
  26. /**
  27. * @return mixed
  28. * @throws \app\common\exceptions\AppException
  29. */
  30. function getPrice()
  31. {
  32. if (!$this->preOrderDeduction->isChecked()) {
  33. return $this->order->getPriceBefore($this->getKey());
  34. } else {
  35. return $this->order->getPriceBefore($this->getKey()) - $this->preOrderDeduction->getUsablePoint()->getMoney();
  36. }
  37. }
  38. }