GoodsScope.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace app\frontend\modules\coupon\services\models\UseScope;
  3. use app\common\exceptions\AppException;
  4. use app\common\models\goods\GoodsCoupon;
  5. use app\frontend\modules\orderGoods\models\PreOrderGoods;
  6. use app\frontend\modules\orderGoods\models\PreOrderGoodsCollection;
  7. use Illuminate\Support\Collection;
  8. /**
  9. * Created by PhpStorm.
  10. * Author: 芸众商城 www.yunzshop.com
  11. * Date: 2017/3/28
  12. * Time: 下午1:53
  13. */
  14. class GoodsScope extends CouponUseScope
  15. {
  16. /**
  17. * 订单中使用了该优惠券的商品组
  18. * @return Collection
  19. * @throws AppException
  20. */
  21. protected function _getOrderGoodsOfUsedCoupon()
  22. {
  23. $orderGoods = $this->coupon->getPreOrder()->orderGoods->filter(
  24. function ($orderGoods) {
  25. /**
  26. * @var $orderGoods PreOrderGoods
  27. */
  28. trace_log()->coupon("优惠券{$this->coupon->getMemberCoupon()->id}","商品id{$orderGoods->goods_id},优惠券支持品商品id{$this->coupon->getMemberCoupon()->belongsToCoupon->goods_ids}");
  29. return in_array($orderGoods->goods_id, $this->coupon->getMemberCoupon()->belongsToCoupon->goods_ids);
  30. });
  31. if ($orderGoods->unique('is_plugin')->count() > 1) {
  32. throw new AppException('自营商品与第三方商品不能共用一张优惠券');
  33. }
  34. return $orderGoods;
  35. }
  36. }