| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shenyang
- * Date: 2018/12/29
- * Time: 2:43 PM
- */
- namespace app\common\modules\discount;
- use app\common\models\GoodsDiscount;
- use app\common\models\MemberLevel;
- class GoodsMemberLevelDiscountCalculator extends BaseGoodsMemberLevelDiscountCalculator
- {
- /**
- * @var GoodsDiscount
- */
- private $goodsDiscount;
- /**
- * @param $price
- * @return float|int|mixed
- * @throws \app\common\exceptions\AppException
- */
- public function getAmount($price)
- {
- return $this->getGoodsDiscount()->getAmount($price,$this->member);
- }
- public function validate($price)
- {
- if (!$this->getGoodsDiscount() || $this->getGoodsDiscount()->discount_value === '') {
- return false;
- }
- return true;
- }
- public function getGoodsDiscount()
- {
- if (!isset($this->goodsDiscount)) {
- $this->goodsDiscount = $this->_getGoodsDiscount();
- }
- return $this->goodsDiscount;
- }
- private function _getGoodsDiscount()
- {
- return $this->goods->hasManyGoodsDiscount->where('level_id', $this->member->yzMember->level_id)->first();
- }
- public function getKey()
- {
- return 'independentGoodsMemberLevel';
- }
- public function getName()
- {
- return '商品会员等级优惠';
- }
- }
|