修改优惠卷查询方式

This commit is contained in:
wucongxing 2023-11-08 20:43:36 +08:00
parent 467957527b
commit 8b7c49c8c7

View File

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