38 lines
853 B
PHP
38 lines
853 B
PHP
<?php
|
|
|
|
//declare(strict_types=1);
|
|
|
|
namespace App\Services\Tg\Hook\Mod;
|
|
|
|
use App\Models\Visitor as ModelVisitor;
|
|
use App\Services\DB;
|
|
|
|
final class Visitor
|
|
{
|
|
|
|
public function All()
|
|
{
|
|
$aVisitors = ModelVisitor::select('from', DB::raw('count(*) as total'))
|
|
->groupBy('from')
|
|
->orderBy('total', 'desc') // 按 total 降序排序
|
|
->get()
|
|
->toArray();
|
|
|
|
$sPre = "\n\n--访客统计--------------------";
|
|
|
|
$sMsg = '';
|
|
$iTotalCount = 0;
|
|
foreach ($aVisitors as $row) {
|
|
$sMsg .= "\n\n" . $row['from'] . ":" . $row['total'];
|
|
$iTotalCount += $row['total'] ?? 0;
|
|
}
|
|
|
|
$sTotal = "\n\n总数:".$iTotalCount;
|
|
|
|
$str = $sPre.$sTotal.$sPre.$sMsg.$sPre;
|
|
|
|
return $str;
|
|
}
|
|
|
|
}
|