diff --git a/app/Services/VipService.php b/app/Services/VipService.php index c4bee74a..4f1e4bed 100644 --- a/app/Services/VipService.php +++ b/app/Services/VipService.php @@ -105,12 +105,13 @@ class VipService if (isset($gift['coupon']) && $gift['coupon']) { $coupon_service = new CouponService(); $couponId = array_column($gift['coupon'], 'id'); - foreach(Coupon::whereIn('id', $couponId)->get() as $item) { + $couponList = Coupon::whereIn('id', $couponId)->get(); + foreach($gift['coupon'] as $item) { try { - $couponItem = array_filter($gift['coupon'], fn($v) => $v['id'] == $item->id); - $amount = data_get($couponItem, 'amount', 1); - if ($amount > 0) { - $coupon_service->sendCoupon($user, $item, $amount); + $coupon = $couponList->firstWhere('id', $item['id']); + $amount = data_get($item, 'amount', 1); + if ($amount > 0 && $coupon) { + $coupon_service->sendCoupon($user, $coupon, $amount); } } catch (BizException $e) { }