BaseFreight.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/8/18
  6. * Time: 10:01
  7. */
  8. namespace app\frontend\modules\dispatch\freight;
  9. use app\frontend\modules\order\models\PreOrder;
  10. abstract class BaseFreight
  11. {
  12. /**
  13. * @var PreOrder
  14. */
  15. protected $order;
  16. /**
  17. * 运费名称
  18. * @var string
  19. */
  20. protected $name;
  21. /**
  22. * 运费码
  23. * @var
  24. */
  25. protected $code;
  26. /**
  27. * 金额
  28. * @var float
  29. */
  30. protected $freightAmount;
  31. /*
  32. * 排序:数值越低权重越大
  33. */
  34. protected $weight;
  35. /*
  36. * 按权重最大项获取运费计算方式
  37. * @param third_party 第三方运费计算方式
  38. * @param shop 默认商城运费计算方式
  39. *
  40. */
  41. protected $priority = 'shop';
  42. /**
  43. * BaseFreight constructor.
  44. * @param PreOrder $order
  45. * @param $weight
  46. */
  47. public function __construct(PreOrder $order, $weight)
  48. {
  49. $this->order = $order;
  50. $this->weight = $weight;
  51. }
  52. /**
  53. * 名称
  54. * @return string
  55. */
  56. public function getName()
  57. {
  58. return $this->name;
  59. }
  60. /**
  61. * 标识
  62. * @return mixed
  63. */
  64. public function getCode()
  65. {
  66. return $this->code;
  67. }
  68. /*
  69. * 排序
  70. */
  71. public function getWeight()
  72. {
  73. return $this->weight;
  74. }
  75. /**
  76. * @return float
  77. */
  78. public function getGroup()
  79. {
  80. return $this->priority;
  81. }
  82. /*
  83. * 返回运费金额
  84. */
  85. public function getAmount()
  86. {
  87. if (!isset($this->freightAmount)) {
  88. $this->freightAmount = $this->_getAmount();
  89. }
  90. return $this->freightAmount;
  91. }
  92. /*
  93. * 计算运费金额
  94. */
  95. abstract protected function _getAmount();
  96. /*
  97. * 是否需要计算运费
  98. * @return bool true 需要 false 不需要
  99. */
  100. abstract public function needDispatch();
  101. }