public static function fence_vehicle_list($params,$page,$perpage,$fence_index_id)
{
$getobjlist = self::getlistobj($params,$page,$perpage);
//根据 是否绑定 做下 筛选 count
$newcondition = [];
if (!empty($params["is_bind"])) {
switch ($params["is_bind"]) {
case 'y':
$newcondition = "if(fb.fence_index_id=".$fence_index_id.",1,0) = 1";
break;
case "n";
$newcondition = "if(fb.fence_index_id=".$fence_index_id.",1,0) = 0";
break;
}
}
$obj = $getobjlist["obj"];
$obj_count = $getobjlist["obj_count"];
$obj = $obj->join('st_fence_bind as fb',function ($join)use ($fence_index_id) {
$join->on('fb.vehicle_id','=','veh.id')
->where('fb.fence_index_id','=',$fence_index_id)
->where('fb.is_delete','=',0);
},null,null,"left")
->select(array_merge(Vehicle::$filed_list, ["fb.fence_index_id"]))
->selectRaw("if(fb.fence_index_id=" . $fence_index_id . ",1,0) as have_bind")
->orderByRaw("have_bind desc");
if (!empty($newcondition)) {
$obj = $obj->whereRaw($newcondition);
}
$obj = $obj->get();
$obj ? $getobjlist["list"]= $obj->toArray(): [];
$getobjlist["count"]= $obj_count->count();
unset($getobjlist["obj"]);
unset($getobjlist["obj_count"]);
return $getobjlist;