DefaultOrderFreight.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: blank
  5. * Date: 2022/4/14
  6. * Time: 15:24
  7. */
  8. namespace app\frontend\modules\dispatch\models;
  9. use app\frontend\modules\order\models\PreOrder;
  10. /**
  11. * 给需要自定义运费的订单使用
  12. * Class DefaultOrderFreight
  13. * @property PreOrder $order 订单类
  14. * @property float $initialAmount 设置运费金额
  15. * @property bool $discountDisable 是否禁用运费优惠计算
  16. * @package app\frontend\modules\dispatch\models
  17. */
  18. class DefaultOrderFreight extends OrderFreight
  19. {
  20. /**
  21. * @var float
  22. */
  23. protected $initialAmount;
  24. public $discountDisable;
  25. /**
  26. * DefaultOrderFreight constructor.
  27. * @param PreOrder $order 订单模型
  28. * @param $initialFreight 运费初始金额
  29. * @param bool $discountDisable 是否禁用运费优惠计算
  30. */
  31. public function __construct(PreOrder $order, $initialFreight, $discountDisable = false)
  32. {
  33. $this->initialAmount = $initialFreight;
  34. $this->discountDisable = $discountDisable;
  35. parent::__construct($order);
  36. }
  37. public function getDiscounts()
  38. {
  39. if ($this->discountDisable) {
  40. return collect([]);
  41. }
  42. return parent::getDiscounts(); // TODO: Change the autogenerated stub
  43. }
  44. }