From 9c46caee6262d81c01676493e9436ee25e532ac3 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Mon, 11 Jul 2022 14:29:57 +0800 Subject: [PATCH] =?UTF-8?q?Admin=20=E4=BC=9A=E5=91=98=E5=8D=A1-=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8-=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Services/VipService.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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) { }