From 25fb9ea4b4c1de1ab0e0020a1774242610be015b Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 17 Jul 2020 19:45:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93=E5=89=8D=E8=AE=A2=E5=8D=95=E5=8F=AF?= =?UTF-8?q?=E7=94=A8=E4=BC=98=E6=83=A0=E5=88=B8-=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/CouponController.php | 62 +++++++++++++++++------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/app/Controller/CouponController.php b/app/Controller/CouponController.php index 9cb74eb..78cacc1 100644 --- a/app/Controller/CouponController.php +++ b/app/Controller/CouponController.php @@ -169,33 +169,45 @@ class CouponController extends BaseController $data = Db::table('ims_system_coupon_user_receive as receive') - ->leftJoin('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') - ->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('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( - [ + ->select([ + 'receive.id as receive_id', + 'receive.user_id', + 'receive.number_remain', + 'coupon.id', + 'coupon.title', + 'coupon.full_amount', + 'coupon.discounts', + 'coupon.usable_start_time', + 'coupon.usable_end_time', + 'coupon.discount_type' + ]) + ->join('ims_system_coupon_user as coupon', 'coupon.id', '=', 'receive.system_coupon_user_id') + ->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('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] + [ + ['coupon.type', 'in', [1,2]], + ['coupon.storetype_id', '=', 0] + ], + [ + ['coupon.type', 'in', [1,3]], + ['coupon.storetype_id', '=', $storetypeId] + ] ] - ] - ); - }) - ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') - ->get(); + ); + }) + ->orderByRaw('coupon.discounts DESC, coupon.full_amount DESC') + ->get(); //var_dump($d); return $this->success($data);