OrderDeductionFreightPricePipe.php 1.8 KB

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