OrderFreightDeductionPricePipe.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: blank
  5. * Date: 2022/4/13
  6. * Time: 10:36
  7. */
  8. namespace app\frontend\modules\dispatch\freight\pipes;
  9. use app\frontend\modules\dispatch\deduction\BaseFreightDeduction;
  10. use app\frontend\modules\dispatch\models\OrderFreight;
  11. class OrderFreightDeductionPricePipe extends PricePipe
  12. {
  13. private $deduction;
  14. public function __construct(OrderFreight $orderFreight,BaseFreightDeduction $deduction, $weight = 5000)
  15. {
  16. $this->deduction = $deduction;
  17. parent::__construct($orderFreight, $weight);
  18. }
  19. public function getKey()
  20. {
  21. return $this->deduction->getCode().'Deduction';
  22. }
  23. public function getAmount()
  24. {
  25. return $this->deduction->getAmount();
  26. }
  27. /**
  28. * @return mixed
  29. * @throws \app\common\exceptions\AppException
  30. */
  31. function getPrice()
  32. {
  33. if ($this->deduction->isChecked()) {
  34. return max($this->orderFreight->getPriceBefore($this->getKey()) - $this->getAmount(),0);
  35. } else {
  36. return $this->orderFreight->getPriceBefore($this->getKey());
  37. }
  38. }
  39. }