GoodsPriceProportion.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2017/10/13
  6. * Time: 下午5:05
  7. */
  8. namespace app\frontend\modules\deduction\orderGoods\amount;
  9. /**
  10. * 按比例抵扣金额
  11. * Class Proportion
  12. * @package app\frontend\modules\deduction\orderGoods\amount
  13. */
  14. class GoodsPriceProportion extends OrderGoodsDeductionAmount
  15. {
  16. /**
  17. * @return float|mixed
  18. * @throws \app\common\exceptions\AppException
  19. */
  20. public function getMaxAmount()
  21. {
  22. $result = $this->getGoodsDeduction()->getMaxPriceProportion() * $this->getBaseAmount('Deduction') / 100;
  23. //todo blank 两种抵扣同时使用问题,订单商品金额已小于抵扣金额则获取最低金额 2022/3/3
  24. $amount = min($result, $this->orderGoods->getPriceBefore($this->getGoodsDeduction()->getCode() . 'Deduction'));
  25. return max($amount, 0);
  26. }
  27. /**
  28. * @return mixed
  29. * @throws \app\common\exceptions\AppException
  30. */
  31. public function getMinAmount()
  32. {
  33. $result = $this->getGoodsDeduction()->getMinPriceProportion() * $this->getBaseAmount('Deduction') / 100;
  34. return max($result, 0);
  35. }
  36. /**
  37. * @param $key
  38. */
  39. private function getBaseAmount($key)
  40. {
  41. $type = $this->getGoodsDeduction()->getDeductionAmountType() ?: 0;
  42. switch ($type) {
  43. case 1:
  44. $amount = $this->orderGoods->getPriceBeforeWeight($this->getGoodsDeduction()->getCode() . $key) - $this->orderGoods->goods_cost_price;
  45. break;
  46. case 2:
  47. $amount = $this->orderGoods->goods_price;
  48. break;
  49. default :
  50. $amount = $this->orderGoods->getPriceBeforeWeight($this->getGoodsDeduction()->getCode() . $key);
  51. break;
  52. }
  53. return max($amount, 0);
  54. }
  55. public function hasMinAmount(){
  56. return $this->getGoodsDeduction()->getMinPriceProportion() > 0;
  57. }
  58. }