1 查询关联加条件查询: 2 $listQuery = BusinessOrderModel::whereIn('business_order.bms_id', $userinfo['bms_id_arr'])->whereIn('business_order.status',$status)->leftjoin('business_order_goods','business_order_goods.order_id','=','business_order.id')->where('business_order.pay_status',1); 3 if(in_array(2,$status)){ 4 $listQuery->whereNotIn('business_order.id', function ($listQuery) { 5 return $listQuery->from('business_order')->select('business_goods_return.order_id')->leftjoin('business_goods_return','business_goods_return.order_id','=','business_order.id')->whereIn('business_goods_return.status',[0,1,2]); 6 }); 7 } 8 9 闭包查询 使用use 传递参数 10 $users = User::whereNotIn('id', function ($query) use($user){ 11 $query->select('toUserId')->from('relation')->where('relation.userId', $user->id); 12 });