EnoughReduceDiscount.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/4/29
  8. * Time: 14:07
  9. */
  10. namespace app\frontend\modules\cart\discount;
  11. use app\frontend\modules\cart\models\CartGoods;
  12. class EnoughReduceDiscount extends BaseCartDiscount
  13. {
  14. protected $code = 'enoughReduce';
  15. protected $name = '全场满减优惠';
  16. /**
  17. * @return float|int
  18. * @throws \app\common\exceptions\AppException
  19. */
  20. protected function _getAmount()
  21. {
  22. if ($this->getShopGoodsPrice() == 0) {
  23. return 0;
  24. }
  25. // (订单商品成交金额/订单中同种商品总成交金额 ) * 订单单品满减金额
  26. return ($this->cartGoods->getPriceBefore($this->getCode()) / $this->getShopGoodsPrice()) * $this->enoughReduce();
  27. }
  28. /**
  29. * @return int|mixed
  30. * @throws \app\common\exceptions\AppException
  31. */
  32. protected function enoughReduce()
  33. {
  34. //只有商城订单参加
  35. if($this->cartGoods->goods()->plugin_id != 0) {
  36. return 0;
  37. }
  38. $shopDiscountAmount = $this->cartGoods->getShop()->getDiscountAmount($this->getShopGoodsPrice());
  39. return $shopDiscountAmount;
  40. //return $this->cartGoods->shop->getDiscount()->getAmountByCode($this->code)->getAmount();
  41. }
  42. /**
  43. * 店铺中能够进行全场满减优惠的商品的价格总和
  44. * @return float
  45. */
  46. protected function getShopGoodsPrice()
  47. {
  48. return $this->cartGoods->shop->carts->sum(function (CartGoods $preCartGoods) {
  49. if ($preCartGoods->isChecked() && $preCartGoods->goods()->plugin_id == 0) {
  50. return $preCartGoods->getPriceBefore($this->getCode());
  51. }
  52. return 0;
  53. // return $preCartGoods->getPriceBefore($this->getCode());
  54. });
  55. }
  56. }