BaseGoodsMemberLevelDiscountCalculator.php 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shenyang
  5. * Date: 2018/12/29
  6. * Time: 2:34 PM
  7. */
  8. namespace app\common\modules\discount;
  9. use app\common\models\Goods;
  10. use app\common\models\Member;
  11. abstract class BaseGoodsMemberLevelDiscountCalculator
  12. {
  13. /**
  14. * @var Goods
  15. */
  16. protected $goods;
  17. protected $member;
  18. public function __construct(Goods $goods, Member $member)
  19. {
  20. $this->goods = $goods;
  21. $this->member = $member;
  22. }
  23. /**
  24. * @param $price
  25. * @return float
  26. */
  27. abstract public function getAmount($price);
  28. /**
  29. * @return boolean
  30. */
  31. abstract public function validate($price);
  32. abstract public function getKey();
  33. abstract public function getName();
  34. public function getLog($amount)
  35. {
  36. return new GoodsMemberDiscountLog([
  37. 'code' => $this->getKey(),
  38. 'name' => $this->getName(),
  39. 'amount' => $amount,
  40. ]);
  41. }
  42. }