mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 12:30:49 +08:00
count_peer() support custom field
This commit is contained in:
@@ -705,20 +705,20 @@ function isIPV6 ($ip)
|
||||
return filter_var($ip,FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
|
||||
}
|
||||
|
||||
function count_peer($whereStr)
|
||||
function count_peer($whereStr, $field = 'peer_id')
|
||||
{
|
||||
if (empty($whereStr)) {
|
||||
throw new \InvalidArgumentException("require whereStr");
|
||||
}
|
||||
if (IN_NEXUS) {
|
||||
$sql = "select count(distinct(peer_id)) as counts from peers where $whereStr";
|
||||
$sql = "select count(distinct($field)) as counts from peers where $whereStr";
|
||||
$res = sql_query($sql);
|
||||
$count = mysql_fetch_assoc($res);
|
||||
return $count['counts'];
|
||||
} else {
|
||||
$res = \Illuminate\Support\Facades\DB::table('peers')
|
||||
->whereRaw($whereStr)
|
||||
->selectRaw("count(distinct(peer_id)) as counts")
|
||||
->selectRaw("count(distinct($field)) as counts")
|
||||
->first();
|
||||
return $res->counts;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user