From a8ec800ec3d2e1e5967637c32924851535ab5109 Mon Sep 17 00:00:00 2001 From: weigang Date: Sat, 18 Jul 2020 14:46:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=94=A8=E6=88=B7=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=AE=A2=E5=8D=95=E5=8F=AF=E7=94=A8=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=96=B0=E5=A2=9E=E5=90=8C=E7=A7=8D=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E4=B8=80=E5=A4=A9=E5=8F=AA=E8=83=BD=E7=94=A8=E4=B8=80?= =?UTF-8?q?=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 30 ++++++++++------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 9cd6298..59d0ec7 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -160,14 +160,14 @@ class CouponController extends BaseController $type = $this->request->input('type',1); # 店铺类型id $storetypeId = $this->request->input('storetype_id',0); + $storetypeIds = explode(',', str_replace(',', ',', $storetypeId)); // 获取用户优惠券 $currentTime = time(); $container = ApplicationContext::getContainer(); $redis = $container->get(Redis::class); - $couponDayUsed = $redis->hGetAll('coupon_day_used'); - $couponRecIds = array_values($couponDayUsed); + $couponIds = $redis->sMembers('coupon_'.date('Ymd').'_used_'.$userId); $data = Db::table('ims_system_coupon_user_receive as receive') ->select([ @@ -183,31 +183,21 @@ class CouponController extends BaseController 'coupon.discount_type' ]) ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') - ->whereNotIn('receive.id', $couponRecIds) ->where(['receive.user_id' => $userId]) - ->where(['receive.user_id' => $userId]) - ->whereIn('coupon.type', [1,$type]) ->whereIn('receive.status', [0,1]) - ->where('receive.number_remain', '>', 0) + ->where('receive.number_remain', '>', 0); + + if (is_array($couponIds)&&!empty($couponIds)) { + $data->whereNotIn('coupon.id', $couponIds); + } + + $data = $data->whereIn('coupon.type', [1,$type]) ->where('coupon.full_amount', '<=', $orderAmount) ->where('coupon.usable_start_time', '<=', $currentTime) ->where('coupon.usable_end_time', '>=', $currentTime) ->where('coupon.usable_number', '<=', Db::raw('receive.number_remain')) ->where('coupon.market_id', 'in', [0,$marketId]) - ->where(function ($query) use ($storetypeId) { - $query->whereOr( - [ - [ - ['coupon.type', 'in', [1,2]], - ['coupon.storetype_id', '=', 0] - ], - [ - ['coupon.type', 'in', [1,3]], - ['coupon.storetype_id', '=', $storetypeId] - ] - ] - ); - }) + ->whereIn('coupon.storetype_id', $storetypeIds) ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') ->get();