From 214fcfde3552b1a778904a42c92b79a6f1593354 Mon Sep 17 00:00:00 2001 From: weigang Date: Sat, 18 Jul 2020 18:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=8F=AF=E7=94=A8=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index cbe7162..7377ab6 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -221,20 +221,23 @@ class CouponController extends BaseController ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') ->get(); - // 剔除用户今天用过的优惠券种类 + // 分离用户今天用过的优惠券种类 $container = ApplicationContext::getContainer(); $redis = $container->get(Redis::class); $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); - $available = $data->reject(function ($item) use ($couponIds) { - return in_array($item->id, $couponIds); - }); - - $notAvailable = $data->reject(function ($item) use ($couponIds) { - return !in_array($item->id, $couponIds); - }); + $notAvailable = []; + foreach ($data as $key => &$item) { + if (in_array($item->id, $couponIds)) { + $notAvailable[] = $item; + unset($item); + } + } - return $this->success(['available' => $available, 'not_available' => $notAvailable]); + return $this->success([ + 'available' => $data, + 'not_available' => $notAvailable + ]); }