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); }