BaseCartDeduction.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/5/25
  8. * Time: 18:44
  9. */
  10. namespace app\frontend\modules\cart\deduction;
  11. use app\frontend\modules\cart\deduction\models\PreCartGoodsDeduction;
  12. use app\frontend\modules\cart\models\CartGoods;
  13. abstract class BaseCartDeduction
  14. {
  15. /**
  16. * @var CartGoods
  17. */
  18. protected $cartGoods;
  19. /**
  20. * 优惠名
  21. * @var string
  22. */
  23. protected $name;
  24. /**
  25. * 优惠码
  26. * @var
  27. */
  28. protected $code;
  29. /**
  30. * @var float
  31. */
  32. private $amount;
  33. protected $weight = 0;
  34. public function __construct(CartGoods $cartGoods)
  35. {
  36. $this->cartGoods = $cartGoods;
  37. }
  38. public function setWeight($weight)
  39. {
  40. $this->weight = $weight;
  41. }
  42. public function getWeight()
  43. {
  44. return $this->weight;
  45. }
  46. public function getCode()
  47. {
  48. return $this->code;
  49. }
  50. public function getName()
  51. {
  52. return $this->name;
  53. }
  54. /**
  55. * 获取总金额
  56. * @return float|int
  57. */
  58. public function getAmount()
  59. {
  60. if (isset($this->amount)) {
  61. return $this->amount;
  62. }
  63. $this->amount = $this->_getAmount();
  64. if ($this->amount) {
  65. $preModel = new PreCartGoodsDeduction([
  66. 'code' => $this->code,
  67. 'amount' => $this->amount ?: 0,
  68. 'name' => $this->getName(),
  69. ]);
  70. $preModel->setCartGoods($this->cartGoods);
  71. }
  72. return $this->amount ?: 0;
  73. }
  74. /**
  75. * @return float
  76. */
  77. abstract protected function _getAmount();
  78. }