EnoughReduce.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\discount;
  9. use app\common\modules\orderGoods\models\PreOrderGoods;
  10. class EnoughReduce extends BaseDiscount
  11. {
  12. protected $code = 'enoughReduce';
  13. protected $name = '全场满减优惠';
  14. /**
  15. * @return float|int|null
  16. */
  17. protected function _getAmount()
  18. {
  19. if ($this->getOrderGoodsPrice() == 0) {
  20. return 0;
  21. }
  22. // (支付金额/订单中同种商品已计算的支付总价 ) * 全场满减金额
  23. return ($this->orderGoods->getPriceBefore($this->getCode()) / $this->getOrderGoodsPrice()) * $this->getAmountInOrder();
  24. }
  25. /**
  26. * 订单此种优惠总金额
  27. * @return float
  28. */
  29. protected function getAmountInOrder()
  30. {
  31. return $this->orderGoods->order->getDiscount()->getAmountByCode($this->code)->getAmount();
  32. }
  33. /**
  34. * 订单中同商品的价格小计
  35. * @return float
  36. */
  37. protected function getOrderGoodsPrice()
  38. {
  39. return $this->orderGoods->order->orderGoods->sum(function (PreOrderGoods $preOrderGoods) {
  40. return $preOrderGoods->getPriceBefore($this->getCode());
  41. });
  42. }
  43. }