BaseCartExtraCharges.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/5/26
  8. * Time: 9:30
  9. */
  10. namespace app\frontend\modules\cart\extra;
  11. use app\frontend\modules\cart\extra\models\PreCartGoodsExtraCharges;
  12. use app\frontend\modules\cart\models\CartGoods;
  13. abstract class BaseCartExtraCharges
  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. /**
  51. * 获取总金额
  52. * @return float|int
  53. */
  54. public function getAmount()
  55. {
  56. if (isset($this->amount)) {
  57. return $this->amount;
  58. }
  59. $this->amount = $this->_getAmount();
  60. if ($this->amount) {
  61. $preModel = new PreCartGoodsExtraCharges([
  62. 'code' => $this->code,
  63. 'amount' => $this->amount ?: 0,
  64. 'name' => $this->name,
  65. ]);
  66. $preModel->setCartGoods($this->cartGoods);
  67. }
  68. return $this->amount ?: 0;
  69. }
  70. /**
  71. * @return float
  72. */
  73. abstract protected function _getAmount();
  74. }