SpentAction.php 748 B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace Longyi\FreeGift\Services\Actions;
  3. /**
  4. * 满额送。
  5. *
  6. * 对应 Amasty 的 Rule\Action\Discount\Spent。
  7. *
  8. * 命中条件的商品金额合计每满 discount_step,送 discount_amount 个赠品。
  9. * 金额口径:base_total - base_discount_amount(不含税,且已扣掉原生促销折扣),
  10. * 与 Bagisto 原生 by_percent 规则的口径保持一致。
  11. */
  12. class SpentAction extends AbstractGiftAction
  13. {
  14. /**
  15. * 命中商品金额每满一个步长,送一份。
  16. */
  17. protected function calculate($rule, array $items, $cart): float
  18. {
  19. $step = $this->getStep($rule);
  20. $amount = $this->getAmount($rule);
  21. return floor($this->totalAmount($items) / $step) * $amount;
  22. }
  23. }