no message
This commit is contained in:
parent
586e049fc6
commit
59bd7b5027
@ -66,6 +66,7 @@ $oHttp->aData['message']['text'] = '\/user#find 1';
|
|||||||
$oHttp->aData['message']['text'] = '\/cmd#list';
|
$oHttp->aData['message']['text'] = '\/cmd#list';
|
||||||
$oHttp->aData['message']['text'] = '\/visitor#all';
|
$oHttp->aData['message']['text'] = '\/visitor#all';
|
||||||
$oHttp->aData['message']['text'] = '\/user#report__day';
|
$oHttp->aData['message']['text'] = '\/user#report__day';
|
||||||
|
$oHttp->aData['message']['text'] = '\/user#countReg__date__2021-03-28__2028-03-28';
|
||||||
|
|
||||||
//{
|
//{
|
||||||
// "update_id": 761180998,
|
// "update_id": 761180998,
|
||||||
|
|||||||
59
src/Services/CountUser.php
Executable file
59
src/Services/CountUser.php
Executable file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
final class CountUser
|
||||||
|
{
|
||||||
|
|
||||||
|
public function RegByDay($iDay)
|
||||||
|
{
|
||||||
|
if (!$iDay) {
|
||||||
|
$iDay = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($iDay == 0) {
|
||||||
|
$sDateEnd = false;
|
||||||
|
} else {
|
||||||
|
$sDateEnd = date("Y-m-d");
|
||||||
|
}
|
||||||
|
|
||||||
|
$sDateStart = date("Y-m-d", strtotime("-$iDay day"));
|
||||||
|
|
||||||
|
return $this->RegGroupFrom($sDateStart, $sDateEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RegByDate($sDateStart, $sDateEnd = false)
|
||||||
|
{
|
||||||
|
if (!$sDateEnd) {
|
||||||
|
$sDateEnd = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->RegGroupFrom($sDateStart, $sDateEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function RegGroupFrom($sDateStart, $sDateEnd = false)
|
||||||
|
{
|
||||||
|
$query = User::selectRaw('COALESCE(`from`, "无") as `from`, COUNT(*) as count');
|
||||||
|
|
||||||
|
if ($sDateEnd) {
|
||||||
|
$query->whereDate('reg_date', '>=', $sDateStart)
|
||||||
|
->whereDate('reg_date', '<=', $sDateEnd);
|
||||||
|
} else {
|
||||||
|
$query->whereDate('reg_date', $sDateStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加排序,按 user_count 降序排列
|
||||||
|
$aCountUser = $query->groupBy('from')
|
||||||
|
->orderBy('count', 'desc') // 根据用户数量降序排序
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return $aCountUser;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ use App\Services\Tg\ReportUser as ServiceTgReportUser;
|
|||||||
use App\Models\User as ModelUser;
|
use App\Models\User as ModelUser;
|
||||||
//use App\Services\DB;
|
//use App\Services\DB;
|
||||||
use App\Utils\Tools;
|
use App\Utils\Tools;
|
||||||
|
use App\Services\CountUser as ServiceCountUser;
|
||||||
|
|
||||||
final class User
|
final class User
|
||||||
{
|
{
|
||||||
@ -72,4 +73,31 @@ final class User
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function CountReg($aParam)
|
||||||
|
{
|
||||||
|
|
||||||
|
@$sOption1 = $aParam['aOption'][1] ?? 'day';
|
||||||
|
@$sOption2 = $aParam['aOption'][2];
|
||||||
|
@$sOption3 = $aParam['aOption'][3];
|
||||||
|
@$sOption4 = $aParam['aOption'][4];
|
||||||
|
|
||||||
|
$sMsg = '?';
|
||||||
|
|
||||||
|
if ($sOption1 == 'day') {
|
||||||
|
$r = (new ServiceCountUser())->RegByDay($sOption2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($sOption1 == 'date') {
|
||||||
|
$r = (new ServiceCountUser())->RegByDate($sOption2, $sOption3);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sMsg = '';
|
||||||
|
foreach ($r as $row) {
|
||||||
|
$sMsg .= "\n\n";
|
||||||
|
$sMsg .= $row['from'].":".$row['count'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sMsg;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user