GoodsAdapter.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2021/4/14
  6. * Time: 13:59
  7. */
  8. namespace app\frontend\modules\cart\manager;
  9. use app\common\models\Goods;
  10. class GoodsAdapter
  11. {
  12. protected $cart;
  13. public function __construct($cart)
  14. {
  15. $this->cart = $cart;
  16. }
  17. public function getPrice()
  18. {
  19. return $this->currentCalculator()->price;
  20. }
  21. public function getCostPrice()
  22. {
  23. return $this->currentCalculator()->cost_price;
  24. }
  25. /**
  26. * 市场价
  27. * @return mixed
  28. */
  29. public function getMarketPrice()
  30. {
  31. return $this->currentCalculator()->market_price;
  32. }
  33. protected $vipDiscountAmount;
  34. protected $vipDiscountLog;
  35. /**
  36. * @return float
  37. * @throws \app\common\exceptions\AppException
  38. */
  39. public function _getVipDiscountAmount()
  40. {
  41. if (!isset($this->vipDiscountAmount)) {
  42. $this->vipDiscountAmount = $this->currentCalculator()->getVipDiscountAmount($this->currentCalculator()->getGoodsPriceAdapter());
  43. $this->vipDiscountLog = $this->currentCalculator()->vipDiscountLog;
  44. }
  45. return $this->vipDiscountAmount;
  46. }
  47. /**
  48. * @return Goods
  49. */
  50. public function currentCalculator()
  51. {
  52. return $this->cart->goods;
  53. }
  54. /**
  55. * @return Goods
  56. */
  57. public function goods()
  58. {
  59. return $this->cart->goods;
  60. }
  61. }