From 8b7c49c8c77e992d0e65ab3a77fa9484aad35aac Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 8 Nov 2023 20:43:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BC=98=E6=83=A0=E5=8D=B7?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/UserCoupon.php | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/app/Model/UserCoupon.php b/app/Model/UserCoupon.php index 3830b03..94d6f13 100644 --- a/app/Model/UserCoupon.php +++ b/app/Model/UserCoupon.php @@ -110,15 +110,16 @@ class UserCoupon extends Model $params[] = ['valid_start_time', '<', date('Y-m-d H:i:s', time())]; // 有效使用时间 $params[] = ['valid_end_time', '>', date('Y-m-d H:i:s', time())]; // 过期使用时间 - return self::with(['Coupon'=> function($query) use($inquiry_type){ - $query->where("coupon_client",1) - ->where("coupon_status",1) - ->where("application_scope",2) - ->where(function ($query) use ($inquiry_type) { - $query->orwhere("inquiry_type","like",'%' . $inquiry_type+1 . '%'); - $query->orwhere("inquiry_type","like",'%1%'); - }); - }]) + return self::with(['Coupon']) + ->whereHas('Coupon', function ($query) use ($inquiry_type) { + $query->where("coupon_client",1) + ->where("coupon_status",1) + ->where("application_scope",2) + ->where(function ($query) use ($inquiry_type) { + $query->orwhere("inquiry_type","like",'%' . $inquiry_type+1 . '%'); + $query->orwhere("inquiry_type","like",'%1%'); + }); + }) ->where($params) ->get($fields); } @@ -138,17 +139,18 @@ class UserCoupon extends Model $params[] = ['valid_start_time', '<', date('Y-m-d H:i:s', time())]; // 有效使用时间 $params[] = ['valid_end_time', '>', date('Y-m-d H:i:s', time())]; // 过期使用时间 - return self::with(['Coupon'=> function($query) use($coupon_product_datas){ - $query->where("coupon_client",1) - ->where("coupon_status",1) - ->where("application_scope",2) - ->whereIn("application_scope",[1,3,4,5]) - ->where(function ($query) use ($coupon_product_datas) { - foreach ($coupon_product_datas as $coupon_product_data){ - $query->orwhere("product_id","like",'%' . $coupon_product_data['product_id'] . '%'); - } - }); - }]) + return self::with(['Coupon']) + ->whereHas('Coupon', function ($query) use ($coupon_product_datas) { + $query->where("coupon_client",1) + ->where("coupon_status",1) + ->where("application_scope",2) + ->whereIn("application_scope",[1,3,4,5]) + ->where(function ($query) use ($coupon_product_datas) { + foreach ($coupon_product_datas as $coupon_product_data){ + $query->orwhere("product_id","like",'%' . $coupon_product_data['product_id'] . '%'); + } + }); + }) ->where($params) ->get($fields); }