From d655936620140f3bf8fe52b649b1f53bd31a187b Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Mon, 7 Sep 2020 01:20:27 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=B7=B2=E5=A4=B1=E6=95=88?= =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/CouponRecService.php | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index 6f4c2d9..02f9d7d 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -121,7 +121,7 @@ class CouponRecService implements CouponRecServiceInterface */ public function getUsedListByUser($userId,$page = 1,$pagesize = 5) { - //查询可用优惠券 + //查询已使用优惠券 $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id') ->where('lanzu_coupon_receive.user_id' ,$userId) ->whereIn('lanzu_coupon_receive.status',[1,2]) @@ -156,7 +156,37 @@ class CouponRecService implements CouponRecServiceInterface */ public function getExpiredListByUser($userId,$page = 1,$pagesize = 5) { - + //查询失效优惠券 + $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id') + ->where('lanzu_coupon_receive.user_id',$userId) + ->where(function ($query) { + $query->where('lanzu_coupon.usable_end_time', '<', time()) + ->orWhere('lanzu_coupon.status', '<>', 1); + }) + ->select( + 'lanzu_coupon.title', + 'lanzu_coupon.discounts', + 'lanzu_coupon.full_amount', + 'lanzu_coupon.discount_type', + 'lanzu_coupon.introduce', + 'lanzu_coupon.usable_end_time', + 'lanzu_coupon_receive.number', + 'lanzu_coupon_receive.number_remain' + ) + ->orderBy('lanzu_coupon.weigh','desc'); + $paginate = $builder->paginate($pagesize); + $couponList = $paginate->toArray(); + foreach ($couponList['data'] as $key => &$coupon) { + //拼接满减文字提示 + $coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用"; + //判断是折扣优惠券还是满减优惠券 + if($coupon['discount_type'] == 1){ + $coupon['discounts_text'] = '¥'.$coupon['discounts']; + }elseif($coupon['discount_type'] == 2){ + $coupon['discounts_text'] = floatval($coupon['discounts'])."折"; + } + } + return ['has_more_pages' => $paginate->hasMorePages(), 'coupon_list' => $couponList['data']]; } } \ No newline at end of file