OrderFreightDeductionPriceNode.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2022/4/26
  8. * Time: 10:44
  9. */
  10. namespace app\frontend\modules\order\discount;
  11. use app\common\exceptions\AppException;
  12. use app\frontend\models\order\PreOrderDeduction;
  13. use app\frontend\modules\order\models\PreOrder;
  14. use app\frontend\modules\order\PriceNode;
  15. class OrderFreightDeductionPriceNode extends PriceNode
  16. {
  17. private $preOrderDeduction;
  18. private $order;
  19. public function __construct(PreOrder $order, PreOrderDeduction $preOrderDeduction, $weight)
  20. {
  21. $this->order = $order;
  22. $this->preOrderDeduction = $preOrderDeduction;
  23. parent::__construct($weight);
  24. }
  25. function getKey()
  26. {
  27. return $this->preOrderDeduction->getCode() . 'FreightDeduction';
  28. }
  29. /**
  30. * @return mixed
  31. * @throws \app\common\exceptions\AppException
  32. */
  33. function getPrice()
  34. {
  35. if ($this->preOrderDeduction->isChecked() && $this->preOrderDeduction->openFreightDeduction()) {
  36. return max($this->order->getPriceBefore($this->getKey()) - $this->preOrderDeduction->getUsableFreightDeduction()->getMoney(),0);
  37. } else {
  38. return $this->order->getPriceBefore($this->getKey());
  39. }
  40. }
  41. }