GoodsMemberLevelDiscountCalculator.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/12/29
  6. * Time: 2:43 PM
  7. */
  8. namespace app\common\modules\discount;
  9. use app\common\models\GoodsDiscount;
  10. use app\common\models\MemberLevel;
  11. class GoodsMemberLevelDiscountCalculator extends BaseGoodsMemberLevelDiscountCalculator
  12. {
  13. /**
  14. * @var GoodsDiscount
  15. */
  16. private $goodsDiscount;
  17. /**
  18. * @param $price
  19. * @return float|int|mixed
  20. * @throws \app\common\exceptions\AppException
  21. */
  22. public function getAmount($price)
  23. {
  24. return $this->getGoodsDiscount()->getAmount($price,$this->member);
  25. }
  26. public function validate($price)
  27. {
  28. if (!$this->getGoodsDiscount() || $this->getGoodsDiscount()->discount_value === '') {
  29. return false;
  30. }
  31. return true;
  32. }
  33. public function getGoodsDiscount()
  34. {
  35. if (!isset($this->goodsDiscount)) {
  36. $this->goodsDiscount = $this->_getGoodsDiscount();
  37. }
  38. return $this->goodsDiscount;
  39. }
  40. private function _getGoodsDiscount()
  41. {
  42. return $this->goods->hasManyGoodsDiscount->where('level_id', $this->member->yzMember->level_id)->first();
  43. }
  44. public function getKey()
  45. {
  46. return 'independentGoodsMemberLevel';
  47. }
  48. public function getName()
  49. {
  50. return '商品会员等级优惠';
  51. }
  52. }