OrderFreightDiscountPricePipe.php 949 B

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