OrderMinDeductionPriceNode.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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\common\exceptions\AppException;
  10. use app\frontend\models\order\PreOrderDeduction;
  11. use app\frontend\modules\order\models\PreOrder;
  12. use app\frontend\modules\order\PriceNode;
  13. class OrderMinDeductionPriceNode extends PriceNode
  14. {
  15. private $preOrderDeduction;
  16. private $order;
  17. public function __construct(PreOrder $order, PreOrderDeduction $preOrderDeduction, $weight)
  18. {
  19. $this->order = $order;
  20. $this->preOrderDeduction = $preOrderDeduction;
  21. parent::__construct($weight);
  22. }
  23. function getKey()
  24. {
  25. return $this->preOrderDeduction->getCode() . 'MinDeduction';
  26. }
  27. /**
  28. * @return mixed
  29. * @throws \app\common\exceptions\AppException
  30. */
  31. function getPrice()
  32. {
  33. $price = $this->order->getPriceBefore($this->getKey()) - $this->preOrderDeduction->getMinDeduction()->getMoney();
  34. if ($price < 0) {
  35. throw new AppException("订单优惠后金额{$this->order->getPriceBefore($this->getKey())}元,不满足{$this->preOrderDeduction->getName()}最低抵扣{$this->preOrderDeduction->getMinDeduction()->getMoney()}元");
  36. }
  37. return $price;
  38. }
  39. }