BaseTaxFee.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/5/23
  6. * Time: 下午3:55
  7. */
  8. namespace app\frontend\modules\orderGoods\taxFee;
  9. use app\frontend\models\orderGoods\PreOrderGoodsDiscount;
  10. use app\frontend\models\orderGoods\PreOrderGoodsTaxFee;
  11. use app\frontend\modules\order\models\PreOrder;
  12. use app\common\modules\orderGoods\models\PreOrderGoods;
  13. abstract class BaseTaxFee
  14. {
  15. /**
  16. * @var PreOrder
  17. */
  18. protected $orderGoods;
  19. /**
  20. * 税费名
  21. * @var string
  22. */
  23. protected $name;
  24. /**
  25. * 税费码
  26. * @var
  27. */
  28. protected $code;
  29. /**
  30. * @var float
  31. */
  32. private $amount;
  33. protected $weight;
  34. public function __construct(PreOrderGoods $orderGoods)
  35. {
  36. $this->orderGoods = $orderGoods;
  37. }
  38. public function setWeight($weight)
  39. {
  40. $this->weight = $weight;
  41. }
  42. public function getWeight()
  43. {
  44. return $this->weight;
  45. }
  46. public function getCode()
  47. {
  48. return $this->code;
  49. }
  50. public function getName()
  51. {
  52. return $this->name;
  53. }
  54. /**
  55. * 获取总金额
  56. * @return float|int
  57. */
  58. public function getAmount()
  59. {
  60. if (isset($this->amount)) {
  61. return $this->amount;
  62. }
  63. $this->amount = $this->_getAmount();
  64. if ($this->amount) {
  65. // 将抵扣总金额保存在订单优惠信息表中
  66. $preOrderGoodsTaxFee = new PreOrderGoodsTaxFee([
  67. 'uniacid' => \YunShop::app()->uniacid,
  68. 'fee_code' => $this->getCode(),
  69. 'amount' => $this->amount ?: 0,
  70. 'name' => $this->getName(),
  71. ]);
  72. $preOrderGoodsTaxFee->setOrderGoods($this->orderGoods);
  73. }
  74. return $this->amount ?: 0;
  75. }
  76. /**
  77. * @return float
  78. */
  79. abstract protected function _getAmount();
  80. }